CDS Associations Part 2: Path Expressions and How Associations Become Joins
Preview · a free account unlocks the full lesson
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 sectionsHide sections
Visual overview
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.
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
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.