2

Batch Load Data into a Custom Business Object in S... - SAP Community

 7 months ago
source link: https://community.sap.com/t5/enterprise-resource-planning-blogs-by-sap/batch-load-data-into-a-custom-business-object-in-sap-s-4hana-cloud/ba-p/13359205
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

MartyMcCormick

Product and Topic Expert

‎07-20-2018 8:35 PM

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.
screen1-1.png
Here are the fictional fields in the CBO.
screen1a-2.png
After creating the CBO, you assign it to a Custom Communication Scenario.
screen3-1.png
Create a Communication Arrangement based on the Custom Communication Scenario where you will find the URL to your CBO.
screen4-1.png
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:
metadata.png
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.
fetch.png
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.
headers.png
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.
post.png
In the response, you should see HTTP/1.1 201 Created if the creation was successful, otherwise you will see the error message.
response.png
The records are now created in the CBO!
data.png
That's all for now, I hope you found this blog helpful!

Thanks,
Marty

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK