Performance Part 7: JOIN vs FOR ALL ENTRIES vs Nested SELECT
Preview · a free account unlocks the full lesson
Compare data retrieval patterns: nested SELECT (worst), FOR ALL ENTRIES (driver from ABAP), INNER and LEFT OUTER JOINs (database does the work), when each fits, join conditions on keys, number of joined tables, buffered tables in joins, and views/CDS for reuse.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Parts 4 and 5 replaced manual loops with FOR ALL ENTRIES. Often, though, a JOIN is actually the better choice, and this lesson is about choosing correctly between the three main options.
A nested SELECT — a SELECT…ENDSELECT with another SELECT inside it — means one database round trip per row of the outer result. Nested SELECT (SELECT…ENDSELECT with inner SELECT) = one round trip per outer row — avoid. This is only acceptable for genuinely tiny data volumes; for anything larger it becomes a performance problem fast.
An inner join lets the database combine tables in a single statement instead. For a header-and-item case, that might look like VBAK INNER JOIN VBAP ON vbap~vbeln = vbak~vbeln, with a WHERE clause filtering on header fields such as dates or order type.
The join itself should happen on key fields, the WHERE clause should stay selective, and the field list should use table aliases with ~. JOIN lets the database combine tables in one statement — usually best when all data is in the database and join conditions use keys/indexes.
It's worth keeping the number of joined tables reasonable — two to four — both for readability and for the optimizer's own stability.
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
Interview questions on this topic
Related SAP topics
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.