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: 
PrasanthM
Product and Topic Expert
Product and Topic Expert
Introduction

You would have already seen how data can be replicated from SAP S/4HANA to SAP S/4HANA Cloud via DRF replication and via iDocs in a Two-Tier ERP setup. You can refer these in the blog Master Data and Integration in Two-Tier ERP. In this blog, I will walk you through a scenario where  a document is replicated from SAP S/4HANA to SAP S/4HANA Cloud using SAP BTP Event Mesh. I will be replicating a business partner in this scenario.

Step 1: Setup SAP BTP Event Mesh

The first step to replicate documents via SAP BTP Event Mesh is to setup SAP BTP Event Mesh in BTP.

You can start this by subscribing to the SAP BTP Event Mesh service in BTP.

Detailed steps on how to configure SAP BTP Event Mesh, is provided in the blog, Data Events scenario With SAP Event Enablement Add-on for SAP S/4HANA, SAP Event Mesh and SAP Cloud ...  by fiona_zhang

As per the blog, you should subscribe to the plans ’standard’ and ‘default’ of the SAP BTP Event Mesh service, to access the application and the instance of the SAP BTP Event Mesh service.

I have maintained the JSON for subscribing to the SAP BTP Event Mesh instance as shown below
{
"emname": "andina2tier",
"namespace": "pscc/andina/2tier",
"options": {
"management": true,
"messaging": true,
"messagingrest": true
},
"rules": {
"queueRules": {
"publishFilter": [
"${namespace}/*"
],
"subscribeFilter": [
"${namespace}/*"
]
},
"topicRules": {
"publishFilter": [
"${namespace}/*"
],
"subscribeFilter": [
"${namespace}/*"
]
}
},
"version": "1.1.0",
"xs-security": {
"oauth2-configuration": {
"credential-types": [
"binding-secret",
"x509"
]
}
}
}

 

Create a queue under the message client under the namespace specified in the JSON which was created in the previous step as shown below


Click on edit queue and add a queue subscription to the queue that was created in the previous step



 

With this, the SAP BTP Event Mesh setup is complete.

Step 2: Connect SAP S/4HANA system to SAP BTP Event Mesh

Inorder for the SAP S/4HANA system to send data to SAP BTP Event Mesh, connectivity has to be established. A channel has to be created in the transaction /IWXBE/CONFIG in SAP S/4HANA. All steps on how to achieve this is explained thoroughly in the blog Configure SAP Enterprise Messaging for SAP S/4HANA via Service Key by ejaz123 .

The topic space will be automatically fetched into the channel once you paste and save the service key as explained in the blog.

You will see the following in the transaction /IWXBE/CONFIG, after this setup is complete


The next step is to create an outbound binding

Select the channel you created in the previous step and choose outbound bindings


Since we are replicating a business partner, create an outbound binding for the business event for business partner as shown below, by choosing the create button


With this, the setup in the SAP S/4HANA system is complete.

Step 3: Create communication arrangement in SAP S/4HANA Cloud

In this step, create a communication system and communication arrangement to connect to the communication scenario SAP_COM_008

You can follow the steps 1-4 from the blog https://blogs.sap.com/2020/12/14/setting-up-an-import-connection-setup-between-sap-s-4hana-cloud-and... which explains how to create a Communication Arrangement and a Communication System in SAP S/4HANA Cloud

Step 4: Binding it all together via SAP Cloud Integration

If you have reached this stage, I believe you have already gone thru fiona_zhang's  blog, where she have explained, how to create an AMQP adapter, which will listen to events triggered from SAP BTP Event Mesh.

A simple integration flow is implemented as shown below to bind all of this together. This iflow will capture the event triggered from the SAP S/4HANA system when a business partner is created via the AMQP adapter, fetch the details of the created business partner from the SAP S/4HANA system and then pass this as a payload to replicate this business partner to SAP S/4HANA Cloud


Now let us look at how each element in the integration flow is maintained.

For the AMQP connection, get the path from the service instance of the SAP BTP Event Mesh, which is created in step 1.


Copy the uri from the service instance and maintain it under the AMQP connection in the integration flow as shown below


The credential for the AMQP connection will be the client id and client secret from the service key that is created in step 1. The credential name should be maintained and available under security materials in Cloud integration

The AMQP message from the SAP S/4HANA system will be received as a JSON string. Convert this to XML by adding a JSON to XML convertor.

Create a content modifier to read the Business partner Id from the AMQP message which is converted to XML as follows
Create    BusinessPartner    XPath    //BusinessPartner    java.lang.String


I have added the following groovy script to log the messages throughout the integration flow. You can ignore this if logging is not required, but I would recommend to add this.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
def body = message.getBody (java.lang.String) as String;
def messageLog = messageLogFactory.getMessageLog(message);
if (messageLog != null){
messageLog.setStringProperty("Logging#1", "Printing Payload As Attachment")
messageLog.addAttachmentAsString("Payload:", body, "text/plain");
}
return message;
}

The next step is to create an oData call to the SAP S/4HANA system to fetch the details of the business partner. This is required because the event that will be triggered upon the creation of the business partner will contain minimal information related to the business partner. In-order to get the complete details of the business partner, we perform this oData get call to the SAP S/4HANA system.

Since the call is done to an SAP S/4HANA system, make sure that the cloud connector setup is done and a virtual host is created for the connection from Cloud to On-Premise. You can follow the steps given here for setting up cloud connector.

The oData connection to the S/4HANA OP system should look like the following. The credential name should be maintained and available under security materials in Cloud integration.



Configure the following in the resource path, to filter the GET call by business partner



"BusinessPartner Equal ${property.BusinessPartner}"

Make sure that you maintain the client of the SAP S/4HANA system under 'Custom Query Options' if your system is client specific.

Create a message mapping to map the output of the oData that is received from the SAP S/4HANA system.


After the mapping is complete, create an oData call to the SAP S/4HANA Cloud system to create the business partner in the SAP S/4HANA Cloud system via the API that is created in Step 3.

The oData connection to the SAP S/4HANA Cloud system should look like the following.




Deploy the iflow and create a Business Partner from the SAP S/4HANA system to replicate the Business Partner to SAP S/4HANA Cloud. This can be monitored via  ‘Monitor Message Processing’ in Cloud Integration as shown below


 

Conclusion

By following the steps provided in this blog, you can replicate a business partner from SAP S/4HANA to SAP S/4HANA Cloud in a Two-Tier ERP setup. These steps can be followed to replicate any document from SAP S/4HANA to SAP S/4HANA Cloud, based on the outbound bindings created in Step 2.

4 Comments