In this article, we will learn how to use $top and $skip query in our OData services.
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.
SAP NetWeaver Gateway Release 2.0 Support Package >=03
- http://<server>:<port>/sap/opu/odata/sap/<service_name>/ EntitySet?$top=5&skip=3
- 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.
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.
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.
Add $top and $skip query in OData URL and execute the service.
Service URL: /sap/opu/odata/sap/ZProduct_Srv/ProductsSet?$top=5