You might be very familiar with consuming OData service by using REST receiver adapter. However SAP has provided a native OData adapter to consume OData service as well.
In the content below, you will learn some knowledge on how to update information in backend by using OData adapter under the $batch mode.
There are some blogs post on using SAP PI OData adapter to make complex query to backend. Whereas in this blog post, I will describe how $batch has been used in OData adapter configuration under POST operation. here are the steps.
- Create a OData service as below from table SFLIGHT
remember to redefine these methods so that it can support $batch
In the above blogs, the author has described a way to get schema, resource path etc. by using
Model Operation for query.
I will describe the detail steps on this.
Then create the ESR contents based on the xsd generated.
However, I found the Model Operation in NWDS has a defect dealing with an entity type having deep structure which prevents xsd from being generated.
I will write the way dealing with deep structure using $batch in another blog.
2. Configuration OData Receiver Channel
The entity set of the OData created in the backend by me is
SflightSet
Note: this additional setting is to avoid an ‘utf-8’ string generated to the Accept in the request message, which cannot be accepted by SAP gateway service
3. Unit Test
Check entries in Table SFLIGHT
The values in field PRICE are 16 and 18.82 here
Make change to price field in the request message and send it.
Response message received by POSTMAN
Entries updated after the batch POST
4. Analysis
goto tx code /IWFND/TRACES, select the communication user, we can find that when OData Adapter makes one call to backend by using POST, the odata service has been called 4 times in the backend.
The GET operation is to retrieve CSRF Token.
Therefore, one of the benefit to use OData Adapter to create/change data is that you do not need to switch off csrf token as for REST adapter.
Hopefully you will find the blog is useful.
Reference
https://blogs.sap.com/2017/01/10/consuming-gateway-odata-service-with-odata-adapter/
https://blogs.sap.com/2017/03/13/diving-deeper-into-the-odata-adapter/