Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
nabsrisubhasourya
Discoverer
3,541

When we faced Delta Token Unavailable Exception for multiple Projects across the Globe, we didn't find a direct solution and have reach out to SAP specialists for solution. We are writing this Blog to make the solution available for everyone by following these simple steps.

What is a Delta Token? 

To enhance API performance, SAP introduced the concept of a Delta Token to optimize data retrieval and reduce unnecessary processing. 

 

Problem Statement 

Consider an API that returns a list of tasks, where the response size is around 10,000 records. Traditionally, the app fetches this entire dataset daily when the user opens the app. However, on any given day, only 10 to 15 new records might be added. Despite this, the API still retrieves the entire dataset, leading to performance issues due to the large response size and increased processing time. 

 

SAP’s Delta Token Solution 

SAP addresses this inefficiency with the Delta Token mechanism. 

  • First API Request (Fresh Request): 
  • When an API request is made for the first time, the GET_ENTITYSET method in OData is executed. 
  • SAP captures the timestamp of this request and generates a Delta Token, which is stored in an SAP table (DELTA_TABLE). 
  • The API response includes both the task list and the Delta Token. 
  • Storage on the Mobile Device: 
  • The SAP SDK creates offline tables on the mobile device to store the received records. 
  • The Delta Token is also saved in Shared Preferences, mapped to the respective entity. 
  • Subsequent API Requests (Delta Requests): 
  • When the user reopens the app the next day, the SAP SDK sends the previously stored Delta Token as a filter in the API request. 
  • The OData service executes the GET_ENTITYSET_DELTA method, triggered due to the presence of the Delta Token in the request. 
  • SAP decodes the Delta Token, checks the timestamp, and retrieves only the newly created, updated, or deleted records since the last request. 
  • A new Delta Token is generated, updated in the SAP table, and returned in the response along with the modified task list. 
  • Efficient Data Synchronization: 
  • The mobile SDK receives only incremental changes (fewer records), reducing response time. 
  • The local database is updated with the new data and the updated Delta Token. 

/IWBEP/CX_QRL_DELTA_UNAVAILABL Exception 

Below is a screenshot of the UserDetailSet entity's fresh request, where the response includes a Delta Token 

Image11.png

After a day, when the mobile device attempts to make a delta request using the previously generated Delta Token, the response returns an exception: /IWBEP/CX_QRL_DELTA_UNAVAILABLE. 

Image 22.pngImage33.png

What is a Delta Token Unavailable Exception? 

As mentioned earlier, every Delta Token generated by SAP OData is stored in the DELTA_TABLE. However, a scheduled process runs at predefined intervals to clear old records from this table. If a request is made after the Delta Token has been purged, the system will be unable to find it, resulting in a Delta Token Unavailable Exception. 

 

Understanding the Exception with an Example 

  • Delta Token Storage & Cleanup 
  • When a fresh request is made, SAP generates a Delta Token and stores it in the DELTA_TABLE. 
  • A scheduler is configured to periodically clear old records from the table. 
  • For instance, if the scheduler is set to run every 3 days, any Delta Tokens older than this timeframe will be removed. 
  • Successful Delta Request 
  • If a user logs in within the scheduler timeframe (e.g., the next day), the mobile app sends the previously stored Delta Token. 
  • SAP looks up the DELTA_TABLE, finds the token, decodes it, and returns only the updated records. 
  • Delta Token Unavailable Scenario 
  • Suppose a user logs in after one week. 
  • The app still sends the last stored Delta Token, but since the scheduler ran 4 days ago, the Delta Token has been purged from the table. 
  • As a result, SAP fails to find the token and throws a DELTA_UNAVAILABLE exception. 

Solution 

SAP recommends handling the Delta Token Unavailable Exception by capturing it in the OData service and returning a 410 (Gone) status code. This status code indicates that the Delta Token is no longer available. 

When Mobile Services receive a 410 response, it recognizes that the Delta Token is missing and automatically triggers a fresh request for the same entity. This fresh request retrieves the entire dataset along with a new Delta Token, ensuring that data synchronisation continues smoothly. 

 

 

Code snippet OData 

 
Write the Custom Exception Message with Status code as 410 whenever the delta token unavailable exception /iwbep/cx_qrl_delta_unavailabl is raised. 

 Image44.png

 

 

How to check/change delta token schedular 

 

Monitor the standard jobname /IWBEP/QUERY_RESULT_LOG_CLEANUP  which uses the standard program -  /IWBEP/R_CLEAN_UP_QRL scheduled based on required days to clear the delta token from the system saved as variant. 

Note: The standard job can be updated with required scheduled cycle from tcode - SM36 

Image55.pngImage66.pngImage77.png

 

 

 

 

 and on execution the cache memory of delta query will be removed.

 

Image88.png

 

 
 
 

 

Conclusion 

If you have any questions related to the same, feel free to post a question here 

Please make sure to follow my profile to know more about my upcoming blog where I will write on how to design a complex MDK application with multiple screens and API. 

If you have any further queries, feel free to comment. 

 

Authors 

nabsrisubhasourya_0-1746883183871.png

Name      :   
About     :  

Nabsri Subha Sourya 
Architect (Mobility, SAP BTP) 

nabsrisubhasourya_1-1746883183872.png

Name      :  
About     :  

Jagadisha N 
Lead Engineer (SAP MDK, Android) 

nabsrisubhasourya_2-1746883183873.png 

Name      :  
About     :  

Navarathana Kumar
Sr Engineer (ABAP)