Skip to content

Prefer SWITCH #( ) Expression over CASE Statement ​

WarningClean ABAP & Modern SyntaxQuickFix Ready#EC PREF_SWITCHRemote Enabled

Overview ​

Prefer SWITCH #( ) expression over CASE statement.

ATC Finding Message: Prefer SWITCH #( ) constructor expression over CASE

Rationale ​

A CASE statement whose branches only assign a result is a verbose value mapping: it repeats the assignment variable in every branch. SWITCH #( ) makes the input value and all possible results visible in one expression and avoids temporary state. Use SWITCH for pure mappings and CASE when a branch contains several statements or side effects.

Non-Compliant ​

abap
CASE lv_status.
  WHEN 'O'.
    lv_text = 'Open'.
  WHEN 'C'.
    lv_text = 'Closed'.
  WHEN OTHERS.
    lv_text = 'Unknown'.
ENDCASE.

Compliant ​

abap
lv_text = SWITCH string( lv_status
  WHEN 'O' THEN 'Open'
  WHEN 'C' THEN 'Closed'
  ELSE 'Unknown' ).

Automated QuickFix ​

This rule provides an automated QuickFix directly in Eclipse ABAP Development Tools (ADT):

  1. Position the cursor on the flagged statement.
  2. Press Ctrl + 1 (Quick Assist).
  3. Select the automated refactoring to apply the clean syntax immediately.

Configuration & Thresholds ​

This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:

Parameter NameData TypeDefault Value
REQUIRE_OTHERSBooleanfalse

Suppression ​

To suppress findings for this rule, append the pseudo-comment to the statement:

abap
" Standard pseudo-comment:
... "#EC PREF_SWITCH

" SAP CI_ prefix format:
... "#EC CI_PREF_SWITCH

Technical Details ​

Released under the MIT License.