Prefer CASE over Multiple IF / ELSEIF on the Same Variable
WarningClean ABAP & Modern Syntax#EC PREF_CASERemote Enabled
Overview
Use CASE instead of IF when checking multiple values.
ATC Finding Message:
Multiple ELSEIF branches check the same variable; use CASE instead
Rationale
A chain of ELSEIF statements that compares the same variable to different values is harder to scan than a CASE statement. CASE groups all alternatives under one subject and makes a missing OTHERS branch visible. Use CASE for multi-value dispatch on a single expression.
Non-Compliant
abap
IF lv_payment_method = 'CARD'.
process_card( ).
ELSEIF lv_payment_method = 'CASH'.
process_cash( ).
ELSEIF lv_payment_method = 'TRANSFER'.
process_transfer( ).
ENDIF.Compliant
abap
CASE lv_payment_method.
WHEN 'CARD'.
process_card( ).
WHEN 'CASH'.
process_cash( ).
WHEN 'TRANSFER'.
process_transfer( ).
ENDCASE.Configuration & Thresholds
This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:
| Parameter Name | Data Type | Default Value | Description & Guidance |
|---|---|---|---|
MIN_BRANCHES | Integer | 3 | Minimum number of ELSEIF branches on the same variable before suggesting CASE (default: 2) |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC PREF_CASE
" SAP CI_ prefix format:
... "#EC CI_PREF_CASERelated Rules
- Prefer COND #( ) Expression over IF/ELSEIF/ELSE —
#EC PREF_COND - Prefer SWITCH #( ) Expression over CASE Statement —
#EC PREF_SWITCH - Avoid CASE with a Single WHEN Branch —
#EC NO_SINGLE_WHEN
Technical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_CASE - Implementation File: zcl_skylint_pref_case.clas.abap