Avoid Duplicate Subexpressions in the Same Statement
NoteAnti-Patterns & Bad Practices#EC NO_DUP_SUBEXPRRemote Enabled
Overview
Avoid duplicate subexpressions in the same statement.
ATC Finding Message:
Avoid repeating duplicate subexpressions; evaluate once into a variable
Rationale
Evaluating the exact same table expression (e.g. lt_orders[ 1 ]-net + lt_orders[ 1 ]-vat) or method call multiple times in the same statement triggers redundant internal table index lookups, hash computations, or method executions. In performance-critical logic, this causes unnecessary overhead.
Best Practice: Evaluate the common subexpression once into a local helper variable or field-symbol and reuse it.
Non-Compliant
abap
lv_total = lt_orders[ 1 ]-net + lt_orders[ 1 ]-vat.Compliant
abap
DATA(ls_order) = lt_orders[ 1 ].
lv_total = ls_order-net + ls_order-vat.Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC NO_DUP_SUBEXPR
" SAP CI_ prefix format:
... "#EC CI_NO_DUP_SUBEXPRRelated Rules
- Modernize READ TABLE (Table Expressions & line_exists) —
#EC PREF_TAB_EXPR - Sort Internal Tables Before DELETE ADJACENT DUPLICATES —
#EC NO_DEDUP_NO_SORT - Specify an Explicit SORT Key with BY —
#EC PREF_SORT_KEY
Technical Details
- Native ATC Class:
ZCL_SKYLINT_NO_DUP_SUBEXP - Implementation File: zcl_skylint_no_dup_subexp.clas.abap