Tuesday, 7 January 2014

Nested Do Loops in SAP ABAP

Nested Do Loops in SAP ABAP

DO loops can also be nested. If this is done, each nested loop will have its own sy-index created and monitored by the system. Be aware that when nesting many loops, it is im-portant to consider how much work the system is being asked to do.
Add to the WRITE statement from the previous section a small amount of text reading ‘Outer Loop cycle:’ before outputting the value of ‘a’. This will allow ‘a’ to be monitored.
Then, under the WRITE statement, add a new DO statement to create the inner loop cycle, as below, as well as adding the extra data variables. The main loop will execute 15 times, but within each of these loops, the nested loop will execute 10 times. The variable named ‘c’ will count how many times the loop has occurred. Around 150 loops will execute here.
While the SAP system will certainly be able to handle this instantly, you should bear in mind that if this number was significantly larger and included more intensive processing than simple counting, this could take much longer.
                                      
Nested Do Loops in SAP ABAP

Set a breakpoint and execute this code in debug mode, keeping an eye on the values of a, b, c and sy-index in the Fields mode. As the DO loop is entered, the sy-index field will be-gin counting. Here, the inner loop has just occurred for the 10th time, noted by the 10 in sy-index (and indeed the value of ‘b’).
        
Nested Do Loops in SAP ABAP

After the second full loop, sy-index and ‘a’ will display 2, ‘b’ will be 10 again (as its value is reset to 0 at the beginning of each loop) and ‘c’ will display 20 representing the number of calculations completed all together
      
Nested Do Loops in SAP ABAP

After the full 15 outer loops are completed, it will look like this
     
Nested Do Loops in SAP ABAP

The value of ‘a’ is then added to ‘c’ to give the total number of both outer and inner loops completed
     
Nested Do Loops in SAP ABAP


When the results are viewed in the output window, the last full loop will look like this
Nested Do Loops in SAP ABAP

7 comments:

  1. Thanks for your informative article on software testing. Your post helped me to understand the future and career prospects in software testing. Keep on updating your blog with such awesome article.
    Regards,
    Software testing training| testing training in Chennai| Software training institutes in Chennai

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Thanks for sharing this kind of information. iam so happy to read your blog. Thanks you so much.

    Android Training in chennai

    ReplyDelete
  4. A very helpful article for everyone. Good work.
    There are different modules for different enterprises depending on nature and size of the business.
    http://eonlinetraining.co/course/sap-sd-online-training/

    ReplyDelete
  5. Excellent blog, I wish to share your post with my folks circle. It’s really helped me a lot, so keep sharing post like this.
    Best Selenium Training Institute in Chennai|Selenium Training in Chennai|Selenium Training

    ReplyDelete
  6. This information is impressive; I am inspired by your post writing style & how continuously you describe this topic.


    Android Training in Chennai

    ReplyDelete