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.

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x