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.
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 Container
Step 2: – Create the extended solution to complete the business process.
◉ Create a global class using T-code SE24.
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 Name
◉ Invoke Get method which would deliver you a value of an element/parameter when you pass the container name.
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 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.
Create Event
◉ Click on event parameter and enter WBSELEMENTINTERNALID.
Container Instance Editor
◉ Click on create event. The Z class will be triggered.
Debugger
Conclusion: – This is how standard events can be utilized to provide a sustainable solution in extending business process solutions without touching the core.
No comments:
Post a Comment