Skip to Content
Technical Articles

Business Events in S/4HANA On Premise System: Trigger, Trace and Debug Custom Events: Part 2

In continuation to my Blog  Part 1; where I covered how to enable change Pointers on Custom table and trigger custom event. In this Blog I will cover the Code and detailed steps that are required to trigger Custom Event.

We can have either of 2 scenarios listed below; trigger custom event for custom change pointers from the code or to trigger Custom Event for the Standard Change pointers using Configurations.

Both Case a and Case b will require Custom Class to be created for the Events. Let’s have a look at steps that are required:

  1. Create Class in SE24 example ZCL_EVENT_CUSTOMTABLE
  2. Add IF_WORKFLOW and BI_EVENT_HANDLER_STATIC under Interfaces section; they are required for managing the events.

  3. Create Constructor for the Class and add parameter in the Constructor

4. Declare Events for the Class ‘CHANGED’

5.Add attributes in the class: MATERIAL_KEY is my custom attribute that will be used in event later

6. Also add the method ON_CHDOC_CHANGED that will have the logic for the custom functionality to be triggered.

7. Implement the methods of the class; in method BI_EVENT_HANDLER_STATIC~ON_EVENT ; handle the events call .

  • In case of CHANGED event; custom code written in method ON_CHDOC_CHANGED will be triggered.

8. In METHOD BI_PERSISTENT~FIND_BY_LPOR

METHOD bi_persistent~find_by_lpor.
DATA: sender TYPE sibflporb.” SIBFLPOR.
sender-instid = lpor-instid.
sender-typeid = lpor-typeid.
sender-catid = lpor-catid.
result = NEW zcl_event_customtable( i_sender = sender ).
ENDMETHOD.

9.  In METHOD BI_PERSISTENT~LPOR

METHOD bi_persistent~lpor.
result = inst_lpor.
ENDMETHOD.

10. In CONSTRUCTOR

METHOD constructor.
DATA(class_name) = cl_abap_classdescr=>get_class_name( me ).

inst_lpor-instid = i_sender-instid.
inst_lpor-typeid = class_name+7.
inst_lpor-catid = ‘CL’.
instid = inst_lpor-instid.
material_key-mandt = sy-mandt.
material_key-matnr = inst_lpor-instid+0(18).
material_key-werks = inst_lpor-instid+19(4).

ENDMETHOD

11. In METHOD ON_CHDOC_CHANGED – You can write your logic example to call REST API End point for sending data to middleware

12. In Transaction SWETYPV, define the Event and Class linkage

Now for Case a. we have already seen that how Event is triggered from Custom Code. Let’s also see an example of case b: where standard change pointers are available example lets take case of Fixed Assets.

  1. Create Custom Class and Event as explained above
  2. Now configure the same in SWEC Transaction as shown below .
  3. Also configure the same in SWETYPV Transaction
  4. Now if Trace is on SWUE transaction ; any changes in Assets data using transaction AS02 will trigger the custom event
  5. Now we have covered both the options a and b for triggering custom event. Let’s check detailed steps for troubleshooting; how you can trace and debug events .

           To check if Custom Event is getting triggered from your program

    • Go to Transaction SWUE and Switch on the Trace if it’s not already switched on
    • Enter the details of your Custom Event to want to track
    • In the next screen, you can filter the data example I want to display only the events that are created by specific Custom Program
    • In next screen, you can see the trace of our Custom Events that were called from the Program
    • Select the Event and Click on display to see the details of the Event

      How to Debug logic inside Event: In case you want to debug the logic that you have written inside the event follow below listed steps: 

  • Go to Transaction SWF_DEBUGGER
  • Now Execute your Custom Program that triggers the Event; once the program is executed you will find the same in Request data. You can select this request data and click on Start Debugging and then you are ready to debug the event 
  • You can debug your custom code now ; example I have further put a break point in my class and method

In this blog I have covered triggering , tracing and debugging of Custom Event. Now with S/4HANA 2020 system; you can Enable Event Mesh for Custom events but that requires a series of Configurations. In upcoming blog post, we will cover the steps that are required to enable Event Mesh for Custom Events.

Regards
Taranam

Be the first to leave a comment
You must be Logged on to comment or reply to a post.