Skip to content

Prefer COND #( ) Expression over IF/ELSEIF/ELSE ​

WarningClean ABAP & Modern SyntaxQuickFix Ready#EC PREF_CONDRemote Enabled

Overview ​

Prefer COND #( ) expression over IF/ELSEIF/ELSE statement.

ATC Finding Message: Prefer COND #( ) constructor expression over IF/ELSEIF

Rationale ​

An IF/ELSEIF chain that only assigns different values to the same variable duplicates the assignment target and spreads one decision over many lines. COND #( ) turns the whole mapping into a single expression, so the target is assigned exactly once and cannot be left uninitialized. It also composes with assignments and method calls. Keep IF when branches perform multiple statements or side effects.

Non-Compliant ​

abap
IF lv_score >= 90.
  lv_grade = 'A'.
ELSEIF lv_score >= 80.
  lv_grade = 'B'.
ELSE.
  lv_grade = 'C'.
ENDIF.

Compliant ​

abap
lv_grade = COND string(
  WHEN lv_score >= 90 THEN 'A'
  WHEN lv_score >= 80 THEN 'B'
  ELSE 'C' ).

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_ELSEBooleanfalse

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.