Require WHEN OTHERS as the Last Branch of CASE
WarningClean ABAP & Modern Syntax#EC PREF_WHEN_OTHERSRemote Enabled
Overview
Require WHEN OTHERS as the last CASE branch.
ATC Finding Messages:
CASE statement has no WHEN OTHERS fallback branchWHEN OTHERS should be the last branch of the CASE statement
Rationale
A CASE statement without WHEN OTHERS silently ignores unexpected values, which turns enum or status changes into hard-to-find bugs. Adding WHEN OTHERS with a RAISE or a safe default makes the state machine total and documents the fallback. WHEN OTHERS should also be the last branch so that readers immediately see the default path instead of hunting for it between explicit branches.
Non-Compliant
abap
CASE lv_status.
WHEN c_status-new.
process_new( ).
WHEN c_status-done.
process_done( ).
ENDCASE.Compliant
abap
CASE lv_status.
WHEN c_status-new.
process_new( ).
WHEN c_status-done.
process_done( ).
WHEN OTHERS.
RAISE EXCEPTION NEW zcx_illegal_status( ).
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 | 2 | Minimum number of explicit WHEN branches before WHEN OTHERS is required (default: 2) |
REQUIRE_LAST | Boolean | true | Require WHEN OTHERS to be the final branch of the CASE statement (default: enabled) |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC PREF_WHEN_OTHERS
" SAP CI_ prefix format:
... "#EC CI_PREF_WHEN_OTHERSRelated Rules
- Prefer CASE over Multiple IF / ELSEIF on the Same Variable —
#EC PREF_CASE - Avoid CASE with a Single WHEN Branch —
#EC NO_SINGLE_WHEN - Avoid Empty Control Blocks —
#EC NO_EMPTY_BLOCK
Technical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_WHEN_OTHERS - Implementation File: zcl_skylint_pref_when_others.clas.abap