Skip to content

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 branch
  • WHEN 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 NameData TypeDefault ValueDescription & Guidance
MIN_BRANCHESInteger2Minimum number of explicit WHEN branches before WHEN OTHERS is required (default: 2)
REQUIRE_LASTBooleantrueRequire 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_OTHERS

Technical Details ​

Released under the MIT License.