Avoid Comparisons and Arithmetic with Identical Operands
WarningAnti-Patterns & Bad Practices#EC NO_SELF_COMPARERemote Enabled
Overview
Detect comparisons and arithmetic with identical operands.
ATC Finding Messages:
Both sides of the comparison resolve to the same symbolArithmetic operation uses the same symbol on both sides
Rationale
Comparing an expression with itself (lv_status = lv_status) always yields the same result, so the condition or assignment is meaningless and usually hides a copy-paste mistake. The same applies to arithmetic that always collapses to a constant (lv_diff = lv_x - lv_x). Operands are resolved through compiler symbols, so shadowed names and textually equal but different symbols are not confused. Statements with an AND/OR chain are left to no-dup-cond to avoid double findings.
Non-Compliant
abap
IF lv_status = lv_status.
lv_count = lv_count + 1.
ENDIF.
lv_diff = lv_x - lv_x.Compliant
abap
IF lv_status = c_status-done.
lv_count = lv_count + 1.
ENDIF.
lv_diff = lv_x - lv_y.Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC NO_SELF_COMPARE
" SAP CI_ prefix format:
... "#EC CI_NO_SELF_COMPARERelated Rules
- Avoid Dead Code with Constant Conditions —
#EC NO_DEAD_CODE - Avoid Duplicate Branch Conditions —
#EC NO_DUP_COND - Remove Redundant Self-Assignments and Identity Moves —
#EC NO_IDENTICAL_MOVE
Technical Details
- Native ATC Class:
ZCL_SKYLINT_NO_SELF_COMPARE - Implementation File: zcl_skylint_no_self_compare.clas.abap