SAP / SAP Mid Level (3 to 8 yrs) Interview questions
What are associations in CDS Views?
An association defines a reusable relationship between one CDS View (or table) and another — declared once in the view's definition — that can then be "followed" in a query using path expressions, without needing to write out the join condition again every time.
define view Z_SalesOrder as select from vbak association [0..1] to Z_Customer as _Customer on $projection.CustomerId = _Customer.CustomerId { key vbeln as SalesOrderId, kunnr as CustomerId, _Customer.CustomerName " follow the association to pull in a field }
Crucially, an association is lazy — the actual join only happens if a query explicitly follows
that association's path to request a field from the associated entity. If nothing references
_Customer, no join is performed at all, which avoids paying the cost of a join the query doesn't
actually need, unlike a join hardcoded directly into the view's FROM clause.
More Related questions...
