Skip to content

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 method

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_WHEN_COUNTInteger10Maximum 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_COUNT

Technical Details ​

Released under the MIT License.