Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
shalabh_jain
Employee
Employee

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.
11 Comments
rcaziraghi
Participant
Hello,

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

Thank you!
shalabh_jain
Employee
Employee
0 Kudos
Thanks Rafael, for sharing your feedback and experience!
former_member230443
Participant
Hi Shalabh,

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

Thanks again,

Vimal
shalabh_jain
Employee
Employee
0 Kudos
Thanks Vimal, Glad that I could help. All the best!
VipulKhullar
Product and Topic Expert
Product and Topic Expert
Very well explained Shalabh!

 
shalabh_jain
Employee
Employee
0 Kudos
Thanks Vipul!
talwinder_singh2
Discoverer
Interesting read. The step by step approach of implementation makes it very clear. Thank you @Shalabh for this blog.
shalabh_jain
Employee
Employee
0 Kudos
Thanks Talwinder!
I'm trying to implement, but the service still wait to finish the processing. Is there any coding necessary in the classes on SEGW?
shalabh_jain
Employee
Employee
0 Kudos
Hi Bruno,

The service will keep running on the server side. However, the consumer will not have to wait for a response and can read the response after some time by polling the server.

No specific implementation is required for this feature and it is completely handled by the framework. Please share more details of your scenario.

Thanks,

Shalabh
gregorw
Active Contributor
0 Kudos
Hi Shalabh,

can you please provide information about the minimum release that is needed for this functionality?

Best Regards
Gregor