OData and SAP Netweaver Gateway. Part IV. Association and Navigation in OData Service

Association and Navigation in OData Services

Till Part III of our Tutorial series on SAP Netweaver Gateway and OData, we have designed our data models to fetch header data from EKKO and item data from EKPO independently. POHeaderSet and POItemSet do not talk to each other as of now. In real projects, we need to manipulate item data based on input from the header or other entity types and vice-versa. So there has to be a connecting link between them. In SAP Netweaver Gateway jargons, we call them Associations and we need to create Associations (and Navigation Properties) between the entity types of the data model.

Association specifies the cardinality between Entity Types. When an Association is created, a Navigation Property of the Entity Type is also generated. The Navigation tells the relationship between entities with the help of Association which it points to and the Association, in turn, tell the cardinality relationship between entities.

Let us create one Association and check how it looks in the system. Go to t-code SEGW, under Data Model, right-click on the Association folder and Create your first Association.
Steps to implement Association in OData

You need to specify the Key (Dependent Property like Foreign Key concept) between the Principal Entity and Dependent Entity.
Understanding Association vs AssociationSet vs Navigation Property

AssociationSet is also generated, in case we want it for multiple entries (i.e tables/arrays).

What is Association Set?

Hit the Finish icon and Association, Navigation Property and Association Set are generated.

What is OData?

The below figure sums up the relationship between Entities, Navigation Property, Association and AssociationSet.


Do we still need to define what Navigation Properties, Association and Association Set are?

The above code snippet and image above shows that Navigation Properties are defined for Entity Types. It points to the association type via Relationship. It also specifies the direction of flow using FromRole and ToRole. In short, Navigation Property helps to navigate between association.

Similarly, the above code and the image above confirm that Association provides the cardinality (multiplicity) of the FromRole and ToRole. It, in turn, has a Referential Constraints which tell the Key field which joins/links the principal and dependent entity. FromRole and ToRole specify the Direction of flow of data. To sum up, Association is the relationship name between two entity types (one being the origin and other is destination point).

AssociationSet is the Association between EntitySets. This is the link between tables(arrays). As clearly visible in the above picture, Association Set points to the Association. To put it simple, AssociationSet has all the properties (cardinality, data flow direction, entity) of the associated Association.

Let us check the how the metadata of the service look after we added the above Association.

URI: /sap/opu/odata/sap/ZGW_PO_SRV/$metadata

Navigation in SAPNWGW

Did you notice, the metadata has the signature of the Navigation Property of the Entity Type? Also, check the response below for the Association and AssociationSet definition.

SAP Netweaver Gateway

We have been using the below URI to fetch one entry of the PO Header in our previous articles. If you try to execute the same URI again, this time, you would notice there is an additional link. This additional new link has the Query Option with the Navigation Property we created above.

URI: /sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet(‘4500002012’)

Navigation Property

The result of the POHeaderSet with one primary key as Query option shows a new href link. It gives the hint that we can navigate to the PO Item data by adding the Navigation Property the Query option.navigate

If you expand one entry of the above result, you would be able to view an alternative link to get the exact one PO Item. The alternate Link to get one specific PO Item is displayed in the result of POHeaderSet query. Isn’t that useful?

URI: /sap/opu/odata/sap/ZGW_PO_SRV/POItemSet(Ebeln=’4500001729′,Ebelp=’00010′)

SAP Netweaver Gateway and OData

Que: What is the difference between the below two URIs?
URI 1: /sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet(‘4500001729’)/HeadToItemNav
URI 2: /sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet(‘4500001729’)?$expand=HeadToItemNav

Ans: First URI would pull the item level entries only while the second URI would pull the item level entries and also display the header level data. In short, the $expand query option is expanding the Header information with the help of the Navigation property and showing the dependent entity type.

As of now, we witnessed data flow from Header to Item. Let us introduce one more entity type which can be associated with the Item. I mean we will build a navigation link from POItem Entity to this new Entity Type. The data of this new Entity Type would be updated, deleted and created. In short this new Entity Type and Entity Set would be our Guinea Pig for our CRUD Operations in subsequent posts.

Before we create the Entity Type, let us create a simple DDIC Table ZEKKOEKPO (EKKO EKPO union) as shown below which we will use in our OData Service.

