Tuesday, 7 January 2014

While Loops in SAP ABAP

While Loops in SAP ABAP

The next looping statement to be examined is the WHILE loop. This differs from the DO loop in that it checks for a predefined condition within the loop before executing any code. All the code between the WHILE and ENDWHILE statements will be repeated as long as the conditions are met. As soon as the condition is false the loop terminates. Here, again the sy-index field can be monitored to see how many times the loop has executed.
                                   
While Loops in SAP ABAP

So here, the loop will again cause the value of ‘a’ to take the form of incremental count-ing, and each time the loop is executed the value of ‘a’ will be written. The loop will con-tinue as long as the value of ‘a’ is not equal to 15, and once it is, it will stop.
                                   
While Loops in SAP ABAP


If one runs this in the debugger mode one will see that on the 15th loop, when the value of ‘a’ is 15, the code inside the statement is skipped over and the cursor jumps straight from WHILE to ENDWHILE.

3 comments: