Skip to content

Disallow Nested LOOP AT Statements Without FROM or GROUP BY ​

WarningPerformance & Database#EC NO_NESTED_LOOPRemote Enabled

Overview ​

Disallow nested LOOP AT statements.

ATC Finding Message: Nested LOOP AT detected; avoid O(N*M) loops or use GROUP BY or parallel cursor

Rationale ​

Nesting internal table loops (LOOP AT within LOOP AT) creates O(N*M) Cartesian complexity that scales poorly with larger datasets and degrades application performance. Use GROUP BY loops, hashed/sorted secondary keys, or parallel cursor (LOOP AT itab FROM sy-tabix) instead.

Non-Compliant ​

abap
LOOP AT lt_orders INTO ls_order.
  LOOP AT lt_items INTO ls_item.
    " O(N*M) quadratic loop
  ENDLOOP.
ENDLOOP.

Compliant ​

abap
LOOP AT lt_orders INTO ls_order.
  LOOP AT lt_items INTO ls_item FROM lv_start WHERE order_id = ls_order-order_id.
    " Parallel cursor or filtered loop
  ENDLOOP.
ENDLOOP.

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.