Joins or FOR ALL ENTRIES: what are the pitfalls of FOR ALL ENTRIES, and when is each the right choice?
Say your answer out loud first.
Practise another way
I prefer a join, or a join on a CTE or subquery, when everything lives in the database, because the database optimises it. FOR ALL ENTRIES works from an internal table.
Its traps: an empty driver table drops the whole WHERE and reads everything, duplicate result rows are removed, and large driver tables become many statements. the cheat sheet lists it as deprecated, so today I would join with the internal table as a source.
FOR ALL ENTRIES (FAE) reads rows whose key matches rows of an internal table. It exists because older Open SQL could not join with an internal table.
The pitfalls
- Empty driver table: the whole
WHEREcondition is dropped and the statement reads the entire table. The keyword documentation says to check that the table is not initial first. This is the classic production incident. - Duplicates are removed: the result behaves like
SELECT DISTINCT, based on the selected columns. If you need duplicate rows (for example two items with the same selected values), select the key fields too. - Restrictions:
GROUP BYshould not be combined with it (it has no effect), andORDER BYis limited to primary key columns, so sorting and aggregating must happen in ABAP. - Performance: the driver table is split into blocks and the database runs several statements. A big or duplicate-heavy driver table means many round trips, so you sort and delete duplicates first.
- Type and conversion differences between the driver column and database column can stop an index from being used.
IF carriers IS NOT INITIAL.
SELECT carrid, connid, fldate
FROM sflight
FOR ALL ENTRIES IN @carriers
WHERE carrid = @carriers-carrid
INTO TABLE @DATA(flights).
ENDIF.
" modern alternative: join with the internal table
SELECT f~carrid, f~connid, f~fldate
FROM sflight AS f
INNER JOIN @carriers AS c ON c~carrid = f~carrid
INTO TABLE @DATA(flights2).
Choice
- Join when all data is in the database: one statement, set-based, and the database picks the plan. An empty driver cannot silently turn into "read everything".
- Join with an internal table when the driver data comes from ABAP and your release supports it (internal tables as data sources since 7.52; the documentation warns that not every database can run it when the data must be passed to the database). The cheat sheet recommends it as the alternative to FAE.
- FAE only in old code you cannot change yet, or releases without the alternative. Always guard the empty table and trim duplicates.
Also: a LEFT OUTER JOIN keeps rows without a partner, an inner join drops them, so say which semantics you want.
Lists empty-table, duplicate removal, no GROUP BY and block splitting, then recommends joins (including join with an internal table) and treats FAE as legacy.
Says 'FAE is faster than join' or 'join is always faster' without naming the empty-table or duplicate behaviour.
Forgetting the empty-table check. With an empty driver table the WHERE is ignored and the whole table is read.
- What exactly happens with FAE when the driver table is empty?
- How do you keep duplicate rows with FAE?
- Inner versus left outer join: what changes in the result?
- Why would a join with an internal table still be slow?
3 official pages, 5 prep guides and 1 technical reference. Confidence: high. Checked 21 Nov 2026.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.
- Technical reference Backs the answer.
- Prep guide Gives the question.
- Prep guide Gives the question.
- Prep guide Gives the question.
- Prep guide Gives the question.
- Prep guide Gives the question.