ERPClimb logoERPClimb
Performance Tuning
ABAP Developmentintermediate 6 min read

Performance Part 5: FOR ALL ENTRIES — Correct Use and Hidden Risks

Preview · a free account unlocks the full lesson

Key takeaway

Use FOR ALL ENTRIES correctly: the empty driver table trap (reads the whole table), automatic duplicate removal (and why you must select full keys), sorting and deleting duplicates in the driver table, package sizes, large driver tables, and when a JOIN or range is better.

In this lessonShow sections

Visual overview

Performance Part 5: FOR ALL ENTRIES — Correct Use and Hidden Risks — learning sheetFlow: Run the code example with an empty driver table (in a test system) and see the row count explode — then add the check → Select without POSNR and compare the row count with POSNR included → Deduplicate the driver table and compare ST05 executions. Key ideas: EMPTY DRIVER TABLE; DUPLICATE REMOVAL; DRIVER TABLE HYGIENE; HOW IT RUNS. Watch out: Very large driver tables are split into many statements (packages); a JOIN or a CDS view can be much faster when both tables are in the database anyway.ERPClimb.com / ABAP / LESSON 5/10 / LEARNING SHEETPerformance Part 5: FOR ALL ENTRIES — Correct Use andHidden Risks1 · HOW IT FLOWS1Run the code example withan empty driver table (ina test system) and see…2Select without POSNR andcompare the row countwith POSNR included3Deduplicate the drivertable and compare ST05executions2 · KEY IDEAS EXPLAINEDEmpty Driver TableFAE with an empty table → the FAE conditions aredropped → full table read (or all rows matchingother conditions).Always: IF lt_driver IS NOT INITIAL. … ENDIF.Duplicate RemovalThe result is made unique based on the selectedcolumns.Example: selecting VBELN and NETWR from VBAP fororders: two items with the same net value collapseinto one row → wrong totals. Include POSNR (full…Driver Table HygieneOnly fields used in WHERE; SORT and DELETEADJACENT DUPLICATES.Avoid FAE on huge driver tables (hundreds ofthousands) without packaging (Part 9).How It RunsThe database interface converts FAE into severalstatements with IN lists or OR conditions (profileparameter rsdb/max_blocking_factor etc.); HANA…3 · REMEMBER · WATCH OUTRememberIf the driver table is empty, FOR ALL ENTRIES ignores the whole WHEREcondition part with the table and reads all rows — always check IS NOT…FAE removes duplicate result rows (like DISTINCT on selected fields) —select all key fields or you lose rows (e.g. two items with equal…Deduplicate the driver table (SORT + DELETE ADJACENT DUPLICATES on theused fields) to reduce database work.!Watch outVery large driver tables are splitinto many statements (packages); aJOIN or a CDS view can be muchfaster when both tables are in thedatabase anyway.4 · IN A REAL PROJECTA nightly interface occasionally took 6 hours instead of 10 minutes and transferred the entire BSEG content.On days without new documents, the driver table was empty and FOR ALL ENTRIES read everything. Adding theempty check fixed the runtime. A second bug surfaced in review: FAE without the item number lost items with…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 4 of this series used FOR ALL ENTRIES to replace a SELECT inside a LOOP, but FOR ALL ENTRIES has pitfalls of its own that can produce wrong results or huge reads if you're not careful.

The most dangerous one: if the driver table is empty, FOR ALL ENTRIES ignores the entire WHERE condition part that refers to that table and ends up reading all rows instead (or all rows matching whatever other conditions remain) — so always check IF lt_driver IS NOT INITIAL. … ENDIF. before using it.

FOR ALL ENTRIES also removes duplicate result rows, in effect behaving like a DISTINCT on the selected fields. This becomes a problem if you don't select all the key fields: for example, selecting VBELN and NETWR from VBAP for a set of orders, two items that happen to share the same net value will collapse into a single row, silently producing wrong totals — the fix is to include POSNR, giving you the full key.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

Keep exploring

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.