ERPClimb logoERPClimb
CDS Views
Architect / Cross-trackintermediate 8 min read

CDS Views Part 6: Associations and Cardinality

Preview · a free account unlocks the full lesson

Key takeaway

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 sections

Visual overview

CDS Views Part 6: Associations and Cardinality — learning sheetFlow: Build ZI_SalesOrderAssoc with _Customer [1..1] and _Item [0..*] → Add CustomerName via path expression — row count stays the same → Add _Item.Material via path — observe duplicated header rows in Data Preview; remove it again → Expose _Customer and _Item; follow them in ADT Data Preview (right-click → Follow Association). Key ideas: SYNTAX; JOIN ON DEMAND; CARDINALITY; PATH EXPRESSIONS. Watch out: Using a path expression to a to-many association ([0..*]) in the field list multiplies rows — the classic cause of doubled totals.ERPClimb.com / ARCH / LESSON 6/10 / LEARNING SHEETCDS Views Part 6: Associations and Cardinality1 · HOW IT FLOWS1BuildZI_SalesOrderAssocwith _Customer…2Add CustomerNamevia pathexpression — row…3Add_Item.Materialvia path —…4Expose _Customerand _Item;follow them in…2 · KEY IDEAS EXPLAINEDSyntaxassociation [cardinality] to <target> as_Alias on <condition>The alias starts with underscore by convention(_Customer, _Item).Join On DemandDeclaring an association costs nothing.Using _Customer.CustomerName in the field listcreates a left outer join in the generated SQL.Cardinality[0..1] or [1]: at most one target (order →customer).[1..1]: exactly one target.Path Expressions_Customer.CustomerName: pulls one field from thetarget.Filtered path: _Text[1: Language =$session.system_language].Description — reducesto-many to to-one.3 · REMEMBER · WATCH OUTRememberAn association is a declared relation ("join on demand"):the join is only executed when a consumer actually uses a field of the…Cardinality [0..1], [1..1], [0..*], [1..*] describes how many targetrows exist per source row — it documents intent and helps the…Exposing the association (listing _Customer in the field list) letsconsumers, OData and Fiori navigate to it.!Watch outUsing a path expression to a to-manyassociation ([0..*]) in the fieldlist multiplies rows — the classiccause of doubled totals.4 · IN A REAL PROJECTA finance user reported that the order value dashboard showed exactly three times the real value for somecustomers. The CDS view had a path expression _Item.Material in its field list to show "firstmaterial", which created one header row per item; SUM(NetAmount) then counted each header several times…Original ERPClimb learning sheet • Verify against your SAP release and edition

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.

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.