Preface – This post is part of the SAP ABAP OData Tutorial series.
In this article, we will learn how to use $top and $skip query in our OData services.
Table of Contents
What is the use of $top $skip query?
The OData query $top and $skip are used to restrict the data from the backend.
To achieve the client-side pagination, we can use $top = n query and $skip = m is used in coordination with $top. $top query fetches the top n records skipping first m records.
System version
SAP NetWeaver Gateway Release 2.0 Support Package >=03
Syntax
- http://<server>:<port>/sap/opu/odata/sap/<service_name>/EntitySet?$top=5
- http://<server>:<port>/sap/opu/odata/sap/<service_name>/ EntitySet?$top=5&skip=3
Business Example
- You want the first 5 records of Products. Or we want the first 10 roll number students in our result.
- Teach wants first 10 roll number students skipping first 5.
Implementation
In this section, we will implement $top and $skip on our Product Entity Set.
Step 1: After the creation of OData service, right Click on Entity Set under Service Implementation, go to ABAP workbench.
Step 2:
Adjust your code for $top and $skip query.
In the above code, we retrieved all the product details and applied $top and $skip query to get the required output.
Step 3:
Add $top and $skip query in OData URL and execute the service.
Service URL: /sap/opu/odata/sap/ZProduct_Srv/ProductsSet?$top=5
0 Comments