Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125

Types of Association in CDS ?

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.

Related Questions

Leave an answer

Leave an answer