Skip to Content
Technical Articles
Author's profile photo Shalabh Jain

Consuming ABAP RESTful Application Programming Model OData Service in Asynchronous Mode

Introduction

This blog post provides an example on consuming ABAP RESTful application programming model OData services in asynchronous mode through SAP Gateway.

Example

Step 1: HTTP POST Request to ABAP RESTful application programming model OData service in asynchronous mode

The calling platform can initiate an HTTP POST Request through an ABAP RESTful application programming model business object modifying operation (example – Create) by passing Name – ‘prefer’ with Value – ‘respond-async’ in the HTTP Request Header.

HTTP Request Header:
URI https://<ABAP RESTful application programming model OData service URI>/EntitySet
Method POST
Header Name/ Value prefer/ respond-async
HTTP Request Body:
{
 "Field 1": "Value 1",
 "Field 2": "Value 2",
          .
          .
}

 

Step 2: Read HTTP Response from ABAP RESTful application programming model OData service

The server can respond to the calling platform indicating the acceptance of processing in asynchronous mode through HTTP Response Status Code ‘202 (Accepted)’ along with an HTTP Response Header ‘location’ from where the response of the ABAP RESTful application programming model OData service can be read by the calling platform after completion of the asynchronous processing.

HTTP Response Header:
status_code 202
status_reason Accepted
location <Location>

Step 3: Poll and check status of ABAP RESTful application programming model OData service processing in asynchronous mode

The calling platform can poll the server to check the status of the ABAP RESTful application programming model OData service processing in asynchronous mode by initiating an HTTP Get Request at the HTTP Response Header ‘location’ from the previous step. The server can respond to the HTTP Request from calling platform with HTTP Response Status Code ‘202 (Accepted)’ if the processing in asynchronous mode is still ongoing. The server can additionally share a time interval through HTTP Response Header ‘retry-after’ after which the calling platform can poll the server for checking the status again.

HTTP Request Header:
URI <Location>
Method GET
HTTP Response Header:
status_code 202
status_reason Accepted
retry-after <Time>

Step 4: Read ABAP RESTful application programming model OData service response

After completion of the asynchronous processing, the calling platform can initiate an HTTP Get Request at the HTTP Response Header ‘location’ from the previous step to read the response of the ABAP RESTful application programming model OData service. The server can respond to the HTTP Request from calling platform with HTTP Response Status ‘200 (OK)’ along with HTTP Response parameter – ‘asyncresult’ indicating the status of the ABAP RESTful application programming model business object modifying operation. Example – ‘201 (Created)’.

HTTP Request Header:
URI <Location>
Method GET
HTTP Response Header:
status_code 202
status_reason Accepted
asyncresult 201

Summary

In the current blog post, a generic way of initiating an HTTP POST Request to a custom ABAP RESTful application programming model OData service is mentioned. The learning can be utilised in other similar scenarios as applicable.

For more understanding, please use the following references which have helped me in gaining knowledge on this feature and get motivated to write this blog post:

I would encourage you to read through other blog posts on such topics at: https://blogs.sap.com/tags/01200615320800003185/

You can post and answer questions on related topics at: https://answers.sap.com/tags/01200615320800003185

Please provide your feedback and ask questions in the comments section.

Assigned Tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Rafael Caziraghi
      Rafael Caziraghi

      Hello,

      Interesting blog post. Had to implement that functionality before and works just fine.

      Thank you!

      Author's profile photo Shalabh Jain
      Shalabh Jain
      Blog Post Author

      Thanks Rafael, for sharing your feedback and experience!

      Author's profile photo Vimal Mohan Jain
      Vimal Mohan Jain

      Hi Shalabh,

      Great blog post, I was looking to implement something similar. It really helps.

      Thanks again,

      Vimal

      Author's profile photo Shalabh Jain
      Shalabh Jain
      Blog Post Author

      Thanks Vimal, Glad that I could help. All the best!

      Author's profile photo Vipul Khullar
      Vipul Khullar

      Very well explained Shalabh!

       

      Author's profile photo Shalabh Jain
      Shalabh Jain
      Blog Post Author

      Thanks Vipul!

      Author's profile photo Talwinder Singh
      Talwinder Singh

      Interesting read. The step by step approach of implementation makes it very clear. Thank you @Shalabh for this blog.

      Author's profile photo Shalabh Jain
      Shalabh Jain
      Blog Post Author

      Thanks Talwinder!