Now let us create the new Entity Type and EntitySet zekkoekpo and zekkoekpoSet respectively. Please check we have created the Entity Type zekkoekpo in lower case deliberately to show that the Entity names are case sensitive. You can check the issues which would arise due to the case of the name in subsequent posts.

By now you should know the next step. We need to implement the METHODs of the Operations we want to use for this new entity type zekkoekpo. If you still do not know how to implement and redefine the methods, then all our effort till now went in vain. 🙂 .


Please refer to Create Your first OData Service and URIs in OData articles to check how to implement and redefine the Data Provider Class Methods.

We have redefined two methods with no line of code. Let us check how our OData Service behave. For testing purpose, put external breakpoints at both the Entity Methods.

Please do not forget to re-generate your OData Project after you add/remove any Entity Type or any other component.

i. Let us call the URI which is supposed to call the GetEntitySet Method.

URI: /sap/opu/odata/sap/ZGW_PO_SRV/zekkoekpoSet

BreakpointsCheck the GetEntitySet Method is triggered for the EntitySet Resource.

ii. Now let us call the URI which would call the GetEntity Method.

URI: /sap/opu/odata/sap/ZGW_PO_SRV/zekkoekpoSet(Ebeln=’4500003480′,Ebelp=’10’)
As expected,GetEntity Method is triggered when we pass the primary keys of the Entity.

We found, our methods get triggered even with no code in it, so now we can write our logic. Let us write simple code to extract data from EKKO and EKPO and put in our Entity Type zekkoekpo.


Let us test this URI for the new code we implemented.

URI: /sap/opu/odata/sap/ZGW_PO_SRV/zekkoekpoSet(Ebeln=’4500003480′,Ebelp=’10’)

We are good till now. Data is fetched and displayed using our logic. Now let us create an Association between the POItem and zekkoekpo Entity Types.

Let us check the metadata again. It would show the new Navigation Property, Association and AssociationSet.
URI: /sap/opu/odata/sap/ZGW_PO_SRV/$metadata

Let us test the Navigation Property

Assume, you do not know how to frame the Query Option using the Navigation Link in the URI. Then just frame the URI for one POItemSet which you already know. Check the XML for the href. There you would have all the links to get the same value using other URI.

For this URI: /sap/opu/odata/sap/ZGW_PO_SRV/POItemSet(Ebeln=’4500003480′,Ebelp=’10’)

Check the XML for the Navigation Property.

Now let us call our URI along with the new Navigation Query Option
URI: /sap/opu/odata/sap/ZGW_PO_SRV/POItemSet(Ebeln=’4500003480′,Ebelp=’10’)/ItemToCustomNav

This is the basic about Association, Association Set and Navigation Property. Try to follow a naming convention to differentiate the Navigation and Association and Association Set. Most of us try to give the same name for Association and Navigation property. So, when we use them in URI to frame the Query Option, we are confused whether it is a Navigation Property or Association. Adding an identifier like Nav, Ass, AssSet helps to identify what you are working with.

I wanted to show some more CRUD (Create, Read, Update, Delete) Operations in this post, but I think that chapter needs more respect than just a mention. Next article would be dedicated to CRUD. We would check two-way navigation between entity types and entity sets.

We would also venture into the other Operation methods like POST, PUT, DELETE etc. As of now, we have used only GET Operation. We will populate data in our Guinea Pig Entity Type zekkoekpo and bring it to life. Please stay tuned.

Next Part V: CRUD Operations in OData Services

If you GENUINELY like our articles then it would be a HUGE help if you subscribed and liked us on facebook. It might seem insignificant, but it helps more than you might think.

Do you have anything to add to this article? Have you faced any issue understanding OData or SAP Netweaver Gateway? Do you want to share any real project requirement or solutions? Please do not hold back. Please leave your thoughts in the comment section.

Thank you very much for your time!!

Call for Guest Authors and Contributors to write SAP Articles on our page and get noticed and also receive cool Gifts.

Do you have any tips or tricks to share? Do you want to write some articles at SAPYard? Please REGISTER and start posting and sharing your knowledge to the SAP world and get connected to your readers. Please check our simple guidelines for contributing your articles and receiving the gifts.

Step by Step Tutorials on SAP Netweaver Gateway and OData

