Prefer COND #( ) Expression over IF/ELSEIF/ELSE
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
IF lv_score >= 90.
lv_grade = 'A'.
ELSEIF lv_score >= 80.
lv_grade = 'B'.
ELSE.
lv_grade = 'C'.
ENDIF.Compliant
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):
- Position the cursor on the flagged statement.
- Press Ctrl + 1 (Quick Assist).
- 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 Name | Data Type | Default Value |
|---|---|---|
REQUIRE_ELSE | Boolean | false |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
" Standard pseudo-comment:
... "#EC PREF_COND
" SAP CI_ prefix format:
... "#EC CI_PREF_CONDTechnical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_COND - Implementation File: zcl_skylint_pref_cond.clas.abap