Skip to Content

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.

/wp-content/uploads/2012/03/1_82666.jpg

Enter description and click on save.

/wp-content/uploads/2012/03/2_82790.jpg

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.

/wp-content/uploads/2012/03/3_82791.jpg

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.

/wp-content/uploads/2012/03/4_82792.jpg

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.

/wp-content/uploads/2012/03/5_82793.jpg

Select the event, click on parameters button and create parameter as shown below

/wp-content/uploads/2012/03/6_82794.jpg

Create parameter EMPID as shown below

/wp-content/uploads/2012/03/7_82795.jpg

Step 3: Creating Methods.

Go to methods tab, and create method as shown below

/wp-content/uploads/2012/03/8_82796.jpg

Click on parameters button to create parameters for the method register_employee.

/wp-content/uploads/2012/03/9_82797.jpg

Create an importing parameter I_EMPID as shown below.

/wp-content/uploads/2012/03/10_82798.jpg

Create one more method to get employee name.

/wp-content/uploads/2012/03/11_82799.jpg

Select method get_empname and click on parameters button to create parameters.

/wp-content/uploads/2012/03/12_82800.jpg

Create an importing parameter I_EMPID and an exporting parameter E_EMPNAME as shown below.

/wp-content/uploads/2012/03/13_82801.jpg

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.

/wp-content/uploads/2012/03/14_82802.jpg

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


To report this post you need to login first.

14 Comments

You must be Logged on to comment or reply to a post.

  1. PavanChand Bhamidipati

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

    (0) 
    1. Kiran Kumar Valluru Post author

      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.

      (0) 
    1. Kiran Kumar Valluru Post author

      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

      (0) 
      1. Gaurav Subramanian

        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.

        (0) 
  2. Ravi Mehta

    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 ???

    (0) 
  3. Julia Lanra

    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.

    (0) 

Leave a Reply