Skip to content

Prefer FILTER for a Simple LOOP with IF and APPEND ​

WarningClean ABAP & Modern Syntax#EC PREF_FILTERRemote Enabled

Overview ​

Prefer FILTER for simple LOOP/IF/APPEND.

ATC Finding Message: Replace the simple filter loop with FILTER

Rationale ​

A LOOP that only copies rows matching one condition into another table is a filter expressed as imperative control flow. FILTER builds the result directly and states the intent without a work area. This rule only targets the simple LOOP AT, IF, APPEND pattern; keep loops that contain extra logic, indexes, or multiple statements.

Non-Compliant ​

abap
LOOP AT lt_orders INTO ls_order.
  IF ls_order-status = 'O'.
    APPEND ls_order TO lt_open.
  ENDIF.
ENDLOOP.

Compliant ​

abap
lt_open = FILTER #( lt_orders USING KEY primary_key WHERE status = 'O' ).

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.