Redundant IF Condition Before LOOP AT
Overview
Redundant IF condition before LOOP AT.
ATC Finding Message:
Unnecessary IF guard before LOOP AT; an empty table iterates 0 times
Rationale
An internal table loop (LOOP AT itab) executes zero times when the internal table is empty. Wrapping the entire loop in an IF itab IS NOT INITIAL check adds unnecessary nesting and boilerplate code.
Non-Compliant
abap
IF lt_items IS NOT INITIAL.
LOOP AT lt_items INTO DATA(ls_item).
process_item( ls_item ).
ENDLOOP.
ENDIF.Compliant
abap
LOOP AT lt_items INTO DATA(ls_item).
process_item( ls_item ).
ENDLOOP.Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC NO_LOOP_GUARD
" SAP CI_ prefix format:
... "#EC CI_NO_LOOP_GUARDRelated Rules
- Prefer Early Return and CONTINUE Guard Clauses over Nesting —
#EC PREF_GUARD_METHOD - Avoid Empty Control Blocks in Branching and Looping Statements —
#EC NO_EMPTY_BLOCK
Technical Details
- Native ATC Class:
/SKYL/CL_NO_LOOP_GUARD - ABAP Implementation: /skyl/cl_no_loop_guard.clas.abap
- Rule Metadata: rules-data.mjs (Line 6014)