Skip to content

Avoid Yoda Conditions ​

WarningAnti-Patterns & Bad PracticesQuickFix Ready#EC 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):

  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.

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.