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.
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.
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 ) ..