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

What is the difference between association vs Joins in CDS ?

Association An association is a declarative relationship between CDS entities (like foreign keys), defined using the association keyword. Key Characteristics: Lazy/Evaluated-on-demand: Data from the association is not fetched unless it is explicitly accessed using a path expression (like to_customer.name). Navigation-style access: You can access associated data using dot (.) notation. Defined once, reused many times: Associations can be defined once and used in multiple views or queries. Cardinality can be defined: e.g. [0..1], [1..*].

define view ZSalesOrder as select from sales_order
association [0..1] to customer as _Customer on $projection.customer_id = _Customer.id
{
key sales_order_id,
customer_id,
_Customer.name
}

Here, _Customer is an association. It won’t trigger a join unless _Customer.name is accessed.

Join
A join is an explicit operation in CDS to combine two data sources based on a condition, much like in SQL. Key Characteristics: Eager execution: The join happens immediately during view evaluation. More control: You control the type of join (INNER, LEFT OUTER, etc.). Typically used when data from both tables is always needed.

define view ZSalesOrderJoin as select from sales_order
inner join customer on sales_order.customer_id = customer.id
{
sales_order.id,
customer.name
}

Here, a real-time INNER JOIN is performed.

When to Use What?

Use Association:

  • When modeling data relationships.
  • When you want flexibility and better performance for optional fields.
  • When the associated data isn’t always needed.

Use Join:

  • When you always need data from both sources.
  • When performing aggregations or filters based on joined fields.
  • When doing complex multi-joins with specific types (e.g. inner join).

Related Questions

Leave an answer

Leave an answer