Netweaver Gateway Development

how to implement Sorting($orderby) in SAP OData service?

             OData developers can make use of query option $orderby for sorting the resultset obtained by GET_ENTITYSET implementation.Order-by parameters are provided by the framework in Get_EntitySet method via the import table IT_ORDER. The table contains an entry for each property provided in the $orderby query option.
             For each property, you can decide if you want the collection to be sorted as ascending (suffix asc) or descending (suffix desc). Ascending is the default setting, so the  asc doesn’t need to be provided explicitly.
            In this tutorial we will sort the result of our GET_ENTITYSET result set mentioned above.


  1. Open our project and expand service implementation node and right click on GetEntitySet(Query) and click on Goto ABAP Workbench.
  2. Open our FLIGHTSET_GET_ENTITYSET method.Inside this method paste below code. it_order at runtime contain $orderby values.We can either read this internal table or acces it from io_tech_request_context.

  3. Fetch data based on the $orderby parameter.Apply your own logic for better performance.

  4. 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?$orderby=Carrname desc.Press execute button.
If you enjoyed this post, I’d be grateful if you’d help it spread by sharing.Thank you! See you soon


Post a Comment

Powered by Blogger.