CDS association duplicates rows? Check the real relationship and cardinality
A manufacturer's component report unexpectedly multiplies rows when related language texts or other non-unique details are included.
START HERE · NO PRIOR TOPIC KNOWLEDGE NEEDED
What it is. Why it matters.
A CDS association describes a relationship between data objects. Cardinality states the expected number of related records; it does not remove duplicates from an incorrect relationship.
Completely new to SAP?
Manufacturers use SAP to connect work such as buying components, recording inventory, planning production, shipping equipment and accounting for costs. SAP S/4HANA is an enterprise resource planning system: it connects these activities through shared business data.
ABAP is SAP’s programming language for business applications. A program reads data, applies rules and produces a result. Start with the objects involved before investigating code.
A transaction code, or t-code, is a shortcut to a task in classic SAP GUI. Fiori apps provide another way to work. Names and screens depend on the product and release; you do not need a live system to learn the concepts in this guide.

Scope and source-review notes
Scope and evidence
Source review by FAST SAP SOLUTIONS® editorial. This badge describes our editorial review; it does not represent SAP certification or independent endorsement.
ABAP CDS associations and cardinality in supported view types; source/target wording and optimizer capabilities depend on backend release.
Primary documentation reviewed on 14 November 2026 using official indexed excerpts. Documentation review only; authored examples were not compiled or executed in an SAP system.
A MANUFACTURING EXAMPLE
Explain duplicated component-report rows
Count the related matches
Read the example values
- Source order
- 1001
- Matching items
- 3
- Joined result
- Can contain 3 rows
- Expected total
- Must respect row meaning
Words you’ll meet in this guide
- Program
- A set of instructions executed by a computer.
- Class
- A reusable unit that groups data with operations called methods.
- Database
- Organized information kept beyond one program execution.
- Internal table
- A list of rows held temporarily in an ABAP program’s memory.
- Key
- One or more fields used to identify or find a record.
- ABAP
- SAP’s programming language for business applications.
- CDS
- Core Data Services: reusable definitions of business data and relationships.
- API
- A defined interface through which programs exchange data or request actions.
- SQL
- A language used to read and work with database data.
Preview the practical steps
SEE THE CONNECTION
See it in a simple example.
A small example to make the idea concrete.
Explain duplicated component-report rows
A manufacturer's component report unexpectedly multiplies rows when related language texts or other non-unique details are included.
Count actual target matches before changing cardinality
When adding an association target field increases a CDS result's row count, inspect how many target rows match each source under the actual ON condition.
Scope and prerequisites
This guide covers ABAP CDS association/cardinality concepts and path-field consumption.
Association definition and consumption are separate observations
An association describes a relationship that can be exposed for consumers to navigate.
Explain duplicated component-report rows
A manufacturer's component report unexpectedly multiplies rows when related language texts or other non-unique details are included.
Check join grain and actual relationship multiplicity before changing totals or declaring a cardinality that the data does not satisfy.
| Reader | Business question | Evidence to carry forward |
|---|---|---|
| SAP developers and application teams supporting manufacturers | Explain duplicated component-report rows | Check join grain and actual relationship multiplicity before changing totals or declaring a cardinality that the data does not satisfy. |
01 Count actual target matches before changing cardinality
When adding an association target field increases a CDS result's row count, inspect how many target rows match each source under the actual ON condition. A one-to-many relationship can legitimately produce several output rows. Declaring the association to-one does not select a preferred row or remove an incorrect match. [1]
Write the intended grain first: one row per order, item, product-language or another defined identity. Then compare that grain with each relationship the consumer follows. This tutorial combines an order's three items with multilingual product texts to show where six rows come from and how an innocent-looking total becomes inflated.
02 Scope and prerequisites
This guide covers ABAP CDS association/cardinality concepts and path-field consumption. Newer source-and-target cardinality wording is not available in every release; older bracket forms and current syntax must be checked against the backend and CDS artifact type. The code uses illustrative customer tables and a compatible view entity.
You need access to source/target definitions and a small authorized data fixture. Understand keys, joins and aggregation before changing a production model. The examples have not been activated or executed in SAP. Their row counts are derived from the explicit fixture, and optimizer behavior is described only within the reviewed documentation's scope.
03 Association definition and consumption are separate observations
An association describes a relationship that can be exposed for consumers to navigate. Using target fields in a projection can cause the corresponding join to participate in the query. The precise generated access depends on use and release; do not assume merely declaring every association eagerly joins every target for every request. [2]
Cardinality states expectations about matching records. It can influence syntax checks and database optimization. SAP warns that a declaration inconsistent with actual data can enable unsuitable optimization and unexpected behavior. Treat the declaration as a truthful model contract, not a row-limiting instruction or a replacement for a complete relationship condition. [1]
04 Worked case: three items multiplied by two language texts
Fictional order O100 has item 10 for product P10 worth 100 EUR, item 20 for P20 worth 80 EUR and item 30 for P10 worth 120 EUR. The item total is 300 EUR. Both products have English and German text rows. A text association matching only Product finds two texts for each item, so projecting its description produces six item-language rows.
If each joined row carries its item amount, summing the joined amounts gives 600 EUR:100 twice,80 twice and 120 twice. If a300-EUR header total is also carried on all six rows, summing that field gives 1,800 EUR. These are different aggregation errors caused by reading measures at the wrong grain, not evidence that the original sales values changed.
| Source item | Amount | Text matches | Joined amount contribution |
|---|---|---|---|
| O100/10 P10 | 100 EUR | English and German | 200 EUR if both rows summed |
| O100/20 P20 | 80 EUR | English and German | 160 EUR if both rows summed |
| O100/30 P10 | 120 EUR | English and German | 240 EUR if both rows summed |
| Total | 300 EUR at item grain | 6 item-language rows | 600 EUR after repeated measure summation |
05 Find the missing relationship dimensions
Inspect target keys and the intended business selection. A product text often includes language; a validity-dependent target can include dates; an organizational record can require company or sales-area context. Match those dimensions because the business relationship requires them, not merely because they reduce the count.
For the teaching fixture, the user needs one text in the effective session language. Add that language condition and verify the target has at most one row per product/language. If two active texts still match for that combination, another dimension or data-quality issue remains. Choosing an arbitrary language or the first text is not a documented business rule.
06 A to-one text model needs both a complete condition and unique data
The sketch demonstrates a product/session-language relationship. The [0..1] declaration is justified only if the target is genuinely unique for that complete combination. Keep the target language and product fields compatible with the source/session types. A missing translation remains possible, hence the optional minimum.
Do not paste this condition into every text association automatically. The report may need all translations, a requested language parameter or a documented fallback design. In that case the intended result and cardinality differ. Model those semantics explicitly and verify that the consumer uses the intended path rather than another exposed unrestricted association.
@EndUserText.label: 'Order items with one language text'
define view entity ZI_OrderItemText
as select from zorder_item
association [0..1] to zproduct_text as _Text
on $projection.Product = _Text.product
and _Text.language = $session.system_language
{
key order_id as OrderID,
key item_no as ItemNo,
product as Product,
_Text.description as ProductDescription,
_Text
}07 Keep legitimate to-many relationships to-many
An order-to-items association remains one-to-many even after text selection is fixed. Three items should not be squeezed into one order row by declaring to-one. If the consumer needs an order total, aggregate item amounts at a defined currency-aware order grain or expose a separate summary entity.
Selecting one item requires a business rule such as a specifically identified reference item. It is not the same as reporting all items. DISTINCT can hide repeated projected values but also collapse genuinely different rows when identity fields are omitted. A design that returns one row after dropping ItemNo has not demonstrated a correct order-level calculation.
08 Audit actual cardinality with a small diagnostic dataset
For each source identity, enumerate target identities under the complete condition. Keep zero-match, one-match and multiple-match examples. Compare the result with the declared maximum and the consumer's selected target fields. This is more informative than inspecting only a schema diagram whose current cardinality is already in question.
A grouped target check can identify duplicate product/language combinations. For validity models, also test overlapping date ranges rather than checking only exact duplicate keys. If overlapping valid records are permitted by the source, redesign the consuming relationship or define an explicit winner. Do not declare exact-one if missing target records are possible.
SELECT product, language, COUNT(*) AS matches
FROM product_text_fixture
GROUP BY product, language
HAVING COUNT(*) > 1;
-- Also enumerate actual matches for O100/10, O100/20 and O100/30.
-- Compare row identities before and after adding the description field.09 Troubleshooting multiplication and surprising totals
Follow the first relationship that increases the grain. Changing aggregation at the final UI can conceal the symptom while leaving API consumers with the same multiplied data.
| Observation | Question | Next evidence |
|---|---|---|
| Rows increase only after adding description | How many texts match? | Product/language/validity fixture |
| To-one declared; results unstable | Does data violate the promise? | Actual target counts under ON |
| Item total doubles | Is measure repeated per language? | Item-language identities before SUM |
| Header total grows with item count | Was header measure aggregated at detail grain? | Separate header and item measures |
| DISTINCT fixes count but loses rows | Were identity fields omitted? | Compare original source identities |
| No text for one item | Is zero match legitimate? | Optionality and fallback requirement |
| Another consumer still duplicates | Does it follow another path or filter? | Actual projection and association use |
10 Verify zero, one and many matches with the real projection
A positive check uses the intended language and expects three item rows with total 300 EUR. A negative integrity check adds two matching text rows for P10 in the same language and confirms that the model review detects the violated to-one assumption. Do not claim the runtime will always raise a friendly cardinality exception; cardinality is not a universal data-validation mechanism.
A boundary check removes P20's text. Under the intended optional text relationship, item 20 should remain with missing text in the supported consumer path. Another check intentionally requests all translations and expects six item-language rows, with measures handled at their proper grain. Test the actual projected fields, because a source-only query may avoid the problematic association entirely.
Compare identity multiplicity before looking at the amount total. Group the projected test output by order/item and count rows for each key. With two language texts, each item appears twice; after the intended language restriction, each should appear once if the product/language relationship is actually unique. If P10 still has two texts for the chosen language, fixing the language condition alone is insufficient. Preserve that duplicate-key fixture so a future cardinality declaration cannot hide an unresolved source-data relationship.
11 Review performance after the relationship is correct
A truthful to-one relationship can permit useful optimization, but declaring it falsely to obtain a faster plan risks correctness. First fix missing dimensions and choose a useful result grain. Then measure the actual consumer query with representative filters and projection fields using the supported SQL analysis.
Avoid exposing a wide cascade of to-many paths merely because each individual association seems reasonable. Two independent child collections can multiply each other when flattened. Consider separate navigations, pre-aggregated summaries or a deliberately detailed result contract. State whether the output is item-language, item-schedule or order-summary data so downstream clients know how to aggregate it.
12 Frequently asked questions
Does [0..1] remove duplicate target matches? No. It describes a cardinality expectation; it is not a LIMIT or a preferred-row algorithm.
Why did adding one field change counts? That field can cause a target relationship to be consumed, exposing multiple matches that the earlier projection did not need.
Can DISTINCT solve the issue? Only if duplicate elimination matches the intended business projection. It can also hide missing keys and lose valid detail.
What should code review retain? Intended grain, complete ON conditions, target uniqueness evidence, zero/multiple-match fixtures and aggregation rules. That record explains why the declared cardinality is true and why the resulting totals are meaningful.
Related services and next steps
Primary sources
Found this useful?
Share this guide with your network, or leave a like.
Your like is saved in this browser.