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_LOOPRelated Rules
- Prefer LOOP AT WHERE over IF CONTINUE Guards —
#EC PREF_LOOP_WHERE - Modernize READ TABLE (Table Expressions & line_exists) —
#EC PREF_TAB_EXPR - Limit Jump Statements (CONTINUE, EXIT) per Loop —
#EC MAX_LOOP_JUMPS
Technical Details
- Native ATC Class:
ZCL_SKYLINT_NO_NESTED_LOOP - Implementation File: zcl_skylint_no_nested_loop.clas.abap