Skip to Content
Product Information
Author's profile photo Marty McCormick

UPSERT a Custom Business Object (CBO)

If you’ve worked with SAP Custom Business Objects (CBOs) via an OData API previously, then you are probably aware that you need to differentiate between a POST (new record) and a PUT (update a record).

This is an important topic because when you have an integration that handles records of both new and update, you need to first query the CBO to check for the existence of a record and retrieve the unique key (SAP_UUID) and if it exists, issue a PUT otherwise a POST HTTP command to create a new record. If you were using SAP Cloud Platform Integration (CPI), you would need to call the CBO first and either use a content enricher pattern (blog) or just a simple call and set property via router to accomplish the CREATE/UPDATE functionality.

Recently, I was working on a project with Pascal Renet and we came across the capability to UPSERT a CBO, which was introduced in SAP S/4HANA Cloud 1905. Quick side note–if you haven’t seen Pascal’s work before, I highly recommend you subscribe to his YouTube channel. He produces outstanding snippet how-to videos.

You need to watch Pascal’s video on the UPSERT functionality before proceeding with this blog. He goes over how the UPSERT functionality works including how to test via Postman. In this blog, I’ll I’ll address how to UPSERT a CBO via CPI.

In this blog, we’ll work with this very simple CBO of 3 fields to maintain an order, product and quantity. In order for UPSERT functionality to be added to your OData service, you need to enable a key field on the CBO.

image1.png

When viewing the metadata, we see the upsert node:

image2.png

Now, it’s time to model the iFlow. In this iFlow, we’ll accept an HTTPS payload and use a splitter/gather to update the CBO. As outlined in the documentation, an upsert is a single function and should not be used in an OData batch call. Furthermore, you need to pass all fields of the record back into the call–so if you are only updating one field you will need to revert to the previously aforementioned method of fetching SAP_UUID and updating.

SampleiFlow.png

The adapter is configured very similar to any other OData service:

image3.png

With the exception that now there is a Function Import available for you to use for the UPSERT.

image4.png

Then you need to pass all fields, which I set as properties in my sample iFlow before getting to this step:

image6.png

Sample payload:

image7.png

Call from Postman with the record shown in the response:

image99.PNG

Thanks,
Marty

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Sandeep Kumar
      Sandeep Kumar

      nice feature and thanks for sharing!

      Author's profile photo Amith Nair
      Amith Nair

      Very Helpful and Thank you for putting this together with a demonstration!