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


<<Japanese version is here>>

1. Introduction





This blog is the fourth in a blog series on "How to extend SAP S/4HANA with SAP Cloud Platform" and I will explain about S/4HANA Event Enablement here.  With this Event Enablement feature, we can trigger an external logic only when an event occurred in SAP S/4HANA. This event here means  Business Object "Create", "Change" or "Delete".

  1. Overview of extended development on SAP Cloud Platform

  2. How to find SAP S/4HANA API

  3. How to use SAP S/4HANA API

  4. If API does not exist (will come later)

  5. Event integration with SAP S/4HANA <<<<HERE


Generally, for the custom development of SAP S/4HANA, it is recommended to follow the  "Keep the Core Clean" principle. In other words, we need to have a clear distinction between the SAP standard application and custom development objects. The extension inside of S/4HANA (In-App Extensibility) will be limited to an extension with a specific tool like a "Key User Tool". And we will put the custom development objects outside of SAP S/4HANA and that is called Side-by-Side extension.






It might be easy to imagine how it works when you develop something (e.g. user interfaces or business logics ) on SAP Cloud Platform and accessing to SAP S/4HANA API. As introduced in Susumu's previous blog, you can get or create data with OData API in SAP S/4HANA. It is also possible to use SAP Cloud SDK which is a wrapper library of OData API there.

 Accessing to SAP S/4HANA API from SAP Cloud Platform


On the other hand, what if we want to trigger some action externally when an object of SAP S/4HANA is created or changed? It is still technically possible to check the object creations or changes by polling API calls at regular intervals, but the real-time integration may not be achievable with that.
Event-based integration comes up here.


An event in SAP S/4HANA will trigger an external logic in SAP Cloud Platform to be executed

By using this method, it is possible to start an external logic or start data/process integration when the SAP S/4HANA object is created.


In past, you would have updated the data with EXIT or BADI of SAP S/4HANA. You may be able to achieve the similar thing with the event-driven fashion with this.


 

SAP S/4HANA and SAP Cloud Platform Enterprise Messaging According to the Event Driven Architecture


Let's take a closer look.
The architecture may look like this.



Events that occur in S/4HANA are sent to SAP Cloud Platform Enterprise Messaging.
It is also possible to broadcast from Enterprise Messaging to multiple runtimes.

In the diagram above, three types of systems (SAP Cloud Platform Integration, Extension Factory Serverless Runtime and web application) receive data from Enterprise Messaging, but you can freely decide which system receives it.

I will briefly introduce each component.

1.SAP S/4HANA Enterprise Event Enablement feature


 

 

 

 

 

 

 

With the feature of Enterprise Event Enablement of S/4HANA, you can pass the S/4HANA event to the external systems via the middleware called SAP Cloud Platform Enterprise Messaging. The  supported communication protocol between SAP S/4HANA and SAP Cloud Platform Enterprise Messaging will be MQTT (over Websocket).

https://help.sap.com/viewer/810dfd34f2cc4f39aa8d946b5204fd9c/1909.002/en-US/c200f98fadb64ff1828ed569...

2.SAP Cloud Platform Enterprise Messaging


SAP Cloud Platform Enterprise Messaging is a middleware service for asynchronous messaging. By placing Enterprise Messaging in between, it is possible to realize asynchronous messaging that separates the sending process and the receiving process, and to level the message processing load.

https://discovery-center.cloud.sap/serviceCatalog/enterprise-messaging

3.SAP Cloud Platform Extension Factory, Serverless Runtime


 

 

 

 

 

 

SAP Cloud Platform Extension Factory, Serverless Runtime is a runtime for building a serverless environment in SAP Cloud Platform. Just like an ordinary serverless environment like AWS Lambda, it is possible to execute logic in an event-driven manner and you don't need to care about server resources or sever management.

https://discovery-center.cloud.sap/serviceCatalog/extension-factory-serverless-runtime

4.SAP Cloud Platform Integration


 

 

 

 

 

 

SAP Cloud Platform Integration is a middleware service for the Process Integration (iPaaS) on SAP Cloud Platform. Currently, multiple Integration services (Cloud Platform Integration, API Management, Open Connector) have been integrated and are now offered as an Integration Suite.  SAP Cloud Platform Integration is the core component of it.

