ABAP Keyword Documentation → ABAP − Reference → Calling and leaving program units → Exiting Program Units → Exiting Loops
CHECK - loop
Other versions: 7.31 | 7.40 | 7.54
Syntax
CHECK log_exp.
Effect
If the statement CHECK
is executed in a
loop and log_exp
is incorrect, the statement CHECK
exits the current loop pass immediately and the program continues with the next loop pass. Any
logical expression can be specified for log_exp
.
Notes
-
Inside a loop,
CHECK log_exp
works just like the following:
IF NOT log_exp.
CONTINUE.
ENDIF.
-
Outside a loop, the statement
CHECK
exits the current processing block (seeCHECK
), however it is best to only useCHECK
inside loops.
Example
Cancels a loop pass using CHECK
if the loop index sy-index
is an odd number.
DATA remainder TYPE i.
DO 20 TIMES.
remainder = sy-index MOD 2.
CHECK remainder = 0.
cl_demo_output=>write_text( |{ sy-index }| ).
ENDDO.
cl_demo_output=>display( ).