CDS Views Part 6: Associations and Cardinality
Preview · a free account unlocks the full lesson
Model relations between CDS views with associations instead of hard joins: syntax, ON conditions with $projection, cardinality [0.. 1], [1.. 1], [0.. ], path expressions, exposing associations to consumers, and the row-multiplication trap.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Part 5 already used an association between a composite and a basic view; here is how associations really work. An association is a declared relation, often called "join on demand" — the join only actually executes when a consumer uses a field from the associated view, so declaring an association by itself costs nothing. The syntax is association [cardinality] to <target> as _Alias on <condition>, with the alias conventionally starting with an underscore (_Customer, _Item), and $projection.<field> refers to a field of the current view by its alias name.
Using _Customer.CustomerName in a field list is what actually creates a left outer join in the generated SQL — a consumer that only selects header fields never triggers that join at all.
Cardinality — written as [0..1], [1..1], [0..*], or [1..*] — documents how many target rows exist per source row: [0..1] or [1] means at most one target (an order has at most one customer), [1..1] means exactly one, and [0..*] or [*] means many (an order has many items).
Getting the cardinality wrong doesn't cause an error, but it can mislead both the optimizer and consumers; newer releases also offer an explicit syntax such as "of exact one to many," though the bracket form remains valid.
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.