Enterprise Event Enablement is a technical component in SAP S/4HANA. It enables the exchange of events across different platforms for seamless event-driven communication. Events from SAP S/4HANA can only be sent to SAP Event Mesh, where they can be used by any recipient.
In my previous blog series of
Enterprise Event Enablement for SAP BTP ABAP Environment, I introduced events in enterprise architecture, and the possible ways to produce and consume an event in SAP BTP ABAP Environment for the version 2208. Here, I would like to explain how you can do a similar process in an SAP S/4HANA on-premise system within release 2022.
Enterprise Event Enablement in a Nutshell
As said, we can develop or consume an event either in SAP S/4HANA on-premise or SAP S/4HANA Cloud. The communication between the consumer and producer applications is provided by SAP EventMesh. To arrange this communication, we need to build channels using the service key of a selected EventMesh instance. We also need to maintain the outbound topic binding to propagate the event from the event provider application to the EventMesh and the inbound topic binding from EventMesh to the consumer application by subscribing the queue to the topic we are interested in.
With the new release, you can
create a RAP Business event in an SAP S/4HANA on-premise system. Also, you can consume an existing event using the event consumption model embedded in ABAP Development Tools for Eclipse with the proper AsyncAPI file which can be downloaded from SAP API Business Hub.This step is important when you maintain channel configuration later.
Generate an Event Consumption Model from AsyncAPI
An Event Consumption Model is a set of ABAP artifacts which allows you to receive events from external applications and to consume them within your business application. We can have a wide range of event producers. So, we need to know how the emitted event exactly looks like. To this aim, we need a file which contains the metadata of this event like how the payload looks like, what kind of types are there and so on. This is all specified in the event specification file, in our case, AsyncAPI specification, which is supported by SAP and can be downloaded from SAP API Business Hub in JSON format. For this aim, I download an event specification for the event ’business partner created’ from the API hub.
Create an event consumption model in ADT
Here you will create an Event Consumption Model with the JASON file that you downloaded previously. Open ADT and connect to your S/4HANA system, then create a new ABAP Package if you have not one. Right-click your package and choose New > Other ABAP Repository Object > Business Services > Event Consumption Model and click Next button to launch the creation wizard.
Fill the fields and upload the. json file you saved before into the new event consumption ADT wizard. Go to the next page, select all the Event Types that you would like to consume in your business application after the first step of the Event Consumption Model. Then Define Consumer Artifacts. In the created event consumption model, you can see the selected Event Types that you are assigned to.
The steps you need to follow is explained in detail in step 2 of this
tutorial.
Implementation of Consumer Extension Class
The developer can then implement the event handler class which contains custom business logic like how the system should respond to this incoming event. In the generated class, you can find a respective handler event method for the selected event types of the Event Consumption Model. In each method, the corresponding event type and the typed business data for this event can be found. As an example, you can implement the same logic as step 4 of the
tutorial.
Channel Configuration
In order to successfully exchange events between SAP Event Mesh and SAP S/4HANA on-premise system, a corresponding connection is required. This connection is maintained by the Enterprise Event Enablement framework during channel creation. To consume events, the inbound bindings and subscriptions of the channel must be configured as well.
Creating a channel using a service key
A channel represents a single connection to a service instance of the SAP Event Mesh. As a prerequisite, you need to
prepare an Event Mesh instance in your SAP Business Technology Platform account and download the service key of this instance.
In your system, run the transaction /IWXBE/CONFIG
and press the button to create a new channel.
Paste the service key of your Event Mesh instance into the corresponding field. Destination name and OAuth Configuration name are optional fields. These are filled with random names if left empty.
The daemon user denotes the user under which the daemon session is running. The daemon sessions are background processes that are responsible for keeping the connection open and process the events. There is a corresponding role for the customer to use SAP_IWXBE_RT_XBE_DAEMON, which has all the required authorizations.
Paste the service key of your Event Mesh instance into the corresponding field. Destination name and OAuth Configuration name are optional fields. These are filled with random names if left empty.
The daemon user denotes the user under which the daemon session is running. The daemon sessions are background processes that are responsible for keeping the connection open and process the events. There is a corresponding role for the customer to use SAP_IWXBE_RT_XBE_DAEMON, which has all the required authorizations.
After creating a channel, you can decide which events should be listed on this channel. This explicit step of maintaining an outbound/inbound binding is necessary to publish/consume events from/in an S/4HANA system.
Configure inbound bindings
In the channel config UI, click on ‘Inbound Bindings’ to start configuring the event topics for the event consumption. Alternatively, you can run /IWXBE/INBOUND_CFG
.
In the following screen, you must first select an active channel. Then, click on ‘Inbound Bindings’.
It is best to use the search help for the topic. Here you will find all possible topics.
After selecting the topic and clicking on next, you can select a topic consumer that can consume the selected event topic. Several consumers for the same topic binding are also possible.
Click on “New Consumer Assignment”. Choose the “Repository ID” and the “Consumer ID” from the list. Here, we take the “Default” repository id which is “Enterprise Event Enablement Framework” repository. Your consumer has the same name as the one you gave when you created the event consumption model. Then, click “Create Destination”. Each consumer requires a bgRFC destination for the user switch. For each consumer we create a corresponding destination.
. Please keep in mind that the specified user here is the user that runs the consumer code in the event consumption model. So, one should make sure the specified user has all the necessary authorizations.
Then save it. The Consumer will be added successfully.
Configure subscriptions
First you must create a queue for your Event Mesh instance. How to get access to the SAP Event Mesh and creating a queue is already explained in this
blog post in details.
The second step of the event consumption configuration is the creation of queue subscriptions for the channel. Back to your OP system. In the channel config UI, you can simply click “Subscriptions” to start configuring the queue subscriptions for the event consumption. Alternatively, you can run /IWXBE/SUBSCRIPTION
.
Then you provide the address of the queue you already created for you Event Mesh instance.
Now you can consume an event using the event consumption model embedded in ABAP Development Tools for Eclipse (ADT).
Configure Event Consumption Scenario
To test your event consumption scenario, a business partner must be created in the event producer system (which can be any cloud or OP system). Based on the logic you defined in the handler event method (see the tutorial for details), as soon as a new business partner is created, the event will be sent to the EventMesh and you will see the ID of the created business partner in the table.
Back to your OP system in ADT, open your database table and run the table with F8. You can find the created business partners IDs in the table.
If you want to send the event from an Op system to the Event Mesh, you need to have an active channel and configure the outbound topic bindings for this channel. In the channel config UI, you can simply click on ‘Out’ to start configuring the event topics to be sent to SAP Event Mesh. Alternatively, you can run /IWXBE/OUTBOUND_CFG.
Here , you can see the details of configuring outbound binding. Then in that OP system, run the transaction ‘BP’ for creating new business partner, click ‘Person’ and create a new business partner. This information will be sent to the Event Mesh through the outbound binding you’ve created. This event then will be sent to you through the inbound binding and the subscription you made in previous steps. The event can also be sent from a cloud system to the EventMesh in a way which is described before in
this post.