Do Not Mutate the Internal Table Currently Being Looped (Iterator Invalidation)
Overview
Avoid mutating or sorting tables inside loops.
ATC Finding Messages:
Do not add, delete, sort, collect, or clear rows from the table currently being loopedAvoid sorting internal tables inside loops to prevent severe performance degradation
Rationale
Modifying, deleting, inserting, or sorting the internal table currently being traversed inside a LOOP AT itab block invalidates the loop iterator. Sorting during a loop breaks binary search indexes and causes infinite loops or skipped rows. Deleting rows alters sy-tabix dynamically, leading to silent data corruption.
Best Practice: To update row values, use field-symbols (ASSIGNING FIELD-SYMBOL(<row>)) which mutates memory directly in-place without altering table layout. For filtering or structural reshaping, use modern constructor expressions (FILTER #( ... )) or build a new secondary table.
Non-Compliant
" Anti-pattern: Modifying and sorting inside loop invalidates table indexes
LOOP AT lt_items INTO ls_item.
ls_item-price = ls_item-price * 1.1.
MODIFY lt_items FROM ls_item.
SORT lt_items BY item_id.
ENDLOOP.Compliant
" Clean ABAP: Direct in-place mutation via field symbol without table re-indexing
LOOP AT lt_items ASSIGNING FIELD-SYMBOL(<ls_item>).
<ls_item>-price = <ls_item>-price * 1.1.
ENDLOOP.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_APPEND | Boolean | true | Detect APPEND statements targeting the loop table |
CHECK_INSERT | Boolean | true | Detect INSERT statements targeting the loop table |
CHECK_MODIFY | Boolean | true | Detect MODIFY statements targeting the loop table |
CHECK_DELETE | Boolean | true | Detect DELETE statements targeting the loop table |
CHECK_CLEAR | Boolean | true | Detect CLEAR or FREE statements targeting the loop table |
CHECK_SORT | Boolean | true | Detect SORT statements targeting the loop table |
CHECK_SORT_ANY | Boolean | true | Detect SORT statements on any table inside a loop |
CHECK_COLLECT | Boolean | true | Detect COLLECT statements targeting the loop table |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
" Standard pseudo-comment:
... "#EC NO_MOD_LOOP_TAB
" SAP CI_ prefix format:
... "#EC CI_NO_MOD_LOOP_TABRelated Rules
- Avoid String Concatenation Inside Loops (Quadratic Memory Allocation) —
#EC NO_CONCAT_LOOP - Only Modify Tables Defined in Your Own Package/Component —
#EC NO_MOD_STD_TABLE - Specify TRANSPORTING in Internal Table MODIFY and READ Operations —
#EC PREF_TRANSPORT
Technical Details
- Native ATC Class:
ZCL_SKYLINT_NO_MOD_LOOP_TAB - Implementation File: zcl_skylint_no_mod_loop_tab.clas.abap