首页 > SAP > HANA > $skiptoken Query Option in SAP OData Service
2019
08-27

$skiptoken Query Option in SAP OData Service

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

Query option $skiptoken is used to limit the amount of entries sent to the application.This also helps in boost-up the performance if huge number of entries requested.A next link is provided back to the application to get the next bulk of data.Server side paging is achieved by adapting the skiptoken.

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 want to restrict the amount if data from server side by paging. You can achieve this by setting skiptoken.

4.Syntax

http://<server>:<port>/sap/opu/odata/sap/<service_name>/ProductsSet?$skiptoken=10

5.How it works ?

You have to define the page size in the server i.e GET_ENTITYSET method in the DPC_EXT class.
If entries in the entity set are more than the page size,divide the entries by page size.
Send the requested set of entries to the application based on skiptoken value and also the next link to next set of entries. For more details see the image below.

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

In this section we will adjust the OData service to respond to $skiptoken query option. $skiptoken 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 $skiptoken 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 $skiptoken query option to restrict the amount of data sent to the application by paging in the server.

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

5. What we did in the above step.First we got all the products and then check $skiptoken query option is requested if so, then send only the bulk of data based of the page size.

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 by adding the $skiptoken=10 query option, we should get the only the set of entries(page size) in the response with link to next set of entries. Test the service by providing the following URI with $skiptoken=10.

/sap/opu/odata/sap/ZDEMO_GW_SRV_SRV/ProductsSet?$skiptoken=0′.

/sap/opu/odata/sap/ZDEMO_GW_SRV_SRV/ProductsSet?$skiptoken=10′.

Stay tuned to us for more SAP Netweaver Gateway tutorials.

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

最后编辑:
作者:yangsen
有需要可在文章留言或者邮件yan252@163.com给我。