首页 > SAP > ODATA > $inlinecount query option in sap OData service
2019
08-29

$inlinecount query option in sap OData service

Hello everyone, in this tutorial we will learn how to use query option $inlinecount 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 $inlinecount query option does ?

Query option $inlinecount is used to get the overall count of feed/collection together with the entity set collection data.

2.Supported System Version

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

3.Business Example

A gateway OData service is getting all the products from the back-end system. You also want the count of the queried collection. In this scenario you can use ‘$inlinecount=allpages’ query option to get both count and entity set collection data in a single OData call.

4.Syntax

http://<server>:<port>/sap/opu/odata/sap/<service_name>/ProductsSet?$inlinecount=allpages

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

In this section we will adjust the OData service to respond to $inlinecount query option. $inlinecount 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 $inlinecount query option.

3. In the above code snippet, we have retrieved the entire list of products.Now we will adjust the code to adapt it to the $inlinecount query option to get the count of collection as well in the response.

4. Put the below code in the method PRODUCTSSET_GET_ENTITYSET to respond to the $inlinecount query option.

5. What we did in the above step.First we got all the products and then check $inlinecount query option is requested if so then provide the count in the response ES_RESPONSE_CONTEXT-INLINECOUNT of the OData service .

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 $inlinecount query option, we should get all the products available in the system.

If we add the $inlinecount=allpages query option to the service we should get the count in the response with collection data as well. Test the service by providing the following URI with $inlinecount=allpages.

/sap/opu/odata/sap/ZDEMO_GW_SRV_SRV/ProductsSet?$inlinecount=allpages’.

Stay tuned to us for more SAP Netweaver Gateway tutorials.

Thank you. Please feel free to comment and let us know your feedback.

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