Skip to Content
Technical Articles

OData Associations using CDS view associations

In this Blog we will cover a simple example to illustrate how CDS view associations translates to OData service associations.

The advantage of associations in CDS views is that the data is provided/join is executed only when needed also known as Join on Demand. By default, left outer join is executed at runtime when a field from the associated table is used/called. However, other join conditions can be specified as well.  For example, in the CDS view below, only when a field from table ZTB_MAT_TAB is used, only then the left outer join between MARA and this table is executed and data is made available –

This same concept is applicable when using associations in OData services, by using associations in CDS views and using annotation OData.publish: true, all settings needed otherwise in SEGW can be avoided, the system automatically takes care of it.

Create a CDS view similar to the one above with the fields needed for your business case. Register it in /IWBEP/MAINT_SERVICE.

You can now test the association in SAP Gateway client using similar URI

Getting All Materials –

/sap/opu/odata/sap/ZI_MAT_TAB_CDS/ZI_MAT_TAB$format=json

Getting details from ZTB_MAT_TAB above for a single material(Association call) –

/sap/opu/odata/sap/ZI_MAT_TAB_CDS/ZI_MAT_TAB(SKU=’ABCD’)/to_MATTAB?$format=json

This example is a very simple one, however, you could have a number of fields displayed, say for example all/many Purchase order header fields. On click of details of a purchase order, all line items can be displayed using the association call similar to the URI above enabling join on demand with no additional programming.

/
2 Comments
You must be Logged on to comment or reply to a post.
  • I’m not sure what additional value that “blog post” (if that what we see deserves the name at all) add. Such a simple example is available in every documentation, in different blog posts and at several other places. What is special in your example here, I do not really see anything. Have I missed something?