Netweaver Gateway Development

how to implement $filter query option in SAP OData service?

            $filter query option is the most used query option whil accessing OData service.The framework does not provide default filtering.We need to implement it ourself.$filter query option allows us to filter the result set of GET_ENTITYSET implementation.
          In this tutorial we will use GET_ENTITYSET method from our earlier tutorial 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.Our filter query passed from service call is inside import paramete it_filter_select_options .We will loop at this table and fetch the filter parameter into a table of structure SELOPT(SELECT-OPTIONS IN ABAP).

  3. Fetch data based on the filter query.

  4. Now we can test our filter query in gateway client( /IWFND/GW_CLIENT).Our service url look like this.http://<host>:<port>/sap/opu/odata/SAP/ZTEST_ODATA_SRV_01/FlightSet?$filter=Carrid eq 'AC'.Press execute button.
Note:Some times filter query can become complex.With abap SELECT-OPTIONS structure we cannot cover all scenarios like  a filter such as FieldA eq ‘A’ or FieldB eq ‘B’ can’t be put into our table because of OR in the filter.In suchcases we can use import parameter IV_FILTER_STRING .Then our select statement should change like this.

If you enjoyed this post, I’d be grateful if you’d help it spread by sharing.Thank you! See you soon


  1. Very nice tutorial..
    Can you please elaborate more on applying filter for multiple columns? I did not get what this query does..

    Can you please pick an example and explain similar to this blog..

    1. Hi,
      IV_FILTER_STRING will have the search string as it is at run time.You can check this by putting an external break point and find the difference.
      For multiple columns you can try the same.just check what it_filter_select_options holds?.For this use this url
      http://:/sap/opu/odata/SAP/ZTEST_ODATA_SRV_01/FlightSet?$filter=Carrid eq 'AC' and Carrname eq 'yourValue'

    2. HI , can you please take a sample for this IV_FILTER_STRING . It seem to be different than singe filter operation.
      How can I convert IV_FILTER_STRING to it_filter_select_options ?

    3. Hi Hoang Thai,
      You can put an external break-point in segw and check the variable yourself.


Powered by Blogger.