cancel
Showing results for 
Search instead for 
Did you mean: 

What exactly is associations in CDS view? And its benefit over JOIN?

former_member197071
Participant
0 Kudos

Hi,

What exactly is the benefit of using associations in CDS view instead JOIN?

I read Associations are metadatas about joining connections. Actual join is created when the association is used in a path expression. Refer to https://blogs.sap.com/2017/03/07/inner-join-with-cds-associations-abap-on-hana/

But what is path expressions? Can anybody help me with this?

Also I Googles for associations cardinality information but did not found a proper documentation.

Can anybody please help me?

Accepted Solutions (1)

Accepted Solutions (1)

Jocelyn_Dart
Product and Topic Expert
Product and Topic Expert

Thanks James.

Hey Ankur,

You use a Join when you want to combine data in the same read from the database. For example, if I am displaying a list of Sales Orders I might want to get the vendor name along with the vendor id in the one read which I use to display a list of Sales Order headers, because that's information I always need to show.

You use an association when you want to NAVIGATE from one entity to another in a UI. I don't always need to drill down to every sales order. I can delay reading the Sales Order Items unless and until the user drills down to them. So I want an association from my Sales Order header joined view to my Sales Order Item view. That sets up an easy navigation but also that navigation won't be used unless the user needs it. So the overall UI will perform better because it only reads the data it needs to.

SAP uses the standard and recommended OData approach for path expressions.

The path expressions are used when navigating from one entity to another. You can see this explained in more detail in http://www.odata.org/documentation/odata-version-2-0/uri-conventions/ where they talk about addressing entities. In other words the path expression defines how you move from e.g. the Sales Order header to the Sales Order items using the OData association.

Rgds,

Jocelyn

Former Member
0 Kudos

Hi Jocelyn,

Thanks for this excellent answer.

I still have a doubt how associations are useful in analytic scenarios (its benefits over join).

If you include an association in select list in analytic cds views, the association cannot be accessed in reporting tool (unlike OData). Element list of association needs to be explicitly specified so that reporting tools like Bex are able to access the association elements.

The moment you include explicit list of elements in the view - you are no longer requesting fields "on demand". In that case, how would association benefit over join?

Thanks,

Anup

Answers (2)

Answers (2)

Former Member

A bit late but it may help someone's search.

I am no expert on CDS yet but learning. I had been just using joins in my CDS views but I am getting ready to use associations because they let me set up navigation between two CDS views so that in my Fiori App, I can go from header table to detail item table.

I will create One CDS view as the HEADER table with association to the ITEM table.

I will create another CDS view as the ITEM table with association to the HEADER table.

I will create a third table known as a "consumption view", It will expose the fields from both the HEADER and the ITEM and will be used to publish an OData Service that I can then use in a Fiori app.

There is a great blog about this here: My CDS view self study tutorial – Part 5

0 Kudos

Hi,

Association in CDS views is same as joins only, but to overcome from some disadvantages of joins, Associations came into existence in CDS views.

When we use joins, the following disadvantages comes,

1) Whether we need data at the end of for joined table or not , the JOIN will always be performed, which is a cost to data base.

2) When we create an ODATA service on such a view , The service will expose all the data always, whether we need or not, so it will cause high network traffic.

3) Writing join is too technical from developer point of view.

Regards,

Tanuja.