https://discovery-center.cloud.sap/serviceCatalog/integration-suite

 

Another important point for the we don't pass the entire data of the business object for the event messaging.The payload of the event only includes the type of business object (Purchase order, Sales Order etc.), key information, and action( creation, change, or deletion).

Here is an example of the palyload.
We can know this is en event of Outbound Delivery Change and the document number is "00800005".
{"eventType":"BO.OutboundDelivery.Changed",
"cloudEventsVersion":"0.1",
"source":"https://sap.corp",
"eventID":"QgEKigAJHuqn0laStiBciA==",
"eventTime":"2020-05-25T14:19:12Z",
"schemaURL":"https://sap.corp/sap/opu/odata/IWXBE/BROWSER_SRV/",
"contentType":"application/json",
"data":{"KEY":[{"OUTBOUNDDELIVERY":"0080000005"}]}}

Enterprise Messaging will simply pass the payload data just as it is and  when you received it with SAP Cloud Platform Integration, Serveless Runtime or custom application, it is necessary to pass the kay and access the API of S/4HANA to get the detailed information.

 

.SAP S/4HANA integration with SAP Cloud Platform Enterprise Messaging


From here, I will explain about the actual configuration in Step by Step.

Most of the steps are similar to this blog. One thing we need to remember is the blog below is using “trial” version of SAP Cloud Platform and the “plan” of Enterprise Messaging is different from the productive version.

https://blogs.sap.com/2019/09/16/sap-enterprise-messaging-for-s4hana-on-premises/

For this blog, I will use the plan for the production environment.

OK, then let's start with the configuration on SAP Cloud Platform.

3.1 CLI Download and Login


In this blog, I will create the the service instance of Enterprise Messaging via CLI (Command Line interface) tool instead of the SAP Cloud Platform Cockpit Web screen.

If you have never used the Cloud Foundry CLI, I would recommend you to install it on your PC and try it out.

Click here to download Cloud Foundry CLI

https://docs.cloudfoundry.org/cf-cli/install-go-cli.html

This is the tutorial about the Cloud Foundry CLI and you will know how to login with CF CLI here.

https://developers.sap.com/tutorials/cp-cf-download-cli.html

 

3.2 Create a Service Instance


Let's create a configuration file for creating a service instance of SAP Cloud Platform Enterprise Messaging. It is a JSON format text file like below on the local PC and name it "param.json".
{
"options": {
"management": true,
"messagingrest": true,
"messaging": true
},
"rules": {
"topicRules": {
"publishFilter": [
"${namespace}/*"
],
"subscribeFilter": [
"${namespace}/*"
]
},
"queueRules": {
"publishFilter": [
"${namespace}/*"
],
"subscribeFilter": [
"${namespace}/*"
]
}
},
"version": "1.1.0",
"emname": "EM1",
"namespace": "SAPJP/EM1/S4HANA"
}

Create a service instance "em1" with the following command.
cf create-service enterprise-messaging default <service instance name> -c <option>
cf create-service enterprise-messaging default em1 -c param.json

Use the "cf service" command to check if the service was created successfully.
You can get information about the service instance with
cf service-<service instance name> .
cf service em1

name: em1
service: enterprise-messaging
tags:
plan: default
description: Connect applications, services and systems across different landscapes.
documentation: https://help.sap.com/viewer/bf82e6b26456494cbdd197057c09979f/Cloud/en-US/df532e8735eb4322b00bfc7e42f...
dashboard:
service broker: sm-enterprise-messaging-service-broker-a6a59ffd-b691-49b4-b439-d4960acc2065

Showing status of last operation from service em1...

status: create succeeded
message:
started: 2020-05-24T23:39:31Z
updated: 2020-05-24T23:40:33Z

There are no bound apps for this service.

Upgrades are not supported by this broker.

 

3.3 Create a Service Key


When you use a service from an application, you can get the access information from the environment variable of the app by binding the app to the service. But if you want to access from an external system like this S/4HANA, we need to create a service key to get the access info.

Create the service key with the following command:
You can create a service key with cf create-service-key <service instance name> <service key name> .
cf create-service-key em1 em1-key

3.4 Get the Service Key


Specify to get access information from the service key.

Information can be obtained with cf service-key <service instance name> <service key name> .
cf service-key em1 em1-key

