Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
cancel
Showing results for 
Search instead for 
Did you mean: 
MartyMcCormick
Product and Topic Expert
Product and Topic Expert
4,669

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.




When viewing the metadata, we see the upsert node:



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.



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



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




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



Sample payload:



Call from Postman with the record shown in the response:




Thanks,
Marty









2 Comments