Skip to content

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 NameData TypeDefault ValueDescription & Guidance
MAX_ELSEIF_COUNTInteger5Maximum 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_COUNT

Technical Details ​

Released under the MIT License.