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 –
Getting details from ZTB_MAT_TAB above for a single material(Association call) –
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.