Open SQL
ABAP Developmentintermediate

FOR ALL ENTRIES — Correct Use

When to use, what to guard, and modern alternatives.

Explanation

FOR ALL ENTRIES translates a driver table into an IN-list at runtime. Always guard with IF driver IS NOT INITIAL — an empty driver table selects every row. Sort and DELETE ADJACENT DUPLICATES on the join columns of the driver before use to avoid Cartesian duplication. On HANA prefer INNER JOIN, subqueries or CDS association joins where possible.

Code example

ABAP Code
IF lt_ekpo IS NOT INITIAL.  SORT lt_ekpo BY ebeln.  DELETE ADJACENT DUPLICATES FROM lt_ekpo COMPARING ebeln.  SELECT ebeln, bukrs, lifnr FROM ekko    FOR ALL ENTRIES IN @lt_ekpo    WHERE ebeln = @lt_ekpo-ebeln    INTO TABLE @DATA(lt_ekko).ENDIF.

Real project scenario

An MRP report returned duplicate purchase order headers because the driver table had duplicate EBELN values.

Common mistakes

Missing IS NOT INITIAL guard; forgetting to remove duplicates; selecting * instead of an explicit column list.

Best practices

Always project explicit columns; guard the driver; batch large drivers in packages if the resulting IN-list would exceed DB limits.

Interview angle

When would you replace FAE with a JOIN or a CDS view?