Skip to Content
Technical Articles
Author's profile photo Deepak G Deshpande

SAP Cloud Integration – OData Service in $batch Mode

Introduction

SAP Cloud Integration provides support to create and host/provision your OData services via the creation of OData Service artifacts. You can find more information about OData Service creation in the documentation https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/d961654cd36b46ad83b668e4434c9f04.html.

This blog explanations on how to invoke the provisioned service in $batch mode and excludes the details on how to create an OData Service.

OData Service

There is no extra configuration or implementation required in OData Service projects to enable $batch mode invocation. As of now the $batch works with below scope/restriction

  1. Only one operation is support per changeset
  2. The Message Processing Log (MPL) per changeset is generated

An OData Service as shown in the below example will be used for the explanation. This OData Service is internally designed to invoke another OData service.

Below is the integration flow generated for Query operation of ProuctSet of OData Service. The integration flow editor opens upon clicking on icon under the Action column against the operation.

 

Upon successful deployment of this OData Service, the endpoint is generated and hosted. The hosted endpoint information is available under the Monitoring -> Overview -> Manage Integration Content as shown in below screenshot. Copy and use this endpoint where it is needed to be invoked.

 

Invoking OData Service

In this example, let’s invoke this OData service in a REST client application, POSTMAN. You need to append /$batch at the end of OData Service URL, e.g. in our case it will be https://<tenant-host>/gw/odata/SAP/ODATA_SERVICE_BATCH_DEMO;v=1/$batch. You need to first fetch the csrf token and use it in the HTPP POST request.

Below is the POST request payload content

--batch_123
Content-Type: application/http
Content-Transfer-Encoding: binary

GET ProductSet(3) HTTP/1.1


--batch_123
Content-Type: multipart/mixed; boundary=changeset_1

--changeset_1
Content-Type: application/http
Content-Transfer-Encoding: binary

POST ProductSet HTTP/1.1
Content-Type: application/json

{
 "ID": 55,
 "Name": "Example55",
 "Rating": 9,
 "Price": "9.9",
 "ReleaseDate": "2008-05-08T00:00:00"
}

--changeset_1--
--batch_123--

Below is the sample screenshot of POSTMAN client

Headers section

Body section

Response body section

 

Example response body contents are as below.

--batch_416e1927-4e84-4ef7-b81f-df9349fe1323
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 200 OK
Location: https://pmt2pw5-iflmap.hcisb.int.sap.hana.ondemand.com:443/gw/odata/SAP/ODATA_SERVICE_BATCH_DEMO;v=1/ProductSet(3)
Content-Type: application/atom+xml;charset=utf-8;type=entry
Cache-Control: no-store, no-cache
Content-Length: 1027

<?xml version="1.0" encoding="utf-8"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="https://pmt2pw5-iflmap.hcisb.int.sap.hana.ondemand.com:443/gw/odata/SAP/ODATA_SERVICE_BATCH_DEMO;v=1/"><id>https://pmt2pw5-iflmap.hcisb.int.sap.hana.ondemand.com:443/gw/odata/SAP/ODATA_SERVICE_BATCH_DEMO;v=1/ProductSet(3)</id><title type="text">ProductSet</title><updated>2018-11-21T05:54:38.35Z</updated><category term="S1.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"></category><link href="ProductSet(3)" rel="edit" title="Product"></link><content type="application/xml"><m:properties><d:ID>3</d:ID><d:Name m:null="true"></d:Name><d:Description m:null="true"></d:Description><d:ReleaseDate>2005-10-01T00:00:00</d:ReleaseDate><d:DiscontinuedDate>2006-10-01T00:00:00</d:DiscontinuedDate><d:Rating>3</d:Rating><d:Price>19.9</d:Price></m:properties></content></entry>
--batch_416e1927-4e84-4ef7-b81f-df9349fe1323
Content-Type: multipart/mixed; boundary=changeset_591ce50b-9727-46bf-8881-0fd7cac16dd3

--changeset_591ce50b-9727-46bf-8881-0fd7cac16dd3
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 201 Created
Location: https://pmt2pw5-iflmap.hcisb.int.sap.hana.ondemand.com:443/gw/odata/SAP/ODATA_SERVICE_BATCH_DEMO;v=1/ProductSet(55)
Content-Type: application/atom+xml;charset=utf-8;type=entry
Content-Length: 997

<?xml version="1.0" encoding="utf-8"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="https://pmt2pw5-iflmap.hcisb.int.sap.hana.ondemand.com:443/gw/odata/SAP/ODATA_SERVICE_BATCH_DEMO;v=1/"><id>https://pmt2pw5-iflmap.hcisb.int.sap.hana.ondemand.com:443/gw/odata/SAP/ODATA_SERVICE_BATCH_DEMO;v=1/ProductSet(55)</id><title type="text">ProductSet</title><updated>2018-11-21T05:54:38.351Z</updated><category term="S1.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"></category><link href="ProductSet(55)" rel="edit" title="Product"></link><content type="application/xml"><m:properties><d:ID>55</d:ID><d:Name></d:Name><d:Description></d:Description><d:ReleaseDate>2008-05-08T00:00:00</d:ReleaseDate><d:DiscontinuedDate m:null="true"></d:DiscontinuedDate><d:Rating>9</d:Rating><d:Price>9.9</d:Price></m:properties></content></entry>
--changeset_591ce50b-9727-46bf-8881-0fd7cac16dd3--
--batch_416e1927-4e84-4ef7-b81f-df9349fe1323--

 

Message Processing Log

As mentioned in the above section on scope/restrictions, an MPL per changeset is created. In the example above, we are using two changeset requests, one for GET and other for POST, hence there will be two MPLs generated for the sample scenario.

 

Summary

The invocation of SAP Cloud Integration OData Service can be done in $batch mode with mentioned scope/restrictions.

 

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Robin Vezina
      Robin Vezina

      Does the statement “Only one operation is support per changeset” means :
      1. Only 1 ChangeSetPart is allowed per ChangeSet ?
      2. Many ChangeSetParts can be used in one ChangeSet as long as it use the same operation (i.e. all POST) ?

      How can an IFlow be configured to sent an OData $batch outbound containing all entities received with an OData $batch inbound ? The communication needs to be synchronous to return the proper http code.

      Author's profile photo Deepak G Deshpande
      Deepak G Deshpande
      Blog Post Author

      Hi Robin,

      Closing this loop as we discussed these questions over the call.

      Thanks for the feedback.

       

      Thanks

      Deepak

      Author's profile photo Andrej Gardon
      Andrej Gardon

      Hi,

      could you please provide explanation to:

      ...

      How can an IFlow be configured to sent an OData $batch outbound containing all entities received with an OData $batch inbound ? The communication needs to be synchronous to return the proper http code.

      ...

      I also wonder how this can be achieved. We send let us say 100 update request via batch and then it is processed one by one for destination Odata. I see the option to turn on batching on destination odata but how can we merge all request?

      Thank you

      Author's profile photo Ashokkumar Duraisamy
      Ashokkumar Duraisamy

      Hello Depak,

      The above information is very useful. I have a query in this.

      I am connecting to Successfactors OData adapter with $batch for deletion of $links. But my response payload is not accepted by CPI and throws following exception.

      com.sap.gateway.core.ip.component.odata.exception.OsciException: while trying to invoke the method org.apache.olingo.odata2.api.edm.EdmEntitySet.getName() of a null object loaded from local variable 'entitySet', cause: java.lang.NullPointerException: while trying to invoke the method org.apache.olingo.odata2.api.edm.EdmEntitySet.getName() of a null object loaded from local variable 'entitySet'

      My batch request:

      --batch Content-Type: multipart/mixed; boundary=changeset_9770de8c-b8e4-44f8-9fd8-0ae9d4a2dde6 --changeset_9770de8c-b8e4-44f8-9fd8-0ae9d4a2dde6 Content-Type: application/http Content-Transfer-Encoding: binary DELETE User('11534748')/$links/matrixManager HTTP/1.1 Accept: application/atom+xml --changeset_9770de8c-b8e4-44f8-9fd8-0ae9d4a2dde6 Content-Type: application/http Content-Transfer-Encoding: binary DELETE User('11534795')/$links/matrixManager HTTP/1.1 Accept: application/atom+xml --changeset_9770de8c-b8e4-44f8-9fd8-0ae9d4a2dde6-- --batch--

      My batch response:

      --batch_77e19246-9934-4971-afd0-1882ceda0263 Content-Type: multipart/mixed; boundary=changeset_822a9dea-cfdb-41c9-9adc-01720af76f2b --changeset_822a9dea-cfdb-41c9-9adc-01720af76f2b Content-Type: application/http Content-Transfer-Encoding: binary HTTP/1.1 204 No Content DataServiceVersion: 1.0 Content-Length: 0 --changeset_822a9dea-cfdb-41c9-9adc-01720af76f2b Content-Type: application/http Content-Transfer-Encoding: binary HTTP/1.1 204 No Content DataServiceVersion: 1.0 Content-Length: 0 --changeset_822a9dea-cfdb-41c9-9adc-01720af76f2b--

       

      Author's profile photo Deepak G Deshpande
      Deepak G Deshpande
      Blog Post Author

      Hi Ashokkumar,

      I missed your comment/issue description to respond. Is the issue resolved?

       

      Thanks

      Deepak