Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member184578
Active Contributor

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
DATA: lv_objtype    TYPE sibftypeid,
lv_event            TYPE sibfevent,
lv_objkey           TYPE sibfinstid,
lr_event_parameters TYPE REF TO if_swf_ifs_parameter_container,
lv_param_name       TYPE swfdname,
lv_id               TYPE char10.


* Setting values of Event Name
lv_objtype = 'ZCL_WF_DEMO'. " Your Class Name
lv_event   = 'REGISTER'" Event Name.

* Instantiate an empty event container
CALL METHOD cl_swf_evt_event=>get_event_container
EXPORTING
im_objcateg  = cl_swf_evt_event=>mc_objcateg_cl
im_objtype   = lv_objtype
im_event     = lv_event
RECEIVING
re_reference = lr_event_parameters.

* Set up the name/value pair to be added to the container
lv_param_name  = 'EMPID'" parameter name of the event
lv_id          = i_empid.

* Add the name/value pair to the event conainer
TRY.
CALL METHOD lr_event_parameters->set
EXPORTING
name  = lv_param_name
value = lv_id.

CATCH cx_swf_cnt_cont_access_denied .
CATCH cx_swf_cnt_elem_access_denied .
CATCH cx_swf_cnt_elem_not_found .
CATCH cx_swf_cnt_elem_type_conflict .
CATCH cx_swf_cnt_unit_type_conflict .
CATCH cx_swf_cnt_elem_def_invalid .
CATCH cx_swf_cnt_container .
ENDTRY.

* Raise the event passing the prepared event container
TRY.
CALL METHOD cl_swf_evt_event=>raise
EXPORTING
im_objcateg        = cl_swf_evt_event=>mc_objcateg_cl
im_objtype         = lv_objtype
im_event           = lv_event
im_objkey          = lv_objkey
im_event_container = lr_event_parameters.
CATCH cx_swf_evt_invalid_objtype .
CATCH cx_swf_evt_invalid_event .
ENDTRY.

COMMIT WORK.
 
endmethod.

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.
* Get employee name corresaponding to employee ID
SELECT SINGLE ENAME from pa0001 INTO e_empname
WHERE PERNR = i_empid.

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


16 Comments
Labels in this area