Skip to content

Remove Redundant Self-Assignments and CLEAR Statements ​

WarningAnti-Patterns & Bad PracticesQuickFix Ready#EC SELF_ASSIGNRemote Enabled

Overview ​

Remove Redundant Assignments & CLEARs.

ATC Finding Messages:

  • Identical assignment has no effect; remove redundant statement
  • Do not CLEAR or FREE variables after declaration; they are already initial
  • Variable is CLEARed or FREEd but never read again before procedure ends

Rationale ​

Self-assignments (e.g. a = a or MOVE a TO a) and superfluous CLEAR/FREE operations have zero net effect on program execution state. Clearing variables immediately after declaration is unnecessary because ABAP automatically initializes variables to their type defaults. Similarly, clearing variables at procedure exit when they are never read again is dead code. Remove these redundant statements to improve clarity and reduce noise.

Non-Compliant ​

abap
ls_order-id = ls_order-id.
DATA lt_items TYPE string_table.
CLEAR lt_items.

Compliant ​

abap
ls_order-id = iv_id.
DATA lt_items TYPE string_table.

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.

Configuration & Thresholds ​

This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:

Parameter NameData TypeDefault ValueDescription & Guidance
CHECK_SELF_ASSIGNBooleantrueDetect identical assignments where variable is assigned to itself (a = a)
CHECK_BEFORE_WRITEBooleantrueDetect redundant CLEAR statements immediately followed by variable write/overwrite
CHECK_WITHOUT_READBooleantrueDetect redundant CLEAR at the very end of procedure where variable is never read again

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.