How to Create and Trigger Class Based Workflow from Web Dynpro ABAP – Part 1
Introduction
Here I am going to explain a simple scenario to trigger Class based Workflow from Web Dynpro ABAP.
Scenario: Employee enters his ID and click on a button which triggers Workflow and send mail with Employee ID and Employee Name to Register for the Participation of Event.
I had explained the same scenario in my earlier article How to Trigger Workflow from Web Dynpro ABAP – Part1 , using Business Objects. Now we will see the same using ABAP Classes.
In this part, I am focusing on creating ABAP Class and Workflow. Web Dynpro part will come into picture in next part of this article series.
After Completion of this Article, You will be able to:
- Create ABAP Class to use in Workflow.
- Create Workflow.
Creating ABAP Class to use in Workflow
Step 1: Create Class.
Go to SE24 transaction and Create a Class.
Enter description and click on save.
Here if you want to reuse this class methods in other subclasses, uncheck the check box ‘Final’.
Go to interfaces tab and enter if_workflow and press enter.
Classes that have implemented the IF_WORKFLOW interface are recognized as workflow-enabled in the Class Builder.
As soon as the interface is added, two sub-interfaces appear: BI_OBJECT and BI_PERSISTENT.
Move across to the Methods tab and you will see some methods of these interfaces have been automatically inherited to the ABAP Class.
Step 2: Creating Events.
Now go to Events tab and create an event REGISTER as shown below.
Select the event, click on parameters button and create parameter as shown below
Create parameter EMPID as shown below
Step 3: Creating Methods.
Go to methods tab, and create method as shown below
Click on parameters button to create parameters for the method register_employee.
Create an importing parameter I_EMPID as shown below.
Create one more method to get employee name.
Select method get_empname and click on parameters button to create parameters.
Create an importing parameter I_EMPID and an exporting parameter E_EMPNAME as shown below.
Step 4: Methods Implementation.
Now enter the below code in REGISTER_EMPLOYEE method.
REGISTER_EMPLOYEE |
---|
method REGISTER_EMPLOYEE. * Data Declarations * Setting values of Event Name * Instantiate an empty event container * Set up the name/value pair to be added to the container * Add the name/value pair to the event conainer CATCH cx_swf_cnt_cont_access_denied . * Raise the event passing the prepared event container COMMIT WORK. |
Just like the function module SAP_WAPI_CREATE_EVENT to trigger business object, we use method cl_swf_evt_event=>raise in OO to trigger event.
Enter the below code in GET_EMPNAME method.
GET_EMPNAME |
---|
method GET_EMPNAME. endmethod. |
As we need to implement the interface methods, double click on each of the methods inherited from the IF_WORKFLOW interface, and activate the empty source code.
Now save and activate the class.
In the next part How to create and trigger class based workflow – part 2 , we will see how to create workflow ( as the max. no of images reached ) ..
Nice work; can you also share this in the Workflow forum?
Well Explained.. Thanks for sharing..
Hi,
thanks for sharing.
Please rectify the event name assigned to variable lv_event.
Regards,
Sayan
Thank You. Updated the Event name 🙂
Kiran
That was nice work and I appreciate your presentation, but I have a comment ,, that I felt this is a repeated content. I still remenber when I submitted my first blog moderator" tried to validate even my code standards like if any exceptions are raised then you need to catch".
Iam trying to correct you, do not take it in other way,
1. You have written the code but you need to also follow the standards.
2. What makes the blog very much different from Jocleyn Darts OO Workflow. The same content is already shared.
3. Focus on what exactly you want to say.(Do you really think that you need 4 parts to say that on click of Register button you are calling a method which raises event by using class method..)
4. Follow the coding standrads.
Iam sorry if i was hard , but this is how you have to judge your selves. when you are publishing a blog....
Hi PavanChand,
Thank you for your comment.
1. I didn't gave much importance to coding standards, as I just want to demonstrate the creating class based workflow for newbies with step by step process. And moreover I had followed some of the naming conventions and exception handling.
2. It takes 4 parts as the max limit for images(20) exceeds for each document.
And it's not a blog to summarize, It is an article. My aim is to show each steps, so that any newbie who is not aware of classes and workflow can able to learn and do it.
Thank you once again for your comment and the point regarding following standards. I will follow those in my coming articles if any..
Thanks,
Regards,
Kiran.
Nice work kiran.... 🙂
good work..nice documents.
The decison to ignore all those exceptions isn't a good idea 😐 They aren't raised just to annoy you!
Hello Ron,
Thanks for your feedback. My intention was not to explain exception handling in this document and hence I left them blank. You can always do your own processing after catching the respective exception.
This document just explains(or focus on) how to trigger a class based workflow from WDA.
Regards,
Kiran
Nice work Kiran.
Do you have any link or detailed blog on calling WDA from Workflow ? I am trying to create an sandbox application with Roadmap UI element, where every step will trigger Workflow and WDA will get displayed to different user's with consecutive roadmap steps based on authorization. Regret, if I would had missed any your such blogs.
Thanks,
Gaurav.
Very nice ... what value should be passed to " im_objkey = lv_objkey " ??
I did everything as mention in your article but still i am getting this error "Exception CX_SY_REF_IS_INITIAL triggered by LSWF_UTL_EXECUTIONU02 in line 193 with text: Dereferenci" am i missing something ???
Hi all,
Thanks for sharing. I have one workflow triggered by a standard class, and now I had to upgrade it adding a wait step for an event in a Z class. Is there any additional configuration for the event? Because I'm able to trigger it but in SWEL tx is saying that there's no connection between the event and the workflow...
Thank you all in advance.
Juls.
Hi kirankumar.valluru and all
I followed all the steps same as mentioned in all 4 continued links of Workflow using classes
Everything is working fine (output also coming correctly). But after clicking on button (Register) nothing is coming in (inbox of) SBWP T Code.
Need your suggestion and help on this. how to correct it?
I also try to do debug and saw one error cx_sy_move_cast_error
so how this error can be corrected or any other changes?
Thanks in Advance!
Thank you