Avoid Yoda Conditions
WarningAnti-Patterns & Bad PracticesQuickFix Ready#EC NO_YODA_CONDRemote Enabled
Overview
Avoid Yoda conditions in comparison expressions.
ATC Finding Message:
Avoid Yoda conditions; place variable before literal in comparison
Rationale
Yoda conditions place the literal or constant on the left side of a comparison and break the natural ABAP reading order of subject, operator, and value. The habit comes from languages where an accidental assignment in a condition is possible, which is not the case for ABAP comparisons. Keep the variable or expression on the left so conditions read like plain language.
Non-Compliant
abap
IF 'ACTIVE' = lv_status.
process( ).
ENDIF.Compliant
abap
IF lv_status = 'ACTIVE'.
process( ).
ENDIF.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.
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC NO_YODA_COND
" SAP CI_ prefix format:
... "#EC CI_NO_YODA_CONDRelated Rules
- Avoid Duplicate Branch Conditions —
#EC NO_DUP_COND - Avoid Negated IF Conditions with ELSE —
#EC NO_NEG_COND - Prefer COND #( ) Expression over IF/ELSEIF/ELSE —
#EC PREF_COND
Technical Details
- Native ATC Class:
ZCL_SKYLINT_NO_YODA_COND - Implementation File: zcl_skylint_no_yoda_cond.clas.abap