Association in cds view abap CDS Part 9 ABAP on HANA Course

SAP TECHNOMANIAC
8 Jul 202218:41

Summary

TLDRIn this video, the speaker explains the concept of associations in SAP and how they differ from joins. They demonstrate creating a CDS view using associations, replacing a left outer join, and discuss the advantages, such as lazy loading and efficiency in data modeling. The video covers cardinality between tables, ad hoc and exposed associations, and how associations work in data retrieval without forming joins until necessary. The speaker also explores SQL execution plans, showing when and how joins occur. Finally, they preview future topics like using associations in WHERE conditions and advanced cardinality scenarios.

Takeaways

  • 😀 Associations in CDS views establish a relationship between the source and target entities, similar to joins but with distinct differences.
  • 📊 Joins in data models form a relationship between source and target entities, but associations act as 'lazy joins,' only executing when needed.
  • 📝 Cardinality in associations defines the relationship between the source and target, such as one-to-many or one-to-one relationships.
  • 🔄 In this example, a sales order can have multiple line items, represented by a one-to-many (1..n) cardinality between tables VBAK (header) and VBAP (line items).
  • 💡 Associations are preferred over joins because they only activate when fields from the associated target entity are accessed, optimizing performance.
  • 🔍 The example replaces a left outer join with an association, demonstrating how the system understands fields from the source entity without needing specific field references.
  • 📊 SAP recommends prefixing association names with an underscore (_) to easily distinguish associations from other fields in SQL queries.
  • 🛠️ There are two types of associations: ad-hoc (used directly within the CDS view) and exposed (used when accessed in other CDS views or SQL queries).
  • 🚀 Exposed associations allow for flexible data retrieval across CDS views, enabling access to associated data without immediately forming a join.
  • 🧩 Using associations in a where condition requires additional understanding, as the join only occurs when the associated fields are accessed, referred to as 'join on demand.'

Q & A

  • What is an association in CDS views?

    -An association in CDS views represents a relationship between a source entity and a target entity, which can be a table, view, or another CDS entity. Associations are similar to joins but with key differences, like being 'lazy' or 'join on demand,' meaning they are not executed unless necessary.

  • How does an association differ from a join?

    -A key difference is that associations are 'lazy' or 'join on demand,' meaning the join will only form if fields from the target entity are accessed. In contrast, a join forms immediately when the tables are linked. This allows for optimized data retrieval in associations.

  • What is the importance of cardinality in an association?

    -Cardinality defines the relationship between the source and target entities. For example, in a 1-to-n cardinality, one record in the source entity can relate to many records in the target entity. This relationship is critical in defining how data is fetched between associated tables.

  • What are ad hoc and exposed associations?

    -Ad hoc associations are used directly in the select list or where clause, triggering a join immediately. Exposed associations are defined but not accessed, so they do not form a join unless accessed by another view or query. They are used for flexibility and deferred joins.

  • What happens if you don’t access fields from an association?

    -If you do not access any fields from the association, no join is formed, meaning the system will only fetch data from the source entity. This lazy loading of associations helps optimize performance by avoiding unnecessary joins.

  • Why does SAP recommend using an underscore before the association name?

    -SAP recommends using an underscore before the association name to easily identify that the association is being used in the CDS view. This naming convention helps differentiate between simple fields and fields coming from an association.

  • What is a path expression in an association?

    -A path expression in an association is the syntax used to access fields from the associated entity. For example, 'sourceEntity.association.field' allows you to access the 'field' from the associated target entity.

  • How do associations behave in a program when data is accessed?

    -When accessing data in a program from an association, the system forms the join only if you access fields from the associated entity. If you only retrieve data from the source entity, the join is not formed, optimizing performance.

  • What are the two types of association in CDS views?

    -The two types of association are ad hoc and exposed. Ad hoc associations are used directly in a select list or where clause, immediately forming a join. Exposed associations are defined but not used until accessed later, keeping the join deferred.

  • What does 'join on demand' mean in CDS views?

    -'Join on demand' means that the join between the source and target entities only forms when fields from the target entity are accessed. This feature of associations helps avoid unnecessary joins and improves query performance.

Outlines

plate

هذا القسم متوفر فقط للمشتركين. يرجى الترقية للوصول إلى هذه الميزة.

قم بالترقية الآن

Mindmap

plate

هذا القسم متوفر فقط للمشتركين. يرجى الترقية للوصول إلى هذه الميزة.

قم بالترقية الآن

Keywords

plate

هذا القسم متوفر فقط للمشتركين. يرجى الترقية للوصول إلى هذه الميزة.

قم بالترقية الآن

Highlights

plate

هذا القسم متوفر فقط للمشتركين. يرجى الترقية للوصول إلى هذه الميزة.

قم بالترقية الآن

Transcripts

plate

هذا القسم متوفر فقط للمشتركين. يرجى الترقية للوصول إلى هذه الميزة.

قم بالترقية الآن
Rate This

5.0 / 5 (0 votes)

الوسوم ذات الصلة
SAPCDS ViewsAssociationsJoinsData ModelingCardinalityABAPHANAProgrammingSales Order
هل تحتاج إلى تلخيص باللغة الإنجليزية؟