Preface – This post is part of the ABAP Beginner series.
Table of Contents
Control Break Statements in ABAP Loop
If you want to break the normal flow of an ABAP loop, you need control break statements in the ABAP loop. ABAP provide three-loop control statements, i.e. CONTINUE, CHECK, EXIT.
CONTINUE
This statement will pass the current loop unconditionally. It needs IF statements to apply conditions. As soon as the compiler reads this statement, it skips the current loop and goes to the next iteration. This will be clearer with an example.
CHECK
This statement will pass the current loop conditionally. If the CHECK condition is true, then it executes the rest of the statements. Otherwise, it skips the current loop and goes to the next iteration. This will be clearer with an example.
EXIT
This statement will end all the iterations as soon as the compiler reads this statement. It also needs IF statements to apply conditions. After the EXIT statement, the program control goes to the statement just after the LOOP statements.
ABAP LOOP
ABAP provides keywords that can be used to run some codes again and again based on a condition called ABAP Loop. Let’s see them one by one.
Do-END DO Statements
These are called unconditional loops because we don’t provide any condition for the loop but provide a fixed number of times for the loop to run. If you want to execute certain codes a fixed number of times, this is the best loop to use.
WHILE-END WHILE Statements
These are called conditional loops because we provide a condition for the loop to run. Loop runs and executes the codes till the condition is true.
In the figure below, we can see the difference between Do and While loop statements.
FOR LOOP Statements
For statements are the most used statements in any language. ABAP also provides the same looping method. Syntax is: FOR i = … [THEN expression] UNTIL|WHILE condition
You can read more about it here.
NESTED LOOP
Nested means using one loop under another loop. It will be clearer with an example.
0 Comments