Skip to Content
Technical Articles
Author's profile photo dinesh k

No upset with CBO ‘Upsert’

By now, we would have come across the CBO(Custom business object) in either Fiori app use cases or Interface use cases… This post is to provide an idea or a tip w.r.t data update using CBO Upsert technique..

Please refer to below articles if you need a kick start:

Introduction:

https://blogs.sap.com/2020/03/30/in-app-extensibility-in-s-4hana-cloud-starting-point/

Creation of CBO –

https://developers.sap.com/tutorials/abap-extensibility-cbo-create.html

Maintenance of CBO via Fiori app –

https://developers.sap.com/tutorials/abap-extensibility-cbo-ui-generation.html

Maintenance of CBO via Interface –

https://blogs.sap.com/2020/04/19/unboxing-custom-business-object-in-s-4hana-cloud/

In a nutshell, We have seen Maintenance of CBO or Creation of entries in the CBO in a Single call per entry or a mass creation using $batch call.

However, I want to touch upon the update scenario which is a little different as Patch/Put is not supported directly over the entity (albeit MERGE is technically possible).. SAP Note 2575658 describes UPSERT way to update or create using function import…

The request looks like the following:

https://<host:post>/sap/opu/odata/YY1_TESTCDS/workitemSap_upsert?workitem_cd=’WI123’&WI_status=’In+process’&SAP_Description=’WorkItem Update’

In the request above, Function import is CBO entity + Sap_upsert i.e., workitemSap_upsert followed by parameters.. This works like a charm but the only concern is that we have to update 1 entry at a time (per call)

Therefore, Taking this learning a step further we can enhance it to “Create or Update CBO entries in mass” using $batch operation-…

URL:

https://host/sap/opu/odata/YY1_TESTCDS/$batch

Request Body:

******************

–batch
Content-Type: multipart/mixed; boundary=changeset

–changeset
Content-Type: application/http
Content-Transfer-Encoding: binary

POST workitemSap_upsert?workitem_cd=’WI123’&WI_status=’In+process’&SAP_Description=’WorkItem+Create’ HTTP/1.1

–changeset
Content-Type: application/http
Content-Transfer-Encoding: binary

POST workitemSap_upsert?workitem_cd=’WI123’&WI_status=’Complete’&SAP_Description=’WorkItem+Update’ HTTP/1.1

–changeset–

–batch–

*******************************

In the above request ‘WI123’ is created if it doesn’t already exist and updated if it exists…

However, Pls note the below points before going ahead with this $batch option

  1. There cannot be a blank space in the URI. We have to add a +(plus) if we need a space in the text for ex: SAP_Description=’WorkItem+Update’ would be updated in table as ‘WorkItem Update’
  2. If any error occurs in the POST the complete call fails…So partial create/update will not happen – which is good in terms of troubleshooting
  3. Usual $batch limit applies for no. of entries that can be posted (we have observed around 180  entries per call but it varies with the size of the payload)

That is all for this article…will update further if we come across something worth sharing…

Please leave your comments or opinions if you want me to add/update anything..

Thanks..

Assigned tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.