Skip to Content

Note: This is the first blog in a two part series.  The second blog builds upon this blog using the batch concept upload directly from a Microsoft Excel spreadsheet.

There may be some cases where you need to perform a one time load of data into a custom business object (CBO) in SAP S/4HANA Cloud.  As outlined in the documentation, a CBO supports batch loading but an example is not provided.  In this blog, we’ll use the Postman tool to batch load a data set into a CBO.

The first step is to create the custom business object.  The documentation is linked above and here is the CBO that we’ll work with in this scenario.  Be sure to check “Service Generation” so the CBO can be called via OData.

Here are the fictional fields in the CBO.

 

After creating the CBO, you assign it to a Custom Communication Scenario.

Create a Communication Arrangement based on the Custom Communication Scenario where you will find the URL to your CBO.

Now that we have exposed the CBO as an OData service, we can call it from a testing tool such as Postman.

First, we can look at the metadata of the service:

Now we are ready to begin our batch update.

If a service supports a batch update, you append $batch to the OData service URL.  For example,

https://my<host>-api.s4hana.ondemand.com/sap/opu/odata/sap/YY1_CBO_DEMO_CDS/$batch

The first step is to fetch the x-csrf-token for cross site scripting.

After we have the token, we need to set our HTTP Headers.  In addition to the x-csrf-token, we need to set the header “Content-Type” to the value: “multipart/mixed; boundary=batch_mybatch”

The boundary attribute value is configurable based on the payload that you are going to send.

 

Batch processing for OData requires a very specific format, including line spacing.

For working with batchsets, refer to SAP Note 1869434

--batch_mybatch
Content-Type: multipart/mixed; boundary=changeset_mychangeset1

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

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

{
"Field1": "key20", 
"Field2": "value2",
"Field3": "value3"
}


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

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

{
"Field1": "key21",
"Field2": "text2",
"Field3": "text3"
}


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

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

{
"Field1": "key22", 
"Field2": "sample2"
"Field3": "sample3"
}



--changeset_mychangeset1--


--batch_mybatch--

We put the batchset into the Body with raw Type and POST the data to the S/4HANA Cloud system.

In the response, you should see HTTP/1.1 201 Created if the creation was successful, otherwise you will see the error message.

The records are now created in the CBO!

That’s all for now, I hope you found this blog helpful!

Thanks,
Marty

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply