Skip to Content
Technical Articles
Author's profile photo Nitin Sharma

Difference between $skip and $skiptoken in Odata

Introduction

When working with large datasets in SAP OData, server-side paging can be a useful technique for improving performance and reducing the amount of data that needs to be transmitted over the network. Two commonly used parameters for server-side paging are $skip and $skiptoken. While they may seem similar, they serve different purposes and have different use cases.

In this technical blog, we will explore the difference between $skip and $skiptoken in SAP OData and provide examples of how they can be used in different scenarios. We will also discuss best practices for using these parameters and provide tips for optimizing performance when working with large datasets.

 

What is $skip : Please refer to this blog for more details about $skipImplementing All OData Query/URI Options – Part 2

What is $skiptoken: Please refer to this blog for more details about $skiptoken Implementing All OData Query/URI Options – Part 2

 

Difference between $skip and $skiptoken:

$skip is used to skip a specified number of items in a collection of data before returning the remaining results. For example, if we want to retrieve all employees after skipping the first 10 employees, we would use the following query:

/sap/opu/odata/sap/<service_name>/Employees?$skip=10

This query would skip the first 10 employees and return the remaining employees in the “Employees” entity set.

On the other hand, $skiptoken is used to enable efficient server-side paging of query results when the size of the data set is too large to be retrieved in a single request. When a server returns a limited number of results along with a $skiptoken value, the client can use this token in a subsequent request to retrieve the next set of results. The $skiptoken value serves as an identifier of the last result returned by the server and helps the server to skip to the next set of results efficiently.

For example, suppose we want to retrieve the first 100 orders from an “Orders” entity set that contains 500 orders. We can use the following query:

/sap/opu/odata/sap/<service_name>/Orders?$top=100

This query would retrieve the first 100 orders. However, if we want to retrieve the next 100 orders, we would need to use $skiptoken. When the server returns the first 100 orders, it would also return a $skiptoken value that identifies the last order returned. We can then use this $skiptoken value in a subsequent request to retrieve the next 100 orders:

/sap/opu/odata/sap/<service_name>/Orders?$top=100&$skiptoken=<skiptoken_value>

In this query, <skiptoken_value> is the $skiptoken value returned by the server in the previous response. The server would skip the first 100 orders and return the next 100 orders after the order is identified by the $skiptoken value.

Few interesting examples that we could use in an SAP OData technical blog about server-side paging using $skip and $skiptoken:

  1. Retrieving large amounts of data efficiently: Imagine we have an entity set containing a large number of records, such as a sales order entity set that contains thousands of orders. Instead of retrieving all the orders in a single request, we can use $skip and $skiptoken to retrieve them in smaller, more manageable batches. This can significantly improve performance and reduce the load on the server.
  2. Implementing infinite scrolling: With server-side paging, we can implement infinite scrolling, where data is loaded dynamically as the user scrolls down a page. This can provide a better user experience and prevent the need to load all the data at once, which can be slow and resource-intensive.
  3. Combining $skip and $filter to retrieve specific data: We can combine $skip and $filter to retrieve specific data from an entity set. For example, if we have an employee entity set and we want to retrieve all the employees in the sales department after skipping the first 10 employees, we can use the following query:
    /sap/opu/odata/sap/<service_name>/Employees?$skip=10&$filter=Department eq 'Sales'
  4. Using $skiptoken with SAP Gateway: SAP Gateway provides built-in support for $skiptoken, allowing us to easily implement server-side paging in our OData services. We can use the go_paging method in our Gateway class to handle $skiptoken values and efficiently retrieve large amounts of data.

Conclusion:

In conclusion, understanding the difference between $skip and $skiptoken in SAP OData is crucial when working with large datasets. By using these parameters effectively, developers can improve the performance and scalability of their OData services and provide a better user experience for their customers. By following best practices and optimizing their queries, developers can ensure that their OData services are performing at their best and delivering value to their users.

If you found this post helpful, please like and share it with your network 🙂

 

Kind Regards,

Nitin Sharma

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Ralf Handl
      Ralf Handl

      The blog says

      In SAP OData, both $skip and $skiptoken are used for server-side paging

      Actually only $skiptoken is used in server-side paging, and $skip is used for client-controlled paging.

      Client-controlled paging to request the third "page" of length 10:

      Server-driven paging

      This request will return the server-side limit of 20 data objects per "page", plus a __next link which the client can use to retrieve the next server-controlled page, plus optionally another __next link.

      The client can follow __next links as long as they appear, resulting in "bottom-less scrolling".

      See OData Protocol section 11.2.6.7 Server-Driven Paging for the (somewhat brief) definition.

      Author's profile photo Nitin Sharma
      Nitin Sharma
      Blog Post Author

      Hello Ralf,

      Thanks for correcting the blog.

      Regards,
      Nitin Sharma