Skip to Content

Step-by-step guide to build an OData Service based on RFCs – Part 3

Thanks for sticking to this multi-part step-by-step guide.

Looking into this part (3) means that you have successfully completed the first part (1) and the second part (2) and you are now curious to see how our EPM OData Service will be extended with an Association and a Navigation Property. This will allow us to navigate from the Sales Order to the related Sales Order Line Items by using a link instead of manually putting a filter together. Furthermore this also allows us to use the $expand statement to fetch the Sales Order together with all Sales Order Line Items in one http call.

We are still in the Service Builder and enhancing our project that we created in part 1 and extended in part 2.

1. Double-click Associations:


2. Choose the Create pushbutton:


3. Enter the following values for the Association and choose Enter:

Name SalesOrderSalesOrderItems
Principal Entity* SalesOrder
Principal Entity Cardinality* 1
Dependent Entity* SalesOrderItem
Dependent Entity Cardinality* M

*) This field has an input help

Now we will Create a referential constraint for the association

1. Expand the Associations node and the SalesOrderSalesOrderItems node and double-click Referential Constraints:


2. Choose the Create pushbutton:


3. Enter the following values and choose Enter:

Principal Key* SoId
Dependent Property* SoId

*) This field has an input help   


Now we create an association set for the association

1. Double-click Association Sets:


2. Choose the Create pushbutton:


3. Enter the values and choose Enter:

Name SalesOrderSalesOrderItems
Association* SalesOrderSalesOrderItems

*) This field has an input help


And finally we create a navigation property based on the referential constraint

1. Expand Data Model -> Entity Types -> SalesOrder and double-click Navigation Properties:


2. Choose the Create pushbutton:


3. Enter the following values and choose Enter:

Name SalesOrderItems
Relationship Name* SalesOrderSalesOrderItems

*) This field has an input help

Now we need to re-generate the runtime objects and we’re then ready to test the service

1. Choose the Generate pushbutton:


2. Verify that the runtime objects have been generated successfully:


3. Start the Gateway Client (Transaction /IWFND/GW_CLIENT) in a separate window to run the service. Provide the following URI to get the metadata for the service:

The Sales Order collection now includes a navigation property.

4. When you now select a sales order entry using
/sap/opu/odata/sap/ZGW100_XX_SO_SRV/SalesOrderCollection(‘0500000001’), for example, you can simply add the navigation link /SalesOrderItems to navigate to the line items without having to set a filter yourself:


5. And finally you can use $expand to read all sales order items for a given sales order in a single http call.
Simply provide the following URI:


The $expand statement is handled by the framework (no additional implementation is required). Since the framework does not know that both entities can be obtained using a single RFC call, it executes two calls to the underlying BAPI. This can be improved by manually implementing (re-defining) the GET_EXPANDED_ENTITY method.

So we are done. The Service is up and running.

I hope you enjoyed creating and consuming an OData Service that is based on RFC modules.