{
"management": [
{
"oa2": {
"clientid": "<client id value>",",
"clientsecret": "<client secret value>",
"granttype": "client_credentials",
"tokenendpoint": "https://<tenant>.authentication.<region>.hana.ondemand.com/oauth/token"
},
"uri": "https://enterprise-messaging-hub-backend.cfapps.<region>.hana.ondemand.com"
}
],
"messaging": [
{
"broker": {
"type": "sapmgw"
},
"oa2": {
"clientid": "<client id value>",
"clientsecret": "<client secret value>",
"granttype": "client_credentials",
"tokenendpoint": "https://<tenant>.authentication.<region>.hana.ondemand.com/oauth/token"
},
"protocol": [
"amqp10ws"
],
"uri": "wss://enterprise-messaging-messaging-gateway.cfapps.<region>.hana.ondemand.com/protocols/amqp10ws"
},
{
"broker": {
"type": "sapmgw"
},
"oa2": {
"clientid": "<client id value>",
"clientsecret": "<client secret value>",
"granttype": "client_credentials",
"tokenendpoint": "https://<tenant>.authentication.<region>.hana.ondemand.com/oauth/token"
},
"protocol": [
"mqtt311ws"
],
"uri": "wss://enterprise-messaging-messaging-gateway.cfapps.<region>.hana.ondemand.com/protocols/mqtt311ws"
},
{
"broker": {
"type": "saprestmgw"
},
"oa2": {
"clientid": "<client id value>",,
"clientsecret": "<client secret value>",,
"granttype": "client_credentials",
"tokenendpoint": "https://<tenant>.authentication.<region>.hana.ondemand.com/oauth/token"
},
"protocol": [
"httprest"
],
"uri": "https://enterprise-messaging-pubsub.cfapps.<region>.hana.ondemand.com"
}
],
"namespace": "sap/scp/em1",
"serviceinstanceid": "7dbde612-2898-4001-a868-2f1ff8cbb03c",
"xsappname": "default-7dbde612-2898-4001-a868-2f1ff8cbb03c-clone!b57|xbem-service-broker-!b25"
}


 

In the information above, you can find three types of access information, AMQP, MQTT, and HTTP REST. In particular, MQTT is used to connect from S/4HANA, so let's take a note of the MQTT information.

  • URI

  • Client ID

  • Client Secret

  • Token Endpoint


3.5 Download Certificate File


Access Enterprise Messaging Token Endpoint from the browser and drop the certificate.




From here, let's try the SAP S/4HANA configuration.

3.6 Importing the certificate


t-code STRUST



 

 

 

 

Double click SSL client SSL Client (Standard)



 

 

Import the file downloaded in 3.3



In t-coe SMICM, restart the (ICM) server alone or restart the entire ABAP system.

 

3.7 Move to channel related settings


T-code SPRO "SAP Reference IMG"

SAP NetWeaver-> Enterprise Event Enablement->Administration->Channel Connection Settings


3.8 HTTP Destination Creation


Select “Manage RFC Destination” to create an HTTP destination



Click "Create" button to create a new HTTP destination (connection information to SAP Cloud Platform Enterprise Messaging).


Connection Type should be "G" (HTTP Connection to external server).





Enter the host name (without "wss:///") and the path using the " uri " of the Service Key information above .

In Logon and Security Tab, change the SSL setting to be Active and select the DEFAULT SSL Client(Standard) where the certificates were imported in t-code STRUST.


3.9 OAuth Client Setup


OAuth Client Credential Flow is used for authentication from SAP S/4HANA to Enterprise Messaging and we will create the OAuth client setting.
Click "Manage OAuth 2.0 Account Client Setup"



 

A new browser window will open, enter your user ID and password to log in to the system.



Once you are logged in, press “Create”.


Select "/IWXBE/MGW_MQTT" for the profile and enter the Configuration name freely.
Enter the clientid of the Service Key to the OAuth 2.0 Client ID and press OK.



Set Client Secret (clientsecret in the service key).

For the authorization endpoint replace “token” of token endpoint with “authorize”
Please do not enter “https://” as it is already there

Select “Header Field” and “Client Certificate”



Press “Save”.


 



3.10 Channel Creation


Click "Manage Channel and Parameters"



 

