CDS View Field Mapping and Associations
Deep dive into how CDS Views map fields from source tables and define associations between views for navigation and joins.
Field Mapping
Every field in a CDS View has a source expression that traces back to a column in a source table or another CDS View. Field mappings can be:
- Direct —
source_table.field_name(simple column reference) - Renamed —
source_table.field_name as NewName - Calculated — Expressions like
field_a + field_b as Total - Cast — Type conversions:
cast(field as abap.char(10)) - Case — Conditional:
case when ... then ... end
CDSee tracks the complete field lineage, showing which physical table column each field ultimately originates from — even through multiple layers of CDS Views.
Associations
Associations define relationships between CDS Views, similar to foreign keys but more powerful. They support:
- Cardinality —
[1..1],[0..1],[1..*],[0..*] - On-condition — The join condition (e.g.,
on $projection.CompanyCode = _Company.CompanyCode) - Lazy evaluation — Associations are only resolved when a consumer navigates to them, improving performance
- OData navigation — Associations become OData navigation properties automatically
Associations vs Joins
| Aspect | Association | Join |
|---|---|---|
| Evaluation | Lazy (on demand) | Eager (always executed) |
| Performance | Better (only when needed) | May fetch unnecessary data |
| OData | Becomes navigation property | Flattened into entity |
| Syntax | association [0..1] to ... | left outer join ... on ... |