Technology Blog Posts by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
RohitSaraf
Product and Topic Expert
Product and Topic Expert
693

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:  

RohitSaraf_0-1742911991867.png

You must also create 2 custom roles an example is given below:  

  •  ZBEL_CONFIG using the template SAP_BR_BPC_EXPERT to configure Business Event Logging. 
  •  ZBEL_MONITORING using the template SAP_BR_BUSINESS_PROCESS_SPEC to check the event log. 

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:

RohitSaraf_1-1742911991867.png

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  

RohitSaraf_2-1742911991868.png

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.  

RohitSaraf_3-1742911991868.png

RohitSaraf_4-1742911991868.png

Please note that you are required to maintain the annotation ObjectModel.sapObjectNodeType.name in abstract entities as well as the RAP CDS views. 

 

RohitSaraf_5-1742911991868.png

Below is an illustration of how the event parameters are filled and event raised in the BDEF implementation class. 

RohitSaraf_6-1742911991869.png

 

RohitSaraf_7-1742911991869.png

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.  

RohitSaraf_8-1742911991869.png

 

RohitSaraf_9-1742911991869.png

Event Binding: Maintain the event bindings using a customer namespace. 

RohitSaraf_10-1742911991870.png

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.  

 

 

RohitSaraf_11-1742911991870.png

Corresponding BDEF: 

RohitSaraf_12-1742911991871.png

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. 

 

RohitSaraf_13-1742911991871.png

 

  1. It is mandatory to maintain annotation ObjectModel.sapObjectNodeType.name in all the abstract entity with the correct name. 

     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. 

 

RohitSaraf_14-1742911991871.png

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. 

 

RohitSaraf_15-1742911991872.png

Display Business Event Log App 

RohitSaraf_16-1742911991872.png

Customer events can always be identified via the entry in the Producer Namespace Column.  

Detail View of Item Quantity Changed 

RohitSaraf_17-1742911991872.png

The source of the demo example is provided at the below given git repo.

https://github.com/aarsaraf/DemoExample.git  

 

 

 

 

11 Comments
DungVT37
Explorer
0 Kudos

Hello @ @RohitSaraf 

Thank you for your sharing.

I have downloaded your sample demo in github and pull it into my project in Eclipse ADT.

And then I have created the custom business roles: ZBEL_CONFIG, ZBEL_MONITORING and assigned them to my account.

But when I went to the app "Display Business Event Logs", I cannot find my business object "ZBusinessObjectHeaderAlt" event if I ran the class: "zcl_create_bizobj_alt" and "zcl_update_bizobj_alt" (F9) successfully.

DungVT37_0-1744085279541.png

DungVT37_1-1744085402443.png

Is there any step that I missied?

Thank you for your help.

RohitSaraf
Product and Topic Expert
Product and Topic Expert
0 Kudos

@DungVT37  Have you activated ZBusinessObjectHeaderAlt in Custom business configuration as we have done for ZBusinessObjectHeader.

DungVT37
Explorer
0 Kudos

Hi @RohitSaraf 

Thank you for the quick response.

Follow the link below:

https://help.sap.com/docs/SAP_S4HANA_CLOUD/a630d57fc5004c6383e7a81efee7a8bb/e477a6054926477c92e24837...

I think I need the basis team active the app "Business Event Logging" first.

DungVT37_0-1744095224950.png

DungVT37_1-1744095344656.png

Please correct me if I am wrong.

Thank you!

RohitSaraf
Product and Topic Expert
Product and Topic Expert
0 Kudos

@DungVT37  When you are trying to maintain the SAP Object Type , are you saying you are not able to open it in edit mode. Role ZBEL_CONFIG should provide you the necessary auth to configure.

DungVT37
Explorer
0 Kudos

@RohitSaraf You are correct, I can not change to Edit mode although the role configuration is already assigned to me.

DungVT37_1-1744097487562.png

DungVT37_0-1744097418490.png

Regards,

DungVT37

RohitSaraf
Product and Topic Expert
Product and Topic Expert
0 Kudos

@DungVT37  can you check in General Role Detail if all values are marked as unrestricted.

 

RohitSaraf_0-1744098209618.png

 

RohitSaraf
Product and Topic Expert
Product and Topic Expert
0 Kudos

@DungVT37 Can you also try logging in incognito mode and try editing

RohitSaraf
Product and Topic Expert
Product and Topic Expert
0 Kudos

@DungVT37 Observed one more point, i can see only one Business Catalog , but if we create roles using template BPC_EXPERT there should be multiple .Can you recheck.

DungVT37
Explorer
0 Kudos

@RohitSaraf Because I filtered the catalog "SAP_CA_BC_IC_LND_BEL_PC" so you only see one business catalog.

DungVT37_1-1744099802882.png

DungVT37_2-1744099885772.png

Regards,

DungVT37

 

RohitSaraf
Product and Topic Expert
Product and Topic Expert
0 Kudos

@DungVT37  In case its still not working for you please open an incident with SAP on component CA-GTF-BEL for resolution

RohitSaraf
Product and Topic Expert
Product and Topic Expert
0 Kudos

@DungVT37 Were you able to run the scenario successfully or raised the incident?