CDS Associations
Learn ABAP CDS associations as semantic relationships between entities, including ON conditions, cardinality, path expressions, exposed associations and their effect on generated SQL and consumers. Use this topic to model reusable relationships without confusing associations with free performance gains.
Overview
Learn ABAP CDS associations as semantic relationships between entities, including ON conditions, cardinality, path expressions, exposed associations and their effect on generated SQL and consumers. Use this topic to model reusable relationships without confusing associations with free performance gains.
Lessons in this topic
- CDS Associations Part 1: Source, Target, ON Condition and CardinalityDeclare CDS associations correctly: source and target, the ON condition, $projection, cardinality, and exposing the association so consumers can use it.
- CDS Associations Part 2: Path Expressions and How Associations Become JoinsSee 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.
- CDS Associations Part 3: To-One vs To-Many — Semantics and PerformanceChoose and use cardinality deliberately: what to-one and to-many mean for results, how to get one row per source when you need it, how to aggregate over to-many data, and how to keep text and time-dependent relations to-one.
- CDS Associations Part 4: Associations vs Compositions in a RAP Business ObjectUnderstand the CDS side of a RAP business object tree: composition vs association, "association to parent", and how projections redirect compositions, parents and normal associations.
- CDS Associations Part 5: Troubleshooting Duplicates, Missing Data and Slow QueriesFix the three typical association problems — too many rows, missing rows and slow queries — with a repeatable method: check cardinality, join type, filters and the generated SQL.
Interview questions covered
- What is a CDS association, how is it declared, and how does it differ from a join?
- A status text association returns duplicate rows in a list. The ON condition is only on the status code. What is wrong and how do you fix it?
- Explain path expressions: what SQL do they generate, how do filtered paths work, and how are they written in ABAP SQL?
- A list of orders must show the number of items and total item value per order. How do you model this in CDS without duplicates?
- How are compositions declared in CDS for a RAP business object, and what must projections do with them?
- What design rules do you follow for associations in an interface view layer?
- A universal sales order view uses inner joins to customer, material and plant, and some orders disappear. How would you redesign it?
- An OData list returns 2,400 rows where the business expects 800. How do you analyze it?
- Users say a CDS-based report 'lost' some records. What are the possible causes related to associations, and how do you tell them apart?
- You inherit a CDS model with many associations. What do you review before extending it?
How to study CDS Associations
CDS Associations has 5 lessons (1 beginner, 4 intermediate) with about 40 minutes of reading in total. Start with the lesson that matches your level, then read the real project scenario and common mistakes in each one before moving on. After the lessons, say the 10 interview questions out loud in your own words, then check yourself against the model answer in each question (shown once you open it). Use the 15 mock questions to check recall. Finish with the 1 code lab scenario: read the buggy code first, say what is wrong, and only then open the optimized version.
Mock test questions covered
Try answering each one before you open the mock test; the answer options and scoring are in the Mock Questions tab.
- A margin report became wrong after a product description was added via a text association without a language condition. Why?
- Attachments, supplier and approval history were all modeled as compositions of a request. Which should remain a normal association?
- An OData list returns 2,400 rows where 800 are expected. What is the recommended first step?
- Which ABAP SQL statement reads the customer name through the association _Customer of ZI_SalesOrder?
- For an association defined in the base entity of a RAP business object to appear as a navigable OData $expand target in a projection service, what must typically be done in the projection view?
- What best describes a 'filtered association' in ABAP CDS?
- A CDS view uses a path expression such as '_Supplier.Country = \'DE\'' inside its WHERE clause. What does this pattern accomplish?
- In the context of RAP business object modeling, how does a COMPOSITION relationship differ from a plain ASSOCIATION between two CDS entities?
- Which statement correctly distinguishes an association's ON condition from a general filter condition placed in the view's WHERE clause?
- In an association ON condition, a source field is referenced with $projection. What must be true?
- An association is declared [0..1], but the target sometimes has two rows per key. What happens?
- When an association with cardinality [0..*] is followed in a path expression that is used in an aggregated CDS view (using GROUP BY), what must a developer be careful about?
- In ABAP CDS, which association declaration restricts the target instance count to at most one, but does not require that a target instance exists?
- A consumption CDS view declares an association with cardinality [0..*] and then uses REDIRECTED TO on that association pointing to a more specialized projection entity. What is the primary purpose of REDIRECTED TO in this scenario?
- What is a key conceptual difference between a CDS association and a classic explicit JOIN defined in the FROM clause?
Code lab scenarios
- Correlated Subquery Instead of an Association in a CDS ViewA CDS view shows each travel with its booking count. It returns correct results but gets noticeably slower as the number of travels grows.