Limit Number of WHEN Branches in CASE Statements
WarningMetrics & Complexity Limits#EC MAX_WHEN_COUNTRemote Enabled
Overview
Limit number of WHEN clauses per CASE.
ATC Finding Message:
CASE statement has too many WHEN clauses; consider refactoring
Rationale
A CASE statement with an excessive number of WHEN branches violates the Single Responsibility Principle and often indicates missing polymorphism, dictionary tables, or strategy patterns. Complex CASE structures are prone to bugs during maintenance.
Non-Compliant
abap
CASE lv_status.
WHEN 'A'. ...
WHEN 'B'. ...
" ... 10+ more branches
ENDCASE.Compliant
abap
" Use a strategy pattern, lookup table, or dispatch methodConfiguration & 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_WHEN_COUNT | Integer | 10 | Maximum number of WHEN clauses allowed per CASE statement (default: 10) |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC MAX_WHEN_COUNT
" SAP CI_ prefix format:
... "#EC CI_MAX_WHEN_COUNTRelated Rules
- Limit Cyclomatic Complexity (McCabe Complexity Metric) —
#EC MAX_CYCLO_COMP - Limit Number of ELSEIF Branches in IF Statements —
#EC MAX_ELSEIF_COUNT - Prefer CASE over Multiple IF / ELSEIF on the Same Variable —
#EC PREF_CASE
Technical Details
- Native ATC Class:
ZCL_SKYLINT_MAX_WHEN_COUNT - Implementation File: zcl_skylint_max_when_count.clas.abap