Skip to Content
Technical Articles
Author's profile photo Shreenath Bhaskar Bangera

Extend business process solutions using standard events.

Recently in one of the project implementations, I got a requirement to extend the solution by creating subsequent document based on a business process being executed. I am sharing this blog as I felt not much has been written for such type of requirements.

Problem Statement: –

How do you create a subsequent document based on a current business process being executed? Example – You want to create an asset and settlement rule immediately after the WBS is created and release the project. BADI implementation will not be an answer for the above requirement because the WBS element will not be created in the system while the BADI is being executed and you want to create the subsequent document based on the WBS element.

Classic extensibility is not a sustainable approach as it builds more complexity to the core and prevents adopting agile practices leading to issues during upgrades as the code would be tightly coupled to the standard process.

Solution: –

Make use of standard events when you want to extend your business process solutions. The below solution is with respect to the example mentioned in the problem statement. You would be able to implement a similar solution for other business processes.

Step 1: – Look for a standard event which would get triggered after the business process is completed.

In my case, event should be triggered after project (T-code CJ20N) is created.

  • Switch on the trace using T-code- SWELS.

          Event%20On%20trace

Switch On trace

  • Run the T-code (CJ20N) for project creation and create a project.
  • Once project is created, switch off the trace using T-code SWELS and go to t-code SWEL to display the trace results. The below screenshot shows the trace result with object type and event that was triggered once WBS is created.

         

Event Trace result

Object type – CL_PS_WBSELEMENT_EVENT

Event – WBSELEMENTCREATED

  • Double click on the event and click on show event container data. Event container will contain the WBS element internal ID which got triggered.

          Event%20Container

Event Container

Step 2: – Create the extended solution to complete the business process.

  • Create a global class using T-code SE24.

          Global%20Class

Global Class

  • Implement interface – BI_EVENT_HANDLER_STATIC in your class and implement the method ON_EVENT. This interface helps you handle the event that would get triggered.

          Interface%20Name

Interface Name

  • Invoke Get method which would deliver you a value of an element/parameter when you pass the container name.

Get%20Method

Get Method

  • Once I have the WBS element number I can implement the rest of the logic to create an asset, update settlement rule in the project and release the project.

Use the below BAPI to create subsequent document and complete the process.

  1. BAPI_FIXEDASSET_CREATE1 to create an asset.
  2. FM- K_SRULE_SAVE_UTASK to update settlement rule.
  3. BAPI- BAPI_BUS2001_SET_STATUS to release the project.

Step 3: – Configure the event linkages using T-code SWE2.

  • Create an entry for the standard class – CL_PS_WBSELEMENT_EVENT and event WBSELEMENTCREATED.
  • Event receiver call would be Method.
  • Maintain the Z class name (created in step 2) in the event receiver section.
  • Check on linkage activated and save.

Event%20linkage

Event linkage

  • Go to SWU3 and make sure RFC destination is configured and everything is checked green. If this is not configured, the triggered event would go into event queue and the Z class will not be called.

Step 4: – Debug and test.

  • Put a break point in the Z class method – ON_EVENT.
  • Go to T-code SWUE, enter object category ABAP Class, object type – CL_PS_WBSELEMENT and event – WBSELEMENTCREATED. Click on Enter.

          T-code%20SWUE

Create Event

  • Click on event parameter and enter WBSELEMENTINTERNALID.

    Container%20Instance%20Editor

Container Instance Editor

  • Click on create event. The Z class will be triggered.

          Debugger

Debugger

Conclusion: – This is how standard events can be utilized to provide a sustainable solution in extending business process solutions without touching the core.

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Dominik Tylczynski
      Dominik Tylczynski

      I really like business process automation with workflow events, especially that they can be triggered very flexibly e.g. from status changes or change documents - SAP Help: Event Creation

      The only drawback I see is that if something goes wrong it is next to impossible to diagnose if workflow trace is off. Therefore I would recommend to keep it active in SWELS.

      Author's profile photo Shreenath Bhaskar Bangera
      Shreenath Bhaskar Bangera
      Blog Post Author

      Hi Dominik,

      If something goes wrong, then I think we should be able to handle the error in the result parameter of the event handler or raise an exception.

      If there is an exception raised, it should be logged in the event queue or somewhere. I am not sure of this, but I will definitely check and get back on your point.

      Thank you for sharing your thoughts.

       

      Author's profile photo NikhilPrateek Kulkarni
      NikhilPrateek Kulkarni

      Good one Shreenath

      Author's profile photo Jelena Perfiljeva
      Jelena Perfiljeva

      Thank you for sharing! This end-to-end process description will be helpful to many developers.

      Question: how did you know to implement BI_EVENT_HANDLER_STATIC interface? Is it mentioned somewhere in the documentation? In the event itself?

      Additionally, for those who need to implement a custom event, there is a good blog post on that: https://blogs.sap.com/2022/03/16/custom-events-in-sap-event-mesh.-step-by-step-part-1-create-a-custom-event/

      Author's profile photo Shreenath Bhaskar Bangera
      Shreenath Bhaskar Bangera
      Blog Post Author

      Hi Jelena,

      I am glad that you asked this question. Let me answer how I came across the interface BI_EVENT_HANDLER_STATIC.

      I was investigating on how I can make use of custom class to handle triggered events. I simply tried to maintain the custom class that I had created without the interface in t-code SWE2 (Event linkages) and the system itself prompts you an error message that you cannot use a class without interface - 'BI_EVENT_HANDLER_STATIC'. That's how I came across this interface and I used it.