ERPClimb logoERPClimb
Performance Tuning
ABAP Developmentintermediate 7 min read

Performance Part 7: JOIN vs FOR ALL ENTRIES vs Nested SELECT

Preview · a free account unlocks the full lesson

Key takeaway

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 sections

Visual overview

Performance Part 7: JOIN vs FOR ALL ENTRIES vs Nested SELECT — learning sheetFlow: Rewrite a nested SELECT to an INNER JOIN → Compare ST05 executions and runtime with an FAE version → Try a LEFT OUTER JOIN to list orders without deliveries. Key ideas: NESTED SELECT; INNER JOIN; LEFT OUTER JOIN; FOR ALL ENTRIES. Watch out: JOINs bypass table buffering; joining a buffered customizing table can be slower than reading it separately from the buffer.ERPClimb.com / ABAP / LESSON 7/10 / LEARNING SHEETPerformance Part 7: JOIN vs FOR ALL ENTRIES vs NestedSELECT1 · HOW IT FLOWS1Rewrite a nested SELECTto an INNER JOIN2Compare ST05 executionsand runtime with an FAEversion3Try a LEFT OUTER JOIN tolist orders withoutdeliveries2 · KEY IDEAS EXPLAINEDNested SelectSELECT … ENDSELECT with SELECT inside → many roundtrips; only acceptable for tiny volumes.Inner JoinHeader + item: VBAK INNER JOIN VBAP ON vbap~vbeln= vbak~vbeln, WHERE on header fields (dates, ordertype).Join on key fields; selective WHERE; field listwith aliases (~).Left Outer JoinKeeps left rows without matches (e.g. orderswithout deliveries); fields of the right table areinitial; restrictions on right-table fields in…For All EntriesDriver from ABAP or a different source; secondstep after complex filtering in ABAP.Needs empty check and key fields (Part 5).3 · REMEMBER · WATCH OUTRememberNested SELECT (SELECT…ENDSELECT with inner SELECT) = one round tripper outer row — avoid.JOIN lets the database combine tables in one statement — usually bestwhen all data is in the database and join conditions use keys/indexes.FOR ALL ENTRIES fits when the driver comes from ABAP (file, previousprocessing, a BAPI result) or when a join would multiply rows…!Watch outJOINs bypass table buffering;joining a buffered customizing tablecan be slower than reading itseparately from the buffer.4 · IN A REAL PROJECTA report used a nested SELECT over VBAK and VBAP for a quarter and ran 35 minutes. An FAE rewrite brought itto 6 minutes; an INNER JOIN with the date filter on VBAK brought it to 50 seconds because the database coulduse the date index and join in one pass. For material descriptions (MAKT) the team kept a separate read into a…Original ERPClimb learning sheet • Verify against your SAP release and edition

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.

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.