Also, Check Step by Step Tutorials on SAPUI5

We have a very active Telegram SAP Technical Group. Please join it using below link.
Telegram SAP Technical Discuss Group.

WhatsApp had the limitation of 256 members per group and we were finding a hard time syncing and maintaining information in multiple WhatsApp group. Therefore we have moved to Telegram as it can accommodate more than 10,000 users. Please join.


      • Hi SAP Yard gurus,

        I have followed the exact steps, and got the output , however when i try to use these steps in my SAP UI5 to display the PO items, it is not working, it is showing as bad request. Here is my piece of code in my V_POITEM.controller.js which is created through SAP WEB ID, and i am trying to display all the line items of the Particular PO in xml views:

        code in V_POITEM.controller.js
        onInit: function() {
        var oRouter = sap.ui.core.UIComponent.getRouterFor(this);

        oRouter.getRoute(“Target_POItem”).attachMatched(this._onRoutefound, this);


        _onRoutefound: function(oEvt) {

        var oArgument = oEvt.getParameter(“arguments”);

        var lv_po = oArgument.SelectedPO;

        var oModel = new sap.ui.model.odata.v2.ODataModel(“/sap/opu/odata/sap/ZGW_PO_N_SRV/POHeaderSet(‘” + oArgument.SelectedPO + “‘)/HeadToItemNav”);

        var oView = this.getView();

        var oTable = this.getView().byId(“it_item”);
        var oBinding = oTable.getBinding(“items”);

        var allFilter=[];
        oBinding.filter(allFilter, sap.ui.model.FilterType.Application);

        code in V_POITEM – VIEW :

        Request you to throw some light .


        • Hi Yoga – Thank you very much for following our article and leaving the comment. Did you copy the code from our post? If yes, try to replace the ” (quotes single and double) in the code and press ” (quotes) manually in your code. Is your Service name correct?

          When you test your service in /N/IWFND/GW_CLIENT does it give success result?

          Team SAPYard.

          • Hi,
            Many thanks for your kind reply.

            1. when I ran transaction /N/IWFND/GW_CLIENT with the following URI Ex: with po 3000000997 It produced all the items of this po correctly.

            /sap/opu/odata/sap/ZGW_PO_N_SRV/POHeaderSet(‘3000000997’)/ HeadToItemNav

            2. I have created services with name ZGW_PO_N_SRV, which is an
            Association of PO header and items. I have used double quotes not copied from site.

            On click of particular PO, it would go to second screens , and display header details, but on click of po items button, it would go third screen , but with this path it is showing as /$metadata 400 (Bad Request) .
            Not sure from where this /$metadata is being concatenated. I am using WEB IDE to develop my UI5 app.
            it is working fine for first screen , where it is showing all PO, on click of particular PO It is going to second d screen, on click of po items i am facing this challenge.

            Note :
            MY PO set and PO item set are in same URI PO set:

            PO item set URI :

            Request you to help me to resolve this Association used in UI5.

            Thanks in advance.


  1. First of all: thank you very much ! Your pages are very, very, very good.

    About this article: perhaps it is worth to describe how to proceed if you have dependencies with unequal database keys like this:

    Scenario: production orders
    Header: AUFK (key field = AUFNR)
    Add. header: AFKO (key field = AUFNR, none key field AUFPL but further relation to items=operations)
    Item: AFVV (key fields = AUFPL + APLZL)
    Add. item: AFVC (key field = AUFPL + APLZL)

    Ok, no problem to link AUFK and AFKO and no problem to link AFVV and AFVC.

    But how to link header and items together by association ?
    You will get no key field match in association wizard step 2.
    You have to link AFVV (key fields AUFPL + APLZL) with AFKO (key field AUFNR) by none-key field AUFPL.

    How to preceed ? Thank you very much !

    Best regards and happy new year …

    • Thank you Sudarshan for stopping by and leaving your feedback. Hope you liked the whole series on OData and Netweaver Gateway.

      Please keep visiting. Please share our links with your colleagues, team members and friends.

      Team SAPYard.

    • Dear Ram – Sure. We will prepare and publish the step by step installation guide. Please stay tuned.

      Thank you for leaving your question.

      Team SAPYard.


Please enter your comment!
Please enter your name here