Loop Termination – CONTINUE in SAP ABAP
Up
until now, the loop statements set up have been allowed to use the conditions
inside them to determine when they are terminated. ABAP also includes
termination statements which allow loops to be ended prematurely. There are two
categories of these, those which apply to the loop and those which apply to the
entire processing block in which the loop occurs.
First, we will looks at how to terminate
the processing of a loop. The first statement of importance here is the
CONTINUE statement. This allows a loop pass to be terminated unconditionally.
As the syntax shows, there are no conditions attached to the statement itself.
It tells the program to end processing of the statements in the loop at the
point where it appears and go back to the beginning of the loop again. If it is
included within a loop, any statements after it will not be executed.
For the simple DO loop ,include an IF
statement which includes CONTINUE inside it, like this.
With this code, the second iteration of the
loop (when the sy-index field, like the value of a, will read 2) will hit the
CONTINUE statement and go back to the top, missing the WRITE statement. When
this is output, the incremental counting will go from 1 to 3. As with many
of these statements, in debug mode, the operation can be observed more closely
by executing the code line by line.
No comments:
Post a Comment