
Creating Customer Events for Customer Business Objects
Context:
In the earlier blog we introduced various scenarios in which business events can be extended and logged via Business Event Logging. In this blog we will explain the steps needed to implement a custom scenario with all its variations.
Environment:
This feature is available for customers working with the SAP BTP ABAP environment, but it also works for SAP S/4HANA Cloud Public, SAP S/4HANA Cloud Private, and S/4HANA (On-Premises) editions from release 2022 FPS 2 onwards.
Pre-requisites:
To get started, ensure that you have the following roles:
You must also create 2 custom roles an example is given below:
A role created using the template SAP_BR_DEVELOPER is also needed to create the required ABAP artifacts for this scenario.
You'll also need the ADT for Eclipse IDE
Explanation: For this example, we use a customer RAP Business object with the following structure:
This is a simple RAP Business Object with a Header Node and Item Node and set of attributes corresponding to each node.
To cover Business Event Logging related scenarios, we have defined two item-related events ItemStatusChanged and ItemQtyChanged and one header level event StatusChanged. All these events transport field change information.
The equivalent Behaviour definition (BDEF) looks like below
Modelling Event Parameter:
From the BDEF we see that each event has a deep parameter assigned to it. This parameter stands for the event payload format. The deep format is used here, as it is the standard way to transport field changes.
For the event parameter ZD_ITEMQTYCHANGED for event ItemQtyChanged, the event parameter represents the event payload (the business data beyond the key). The payload is modelled using abstract entity. The abstract entity ZD_ITEMQTYCHANGED is a nested structure with certain fields and a node named as __before (two underscores) of type ZD_ITEMQTYCHANGEDOLD. This is the default way to define field changes in a business event.
Both the structures have the same fields. The structure ZD_ITEMQTYCHANGED holds the latest values of Quantity and UOM while ZD_ITEMQTYCHANGEDOLD holds the values of Quantity and UOM before the change was executed.
Please note that you are required to maintain the annotation ObjectModel.sapObjectNodeType.name in abstract entities as well as the RAP CDS views.
Below is an illustration of how the event parameters are filled and event raised in the BDEF implementation class.
SAP Object Type and SAP Object Node Type
For each node we need to create the SAP Object Node Type and for header node we create SAP Object Type as well in ADT as shown in below picture. The names should be maintained in CamelCase.
Event Binding: Maintain the event bindings using a customer namespace.
Business Event Modelling in On-Premise/ Private Cloud Prior 2023 Release:
In the releases prior to 2023, the event modelling was done in different way as RAP framework didn't allow declaration of a given node event at the respective node. All events had to be declared at the root node level in BDEF. BEL supports logging of the events in this scenario as well, but we need to follow few rules.
Corresponding BDEF:
For this alternate example we have created SAP Object Types and SAP Object Node Type
SAP Object Type. = ZBusinessObjectHeaderAlt
SAP Object Node Type = ZBusinessObjectItemAlt
A careful look at the abstract entity definition you will notice three important distinctions.
2. For the node level events Event.sapObjectNodeTypeKey annotation need to be maintained with the correct names of the Key Names for that node.
3. To model the old and new values in abstract entity we need to use event.previousValue.element annotation.
This functionality is available on:
ABAP on BTP (Steampunk)
SAP S/4 HANA Cloud Public Edition
SAP S/4 HANA Cloud Private Edition (Release 2022 FPS2 onwards)
SAP S/4 HANA On-Premise 2022 FPS2 onwards
Note: In On-Premise and Private Cloud Editions for release 2022, the functionality to create SAP Object Type (SOT) and SAP Object Node Type (SONT) is not available for customer. The customer can explicitly define SOT in the event binding and SONT in the annotations. Care should be taken that the names are in camel case.
Once all the above considerations are met in a RAP BO we can use BEL by a simple configuration. We need to maintain SAP Object Type via the steps given below and select Activate Logging and Log All Data Options. With this we are good to go with logging our custom business events using BEL.
Execution and Monitoring:
For the demo purpose I have created an ABAP code to consume the RAP BO using EML thereby triggering these events multiple times. We can visualize these logs using BEL apps.
Display Business Event Log App
Customer events can always be identified via the entry in the Producer Namespace Column.
Detail View of Item Quantity Changed
The source of the demo example is provided at the below given git repo.
https://github.com/aarsaraf/DemoExample.git
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
32 | |
16 | |
13 | |
9 | |
8 | |
8 | |
6 | |
6 | |
5 | |
5 |