CHECK statement in ABAP is used for leaving a loop or processing block with some conditional check. If the conditional check with the CHECK statement is true, the process will continue the execution with the next statement. If the conditional check is false, the process will quit the current loop pass and will process the next loop. If CHECK statement is not within a loop, the false condition will terminate the current event.
Inside loops /bloks
With Reports with logical databse
You will get clearer picture by seeing the following sample scenarios.
Check statement in a loop
We can use check statement within a loops like
- DO … ENDDO
- WHILE … ENDWHILE
- LOOP … ENDLOOP
- SELECT … ENDSELECT
In these loops, if the check statement returns the false, it will stop the current loop pass and start the next loop. Here is an example.
DATA: I =0,
WHILE J < 5.
J = J + 1.
CHECK J NE 2.
Its output will be
Tip: You can see that check statement terminates the loop with value 2.In that loop check conditional statement return false and the loop pass terminated.
CHECK statement with logical databases
CHECK sel: Checks the selection criterion requested by the statement SELECT-OPTIONS sel. If the result of this check is negative, the processing in this event is terminated and the GET events for any subordinate database tables are not processed either.
CHECK SELECT-OPTIONS: checks all the selections for SELECT-OPTIONS where the reference field after FOR belongs to the current table dbtab. And it is calling only after GET event.
Also Read : View Other ABAP Keywords & Syntax -> ABAP Transaction codes