Control Break Statements in ABAP Loop

by | Mar 8, 2018 | ABAP Beginner

Home » SAP » ABAP » ABAP Beginner » Control Break Statements in ABAP Loop

Preface – This post is part of the ABAP Beginner series.

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.

Control Break Statements in ABAP Loop

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.

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author