Press “New entries” to add a new entry and enter the Channel Name, Destination name, Topic space and description.
Channel Name: Arbitrary value
Protocol: MQTT_311_WS
Destination: HTTP destination created in 3.8
Topic space: This needs to match to the Enterprise Messaging Namespace.



Select the entry and double-click “Parameters”.



 

Press "New Entries" and add the parameters.



Enter the name entered in 3.9 above for OAUTH_20_CONFIGURATION.

Enter a fixed value of /IWXBE/MGW_MQTT for OAUTH_20_CLIENT_PROFILE.

You can add some other parameters based on the requirements.



Press this button to switch it to display mode.


Click “Active<->Inactive” to activate it.



 


3.11 Check the service settings


 



 

 

 

 

 

 

 

 

 

 

 

Make sure there is an entry for Service: IWXBE, Enablement Service Registry: CL_BEH_SERVICE.


3.12 Event topic setting


Select "Maintain Event Topic".



 

 

 

 

 

 

 

 

 

 

 

 

Enter the channel name created in 3.10 and press enter.


Enter a new entry for Business Object Event.

If you enter “BO/OutboundDelivery/*” as shown below, all events (create, change, delete) of Outbound Delivery Document will be captured.



 

From here you work with SAP Cloud Platform Cockpit.

3.13 SAP Cloud Platform Enterprise Messaging Subscription


Select subaccount and select "Subscription" from the menu.

Click “Go to Application”.



 

On the Enterprise Messaging Admin page, click Message Client.



You can see the service instance created with CF CLI before.

Select “Create Queue”.


Create it with any name.





The Queue created here is the setting of this red frame part in the figure below.



 

Next, make a subscription from Queue to Topic.

Click "Action" and select #Queue Subscriptions".



T

 

 

 

 

 

 

 

 

As I have configured in the S/4HANA side, we want to subscribe to the Topic for the Outbound Delivery Document this time. "*" means  all of "create", "change" and "delete" event again.


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

With this setting, the Queue is now subscribing to the Topic, and messages entering the Topic will come to the Queue.
This configuration is the connection part inside the red frame in the figure below.



 

If you want to make an HTTP request to the outside when a message enters the Queue, you can also create a webhook. This setting is not necessary when sending with AMQP.

Let's create another Queue and set the webhook.
Go to the Webhooks tab and press “Create Webhook”.



Create it by giving the subscription name and entering the destination URL.



 

 

 

 

 

 

 

 

 

 

 

 

Since it is in the paused status at the first creation, select the "Resume" button from the drop-down list to resume it.



 

 

.Receiving system side settings etc.


I will omit the details of the setting to receive Queue with AMQP over websocket, but let's highlight the screenshot here.

Here is the trigger settings in SAP Cloud Platform Extension Factory, Serverless Runtime



Add using the set Queue name.



Connect using the service key information.



This is the sample code for receiving data from Enterprise Messaging.
Java
https://github.com/SAP-samples/enterprise-messaging-client-java-samples
Node
https://github.com/SAP-samples/enterprise-messaging-client-nodejs-samples

4 Conclusion


It is getting more important to think about asynchronous messaging using Event for the future system architecture.This blog is about S/4HANA On-Premise and SAP Cloud Platform but similar concept will come to the other solutions as well. I hope everyone can get the rough idea how the event based messaging works.
And please give it a try!

Enterprise Messaging Developer Tutorial
https://developers.sap.com/tutorial-navigator.html?tag=products:technology-platform/sap-cloud-platfo...

S/4HANA On-Premise Enterprise Event Enablement Online Help
https://help.sap.com/viewer/810dfd34f2cc4f39aa8d946b5204fd9c/1909.002/en-US/c200f98fadb64ff1828ed569...

SAP Cloud Platform Enterprise Messaging Online Help
https://help.sap.com/viewer/product/SAP_ENTERPRISE_MESSAGING/Cloud/en-US

SAP Cloud Platform Extension Factory Serverless Runtime Online Help
https://help.sap.com/viewer/product/XF_SERVERLESS_RUNTIME/Cloud/en-US

SAP Cloud Platform Integration Online Help
https://help.sap.com/viewer/product/CLOUD_INTEGRATION/Cloud/en-US

 
20 Comments