Limit Number of ELSEIF Branches in IF Statements
WarningMetrics & Complexity Limits#EC MAX_ELSEIF_COUNTRemote Enabled
Overview
Limit number of ELSEIF clauses per IF.
ATC Finding Message:
IF statement has too many ELSEIF clauses; consider CASE or polymorphism
Rationale
Deep chains of ELSEIF statements are difficult to read and test. Consider replacing long ELSEIF cascades with a CASE statement, polymorphism, or separate dispatch methods.
Non-Compliant
abap
IF lv_code = 1. ...
ELSEIF lv_code = 2. ...
ELSEIF lv_code = 3. ...
" ... 6+ branches
ENDIF.Compliant
abap
CASE lv_code.
WHEN 1. ...
WHEN 2. ...
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 |
|---|---|---|---|
MAX_ELSEIF_COUNT | Integer | 5 | Maximum number of ELSEIF clauses allowed per IF statement (default: 5) |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC MAX_ELSEIF_COUNT
" SAP CI_ prefix format:
... "#EC CI_MAX_ELSEIF_COUNTRelated Rules
- Limit Cyclomatic Complexity (McCabe Complexity Metric) —
#EC MAX_CYCLO_COMP - Limit Number of WHEN Branches in CASE Statements —
#EC MAX_WHEN_COUNT - Prefer CASE over Multiple IF / ELSEIF on the Same Variable —
#EC PREF_CASE
Technical Details
- Native ATC Class:
ZCL_SKYLINT_MAX_ELSEIF_COUNT - Implementation File: zcl_skylint_max_elseif_count.clas.abap