首页 > SAP > ODATA > $filter Query Option in SAP OData Service
2019
08-26

$filter Query Option in SAP OData Service

Hello everyone, in this tutorial we will learn how to use query option $filter in SAP netweaver gateway OData service. Before proceeding further we assume that you know how to build OData service in sap gateway.Access all SAP Netweaver Gateway tutorials here.Lets get started

1.What $filter query option does ?

Query option $filter adds filtering capabilities to the SAP gateway OData service. So that you can able to filter the OData service feed/collection based on the fields available in the Entity Type set.

2.Supported System Version

SAP NetWeaver Gateway Release-采购向厂商下P/O之后,必须透过一定权限经由主管对此张P/O做 release后才能收料 2.0 Support Package >=03

3.Business Example

A gateway OData service is getting all the products from the back-end system, but you don’t want to get all the products and you want to apply filters on the OData service so that required products are retrieved.

4.Syntax

http://<server>:<port>/sap/opu/odata/sap/<service_name>/ProductsSet?$filter=ProductId eq ‘HT-1000’

$filter = <fieldname> <operator> <value> , where:

<fieldname> is the name of the field.

<operator> must be from the list of supported operators.

<value> can be a string value and should be enclosed in quotation marks (‘value’).

5.How to Implement $filter query option in OData Service

In this section we will adjust the OData service to respond to $filter query option. $filter query option should be applied only to Entity Type sets. We assume that you have already build the OData service to get the list of products. if you have not click here.

1. After successful creation of OData service. Go back to service builder SEGW, Navigate to the ABAP workbench for the Product Entity set.

2. Code inside the method PRODUCTSSET_GET_ENTITYSET will look like below i.e before adjusting the service to $filter query option.

3. In the above code snippet, we have retrieved the list of products generally by providing the max rows.Now we will adjust the code to adapt it to the $filter query option. Filter query option is available in the method by accessing the importing parameter IT_FILTER_SELECT_OPTIONS.

4. Put the below code in the method PRODUCTSSET_GET_ENTITYSET to repond to the $filter query option.

5. What we did in the above step.First we got the filter select options for the “ProductId” and pass the select option range to the BAPI to get the required data.

[adsenseyu1]

6. From code perspective we are ready, so lets test the service by using the sap gateway client /IWFND/GW_CLIENT.

7. If we execute the service without adding $filer query option, then we will get all the products available in the system. If we add the $filter query option to the service our service will respond to that and it will give the results based on the filters provided. Test the service by providing the following URI with $filter on ProductId = HT-1000.

/sap/opu/odata/sap/ZDEMO_GW_SRV_SRV/ProductsSet?$filter=ProductId eq ‘HT-1000’.

8. Check the collection/feed, now you should get only the product what we have given in the filter. You can add N number fields with $filter query option.

6.


$filter Query Option in SAP OData Service - 第2张  | 优通SAP

Known Constraints on $filter query option

There are currently some limitations for query options $filter. Logical Operators supported as of now are  ‘eq’ , ‘ne’ , ‘le’ , ‘lt’ , ‘ge’ , ‘gt’ . startswith and endwith is not supported.Full list of supported options are listed in

最后编辑:
作者:yangsen
本站为个人博客网站,全由我个人维护,我从事SAP开发13年,其它ERP开发7年,基本都是零售行业。本站记录工作学习的过程, 有SAP相关询问专、兼职工作可随时联系我。 有网站相关的问题可直接在文章下方留言,或者联系我。 邮件:yan252@163.com给我。 QQ:415402519