You must be Logged on to comment or reply to a post.
  • Hi Volker,

    Thx, these are a great tutorial series to get started with Gateway.

    But I'm having some troubles adding a navigation torwards the Product Detail, from the Sales Order Item entity. Do you have any pointers? Maybe this is a good idea for a part 4.



    • Hi Wouter,

      thanks for the feedback.

      Navigating from a Line Item to the related Product is a little trickier. This is because the URI that you use (e.g. ".../SalesOrderItemCollection( SoItemPos=..., SoID=...)/ToProduct" ) only has the key information of the Line Item. In order to be able to navigate to the product entry you first need to read the Line Item detail to fetch the related Product-Id, and from there fetch the entire product.

      Luckily this is taken care of by the Service Builder as well. You just need to make sure to maintain the Association and the Referential Constraint between the Line Item and the Product.


      Regards, Volker

      • Hi Volker,

        I did the same steps but unable to use the navigation or expand option? what was the issue.

        Below is the metadata for my service.

        <?xml version="1.0" encoding="utf-8" ?>

        - <edmx:Edmx Version="1.0" xmlns:edmx="" xmlns:m="" xmlns:sap="">

        - <edmx:DataServices m:DataServiceVersion="2.0">

        - <Schema Namespace="ZDEMO09_SRV" xml:lang="en" xmlns="">

        - <EntityType Name="Orderheader" sap:content-version="1">

        - <Key>

        <PropertyRef Name="Vbeln" />


        <Property Name="Vbeln" Type="Edm.String" Nullable="false" MaxLength="10" sap:label="Sales Document" sap:sortable="false" sap:filterable="false" />

        <Property Name="Erdat" Type="Edm.DateTime" Nullable="false" sap:label="Created on" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" />

        <Property Name="Erzet" Type="Edm.Time" Nullable="false" sap:label="Time" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" />

        <Property Name="Ernam" Type="Edm.String" Nullable="false" MaxLength="12" sap:label="Created by" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" />

        <NavigationProperty Name="OrderItemSet" Relationship="ZDEMO09_SRV.SalesOrder" FromRole="FromRole_SalesOrder" ToRole="ToRole_SalesOrder" />


        - <EntityType Name="OrderItem" sap:content-version="1">

        - <Key>

        <PropertyRef Name="Posnr" />

        <PropertyRef Name="Vbeln" />


        <Property Name="Pstyv" Type="Edm.String" Nullable="false" MaxLength="4" sap:label="Item category" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" />

        <Property Name="Matkl" Type="Edm.String" Nullable="false" MaxLength="9" sap:label="Material Group" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" />

        <Property Name="Matnr" Type="Edm.String" Nullable="false" MaxLength="18" sap:label="Material" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" />

        <Property Name="Posnr" Type="Edm.String" Nullable="false" MaxLength="6" sap:label="Item" sap:sortable="false" sap:filterable="false" />

        <Property Name="Vbeln" Type="Edm.String" Nullable="false" MaxLength="10" sap:label="Sales Document" sap:sortable="false" sap:filterable="false" />


        - <Association Name="SalesOrder" sap:content-version="1">

        <End Type="ZDEMO09_SRV.Orderheader" Multiplicity="1" Role="FromRole_SalesOrder" />

        <End Type="ZDEMO09_SRV.OrderItem" Multiplicity="*" Role="ToRole_SalesOrder" />

        - <ReferentialConstraint>

        - <Principal Role="FromRole_SalesOrder">

        <PropertyRef Name="Vbeln" />


        - <Dependent Role="ToRole_SalesOrder">

        <PropertyRef Name="Vbeln" />




        - <EntityContainer Name="ZDEMO09_SRV" m:IsDefaultEntityContainer="true">

        <EntitySet Name="OrderHeaders" EntityType="ZDEMO09_SRV.Orderheader" sap:pageable="false" sap:addressable="false" sap:content-version="1" />

        <EntitySet Name="OrderItems" EntityType="ZDEMO09_SRV.OrderItem" sap:pageable="false" sap:addressable="false" sap:content-version="1" />

        - <AssociationSet Name="SalesOrderSet" Association="ZDEMO09_SRV.SalesOrder" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:content-version="1">

        <End EntitySet="OrderHeaders" Role="FromRole_SalesOrder" />

        <End EntitySet="OrderItems" Role="ToRole_SalesOrder" />



        <atom:link rel="self" href="$metadata" xmlns:atom="" />

        <atom:link rel="latest-version" href="$metadata" xmlns:atom="" />






  • Hi Volker,

    Your Tutorial has been very helpful. I am learning Webservices from scratch.

    I have a doubt.

    I cant find the ASSOCIATION SETS block in my SEGW Project. Would there be a reason for this?



    • Hi Abraham,

      I assume you are using a newer version of SAP NetWeaver Gateway (the blog was written for SP5)?

      The Gateway Framework is automatically generating the Association Sets based on the defined Associations. That's the reason why the Service Builder is not showing them in the navigation tree anymore. But you can still create own Association Sets if you want (Right-Click on Data Model and choose Create -> Association Set).

      Best Regards, Volker

  • Hi Volker,

    I would like to add few comment to this wonderful blog.

    People who are working on higher version of SAP Netweaver Gateway services who can't see the Associate Sets and Navigation folder in Gateway Service Builder Project they can actually follow navigation using following link

    Association and Navigation in OData Service - SAP Netweaver Gateway - SAP Fiori,SAP HANA,SAPUI5,SAP Netweaver Gateway Tu…

    This is only for navigation still they need to follow the same naming convention what you used in this document


  • Hi Volker,

    Can you explain what is the difference between




    I think out put is looking same

    what is the use of $expand



    • Hi Uma,

      there is a typo in your URI. The '$' is missing. It should look like:


      With this you will see a difference.

      Best Regards,


  • Step by step and succinct: Enough detail so we can't make any mistakes, not so much that we get confused as to what's going on. This is one I shall be showing to others when they need guidance!

  • Hey volker,

    I am new to the Odata services, can you explain in the same way for all the CRUD properties.
    That would be very helpful.

    Thanks and regards,

  • hi volker,

    very useful blog . Me and one of my friend were following your  blog ,he successfully completed the task using association and navigation.

    When i am looking for all data it is ok.

    but i am facing unknown problem Can u please help me out.

    My mHeaderset is working fine it is giving back the required table entries, but when i am trying to retrieve the specific data it is throwing me 404.

    it is not taking my service. what can be the reason for it?


    • Hi Vijay,

      Can you put a break point in entityset method and check if the sales order which you are trying to retrieve has done conversion(CONVERSION_EXIT_ALPHA_INPUT).




  • Hi Volker

    Hope you are doing good.As per the below screen the metadata connection is working fine and also completed part 3 .


    The below step is not working for me when I am trying to fetch fields instead of $metedata I am using SalesOrderCollection.Can you help to support as I need to provide a demo.Or If any case you can provide or number or chat window where we can discuss.


    4. When you now select a sales order entry using
    /sap/opu/odata/sap/ZGW100_XX_SO_SRV/SalesOrderCollection(‘0500000001’), for example, you can simply add the navigation link /SalesOrderItems to navigate to the line items without having to set a filter yourself.This portion is not working and I am getting error 404.Can you help to resolve this step.