Skip to content

Do Not Mutate the Internal Table Currently Being Looped (Iterator Invalidation) ​

WarningPerformance & Database#EC NO_MOD_LOOP_TABRemote Enabled

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 looped
  • Avoid 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 ​

abap
" 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 ​

abap
" 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 NameData TypeDefault ValueDescription & Guidance
CHECK_APPENDBooleantrueDetect APPEND statements targeting the loop table
CHECK_INSERTBooleantrueDetect INSERT statements targeting the loop table
CHECK_MODIFYBooleantrueDetect MODIFY statements targeting the loop table
CHECK_DELETEBooleantrueDetect DELETE statements targeting the loop table
CHECK_CLEARBooleantrueDetect CLEAR or FREE statements targeting the loop table
CHECK_SORTBooleantrueDetect SORT statements targeting the loop table
CHECK_SORT_ANYBooleantrueDetect SORT statements on any table inside a loop
CHECK_COLLECTBooleantrueDetect COLLECT statements targeting the loop table

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.