code pal for ABAP > Documentation > CHECK Statement Position Check
This check searches for CHECK
statements that are not the first statement within a method, function module or form subroutine since the statement behaves differently in different positions and may lead to unclear, unexpected effects.
When the check finds a CHECK
statement, it will report a finding unless one of the following circumstances applies:
- The statement occurs within a loop - see Check in Loop for a check dealing with these statements.
- The only statement before the
CHECK
statement are variable declarations. However, see the check for chained declarations for better practices when declaring variables.
While it might sometimes seem necessary to have a CLEAR
statement for exporting parameters in front of any CHECK
statements, a need for both of these statements indicates a method that should be refactored to be less confusing, so the check still reports a finding for these cases.
Either move the CHECK
statement to be the first statement of the method or replace it with its equivalent IF
statement.
In exceptional cases, you can suppress this finding by using the pseudo comment "#EC CHECK_POSITION
which has to be placed after the CHECK
statement:
METHOD example.
some code...
CHECK condition = abap_true. "#EC CHECK_POSITION
Before the check:
METHOD example.
...
CHECK sy-mandt = 000.
...
ENDMETHOD.
After the check:
METHOD example.
...
IF sy-mandt <> 000.
RETURN.
ENDIF.
...
ENDMETHOD.
or
METHOD example.
...
IF sy-mandt = 000.
...
ENDIF.
ENDMETHOD.
or
METHOD example.
CHECK sy-mandt = 000.
...
ENDMETHOD.
Note how the second option expresses most clearly the intent both syntactically and visually - the rest of the method (the part indented inside the IF
statement) is to be executed if the condition is true.