Netweaver Gateway Development

how to implement Association/Navigation in SAP OData service?

        An association is a named relationship between two or more entities.Association defined a peer to peer relation ship between entitytypes and can have different multiplicity.Example for association is relation between salesorder and line item entities.
      When creating an association a navigation property is created in principal entity.Navigation properties describe the navigation path between the related entities.It is property of an entity that provide a link from one entity to related entities.
       In this tutorial we will create an association from our flight entity set to flight schedule entityset. 

  1. GET_ENTITYSET of flightset implemented already.(GET_ENTITYSET implementation)
  2. GET_ENTITY of flightset implemented already.(Refer OData Service Implementation for GET_ENTITY)
  3. FlightScheduleSet created by importing ddic structure SPFLI table(Please refer  my previous post step-by-step-gateway-odata-service)



  1. First step is creating association.For this Open the service and click on edit button.Expand Data Model.Right click on Associations and click on create button.Association wizard will be opened.

  2. In the association wizard you have to give Association Name,Principal entity type name,Dependant entity type name,cardinality and Navigation Property name.Navigation Property name is used when accessing associated entity data in our OData url.(Create related navigation property check box will be checked by default).After entering values to these fields click next.
  3. You will land on step 2 of association wizard.Select dependent property and click next.Dependent property will be the key relating two entities.
  4. In step 3 select Principal entityset and dependant entityset and click finish.
  5. Finally our odata service should look like this.See navigation propery is added to flight entity set.Also an association and association set is created.Press generate button.
  6. Easy part is over.Lets do some coding.We have to code inside getentityset method of our new entityset FlightSchedule.For this Open our project and expand service implementation node and right click on GetEntitySet(Query) of FlightScheduleSet and click on Goto ABAP Workbench.
  7. You will now land on class builder with ****_DPC_EXT opened.We write our code in this class.Expand methods node.expand inherited methods node.Right click on FLIGHTSCHEDULESE_GET_ENTITYSET and click redefine.(If it is already done open this method)
  8. Paste below code inside the method.Here we access the key from the url and populate data according to this key.
  9.      data:  ls_key_tab type /iwbep/s_mgw_name_value_pair,
               lv_carrid  type spfli-carrid.
    *Get the key property values
        read table it_key_tab with key name = 'Carrid' into ls_key_tab.
        lv_carrid = ls_key_tab-value.
        if lv_carrid is not initial.
          select carrid connid countryfr cityfrom airpfrom cityto from spfli into corresponding fields of table et_entityset
            where carrid = lv_carrid.
          select carrid connid countryfr cityfrom airpfrom cityto from spfli into corresponding fields of table et_entityset.
  10. Now we can test  in gateway client( /IWFND/GW_CLIENT).Our service url look like this.http://<host>:<port>/sap/opu/odata/SAP/ZTEST_ODATA_SRV_01/FlightSet('AA')/ToFlightSchedules.Press execute button.ToFlightSchedules is the navigation property.


If you enjoyed this post, Please Share!!


Powered by Blogger.