1Introduction
In the blog I will introduce how to exit loop. It is used in the abap.
2 Usage
2.1.Exit
If the EXIT statement is listed within a loop, it leaves the loop by ending the current loop process. Program execution is continued after the closing statement in the loop.
DATA limit TYPE i VALUE 10.
DO.
IF sy-index > limit.
EXIT.
ENDIF.
WRITE / sy-index.
ENDDO.
2.2.Check
If the statement CHECK is executed in a loop and log_exp is incorrect, the statement CHECK immediately terminates the current loop pass and the program continues with the next loop pass. For log_exp, you can specify any logical expression.
DATA remainder TYPE i.
DO 20 TIMES.
remainder = sy-index MOD 2.
CHECK remainder = 0.
WRITE / sy-index.
ENDDO.
2.3. continue
The CONTINUE statement can only be used in loops. If it is used, the current loop pass is ended immediately and the program flow is continued with the next loop pass.
DATA remainder TYPE i.
DO 20 TIMES.
remainder = sy-index MOD 2.
IF remainder <> 0.
CONTINUE.
ENDIF.
WRITE / sy-index.
ENDDO.
3. Summary
EXIT terminate loop for ever and continue programe after the statement of loop.
CONTINUE and CHECK are only terminate current loop and go on next loop.
CHECK log_exp.
Effect
If the statement CHECK is executed outside a loop and log_exp is incorrect, the statement terminates the current process block. You can specify any logical expression for log_exp
data limit type i value '10'.
check limit is initial.
write / limit.