ABAP Keyword Documentation → ABAP − Reference → Calling and leaving program units → Exiting Program Units → Exiting Processing Blocks
CHECK - processing_block
Other versions: 7.31 | 7.40 | 7.54
Syntax
CHECK log_exp.
Effect
If the statement CHECK is located outside a
loop and log_exp is false, this statement exits the current processing block. Any
logical expression can be specified for log_exp.
After the processing block is exited, the runtime environment proceeds in the same way as when the
processing block is exited in the regular way
(with the exception of the event block LOAD-OF-PROGRAM and the
reporting event block
GET) . In particular, the output parameters of procedures are passed on to the bound actual parameters.
-
The event block
LOAD-OF-PROGRAMcannot be exited usingCHECK. -
After the reporting event block
GETis exited usingCHECK, any subordinate nodes in the hierarchy structure of the associated logical database are no longer processed. The logical database reads the next line of the current node or next higher node, if it has reached the end of the hierarchy level.
Programming Guideline
Only use RETURN to exit procedures
Notes
-
In a procedure (a method, function module, or subroutine),
CHECK log_expworks outside a loop in the same way as the following:
IF NOT log_exp.
RETURN.
ENDIF.
-
A further variant of the statement
CHECKfor exiting processing blocks isCHECK SELECT-OPTIONS. This can only be used inGETevent blocks for logical databases.
Example
This example shows a case where CHECK can be used outside a loop. Right at
the start of a procedure, a prerequisite for executing the procedure is checked (and the procedure exited if the check is not successful). In this case, the procedure cannot be executed in the background.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
CHECK sy-batch IS INITIAL.
...
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).