Remove Redundant Self-Assignments and CLEAR Statements
Overview
Remove Redundant Assignments & CLEARs.
ATC Finding Messages:
Identical assignment has no effect; remove redundant statementDo not CLEAR or FREE variables after declaration; they are already initialVariable 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
ls_order-id = ls_order-id.
DATA lt_items TYPE string_table.
CLEAR lt_items.Compliant
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):
- Position the cursor on the flagged statement.
- Press Ctrl + 1 (Quick Assist).
- 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 Name | Data Type | Default Value | Description & Guidance |
|---|---|---|---|
CHECK_SELF_ASSIGN | Boolean | true | Detect identical assignments where variable is assigned to itself (a = a) |
CHECK_BEFORE_WRITE | Boolean | true | Detect redundant CLEAR statements immediately followed by variable write/overwrite |
CHECK_WITHOUT_READ | Boolean | true | Detect 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:
" Standard pseudo-comment:
... "#EC SELF_ASSIGN
" SAP CI_ prefix format:
... "#EC CI_SELF_ASSIGNRelated Rules
- Avoid Chained Assignments (a = b = c = 1) —
#EC NO_CHAINED_ASSIGN - Eliminate Unused Local Variables and Symbols —
#EC NO_UNUSED_VARS - Avoid Hungarian Notation and Type Prefixes —
#EC NO_HUNGARIAN
Technical Details
- Native ATC Class:
ZCL_SKYLINT_NO_REDUN_ASSIGN - Implementation File: zcl_skylint_no_redun_assign.clas.abap