Skip to content

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 symbol
  • Arithmetic 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_COMPARE

Technical Details ​

Released under the MIT License.