首页 > SAP > ODATA > Association and Navigation in OData Service – SAP Netweaver Gateway
2019
08-29

Association and Navigation in OData Service – SAP Netweaver Gateway

Hello everyone, in this tutorial we will learn about Association and Navigation concepts in SAP Netweaver Gateway.Association and Navigation are two important properties available in SAP Netweaver Gateway to associate two entity types.

Let us understand this with an example, in our earlier tutorials we retrieved sale-ale settingss order header data and item data in two different entity types “SalesOrderSet” and “OrderItemsSet”.

These two entity types are individual and can be executed differently.But what we want here is based on selected Sales Order# we would like to pull the item data from other entity type.This is can be achieved using association and navigation property.Lets look at that.

1. Go to Service Builder SEGW and expand the service to create an association

2. Provide the following information and Click on Next.

Principal Entity – To which you want to build the association
Dependent Entity – From which you want to get the data based on association
Cardinality – What the occurrence of no records
Navigation Property – Name of the navigation property for the Entity Type

3. In the next screen, provide the common field among two entity sets and click on Next.In our case Sales Order Id is the common field.

4. Check the entries and Click on Finish.

5. This creates a navigation property for “SalesOrder” Entity Type and association property in OData service.

6. Regenerate the service once again.You can observe that meta data of the service is grown because of our newly added association and navigation property. To access the order items based on order# we just need to add the name of the navigation property of the Entity Type. If you try to execute the service now, you will run into error, we need to enhance the method GET_ENTITYSET of “Orderitems” entity type to get the data.

/sap/opu/odata/SAP/ZSL_EPM_DEMO_SRV/SalesOrderSet(‘500000000’)/ToOrderItems

7. Open and enhance the code inside GET_ENTITYSET method of “Orderitems” entity type.Why only this method we call the URI with navigation property based on the cardinality of dependent entity methods we get triggered. In our case our cardinality is 1..n of dependent entity i.e “Orderitems” so GET_ENTITYSET has to be enhanced.

8. If you go to that method you will find the code which we have already written for “Orderitems“, replace that code with the below code.

9.After activating the code. Try now the same URI to get the line items of a order, you should be able to see the items only specific to the order you have provided in the URI.

/sap/opu/odata/SAP/ZSL_EPM_DEMO_SRV/SalesOrderSet(‘500000000’)/ToOrderItems

Now you have successfully implemented the Association and Navigation in SAP Netweaver Gateway.

Stay tuned for is for more SAP Netweaver Gateway tutorials. Please feel free to comment and let us know your feedback.

Thank you.

最后编辑:
作者:yangsen
本站为个人博客网站,全由我个人维护,我从事SAP开发13年,其它ERP开发7年,基本都是零售行业。本站记录工作学习的过程, 有SAP相关询问专、兼职工作可随时联系我。 有网站相关的问题可直接在文章下方留言,或者联系我。 邮件:yan252@163.com给我。 QQ:415402519