code pal for ABAP > CHECK Statement Position Check
This check verifies whether the CHECK
statement is the very first statement within a method, function-module or form-routine.
The Clean ABAP says:
Do not use
CHECK
outside of the initialization section of a method. The statement behaves differently in different positions and may lead to unclear, unexpected effects.
REMARKS:
- CHECK statement inside of LOOPs will be disregard by check (for that, refer to: CHECK_IN_LOOP).
- The usage of CLEAR statement prior to CHECK statement is considered to be a bad coding practice! This is actually a workaround in bad designed code (against OO scope principles).
- DATA declarations (DATA / FIELD-SYMBOLS when not dynamic declared – inline declarations), might also come before the keyword CHECK.
The CHECK
statement shall be the first statement of a method. If it is not possible, try to substitute this keyword with an IF-statement instead.
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.
CHECK sy-mandt = 000.
...
ENDMETHOD.