ERPClimb logoERPClimb
CDS Associations
RAP / CDS / ODataintermediate 8 min read

CDS Associations Part 2: Path Expressions and How Associations Become Joins

Preview · a free account unlocks the full lesson

Key takeaway

See exactly how associations turn into SQL: path expressions in views, in ABAP SQL and in OData, the default LEFT OUTER JOIN, filtered paths, and join-type attributes.

In this lessonShow sections

Visual overview

CDS Associations Part 2: Path Expressions and How Associations Become Joins — learning sheetFlow: Build ZC_SalesOrderList (code example) with two to-one paths and one filtered path → In ADT, open the view and use "Show SQL CREATE Statement" to see the generated joins → Add _Item.Material without a filter and compare the row count in Data Preview — you will see the multiplication (Part 3 explains the fix). Key ideas: PATH EXPRESSIONS IN A CDS VIEW; PATH EXPRESSIONS IN ABAP SQL; IN ODATA; THE GENERATED JOIN TYPE. Watch out: Each path is joined once per distinct path — but to-many paths still multiply rows.ERPClimb.com / RAP / LESSON 2/5 / LEARNING SHEETCDS Associations Part 2: Path Expressions and HowAssociations Become Joins1 · HOW IT FLOWS1Build ZC_SalesOrderList(code example) with twoto-one paths and one…2In ADT, open the view anduse "Show SQL CREATEStatement" to see…3Add _Item.Materialwithout a filter andcompare the row count in…2 · KEY IDEAS EXPLAINEDPath Expressions In A CDS ViewIn the element list of another view:Path Expressions In ABAP SQLIn ABAP SQL the syntax uses a backslash and adash:In ODataConsumers follow associations with $expand (e.g.?$expand=_Item) or navigation URLs. The joinhappens only for requests that ask for it. This is…The Generated Join TypeBy default a path becomes a LEFT OUTER JOIN:orders without a customer still appear, with emptycustomer fields. This is usually what you want.3 · REMEMBER · WATCH OUTRememberA path expression (_Customer.CustomerName) is what turns anassociation into a join.The default join is LEFT OUTER — rows without a target are kept.Filters in square brackets restrict the target: _Item[ Material = 'X'].!Watch outEach path is joined once perdistinct path — but to-many pathsstill multiply rows.4 · IN A REAL PROJECTA report on German customers' orders used "WHERE \_Customer-Country = 'DE'" in ABAP SQL and workedwell. A developer copied the pattern for "orders containing material X" as "WHERE\_Item-Material = 'X'". Orders with that material in three items appeared three times, and a subsequent…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

A path expression, such as _Customer.CustomerName, is what actually turns an association into a join. By default, that join is a LEFT OUTER JOIN, so rows without a matching target are still kept. A filter in square brackets, like _Item[ Material = 'X' ], restricts the target. Each distinct path is joined only once, no matter how many fields are pulled through it, but a to-many path still multiplies the number of rows returned.

Part 1 declared associations; this part is about actually using them. Every use of an association is a path expression, and every path expression becomes a join in the generated SQL.

Inside the element list of a CDS view, a path expression looks like _Customer.CustomerName as CustomerName. This causes the database to join the view with ZI_Customer. If several fields go through the same path — say both _Customer.CustomerName and _Customer.Country — only one join is generated for all of them. Paths can also be chained, as in _Customer._Country.CountryName, with one join generated per step in the chain.

In ABAP SQL, the same idea uses a backslash-and-dash syntax: SELECT SalesOrder, \_Customer-CustomerName AS CustomerName FROM zi_salesorder …, with chaining written as \_Customer\_Country-CountryName. This is valuable because it lets ABAP code reuse relationships already modeled in CDS instead of re-coding the joins by hand.

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

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.