Exposed Associations
An exposed association is one that is defined in a CDS view and is made available (exposed) to consumers of the view — such as other CDS views, analytical queries, or OData services. You define the association using the association […] to clause and then expose it using an alias (typically starting with an underscore _) in the SELECT list.
define view ZI_SalesOrder as select from ZSalesOrderHeader
{
key SalesOrderID,
CustomerID,
association [0..1] to ZI_Customer as _Customer
on _Customer.CustomerID = ZSalesOrderHeader.CustomerID
// Exposing the association
_Customer
}
Key Points:
- You can reuse exposed associations in other views.
- Useful in modular CDS design.
- Can be traversed via path expressions (e.g., _Customer.Name).
Ad-hoc Associations
Ad-hoc associations are associations that are used inline (on-the-fly) via path expressions, without needing to expose the association explicitly in the SELECT list. If an association (like _Customer) is already defined in a view (exposed or implicit), you can use it ad-hoc in the SELECT or WHERE clause without re-exposing it.
define view ZI_SalesOrder as select from ZSalesOrderHeader
{
key SalesOrderID,
_Customer.Name // Ad-hoc usage of the association
}
Key Points:
- No need to expose
_Customer
again in the select list. - You’re just traversing the association to access fields of the target entity.
- Makes CDS views more compact and readable.