CHECK_99 - Minimum number of WHENs in a CASE
Improve this pageRFC enabled
CODE
A CASE
statement should have a minimum number of WHEN
branches. If there is only one branch, it would be better to
use an IF
statement.
FORM foo.
DATA lv_bar TYPE i.
CASE lv_bar.
WHEN 1.
WRITE: / 'hello world'.
ENDCASE.
ENDFORM.
can be replaced by
FORM foo.
DATA lv_bar TYPE i.
IF lv_bar = 1.
WRITE: / 'hello world'.
ENDIF.
ENDFORM.
Empty WHEN
branches don’t count.
When setting the minimum number, please consider the recommendations in SAP’s styleguide for Clean ABAP: Prefer CASE to ELSE IF for multiple alternative conditions
Configuration
The minium number of WHEN
branches is by default 2, but can be configured: