---
title: "转 How to Trigger Class based workflow "
author: "evangxli"
date: "2013-08-15T09:45:23Z"
tags: []
categories: ["行业应用"]
slug: "how-to-trigger-class-based-workflow"
draft: false
lastmod: "2013-08-07T13:02:12Z"
id: 1917186
url: "https://sapabap.iteye.com/blog/1917186"
---

#### How to Trigger Class based workflow

By Rakesh Dhudipala from [Link](http://www.saptechnical.com/)

 

**Scenario:**

This explains a simple scenario to trigger Class based Workflow from program.  

**Step by Step procedure:**  

Go to SE24 transaction and create a class with ZCL\_WEBDYNPRO\_WF.

![](http://www.saptechnical.com/Tutorials/Workflow/Class/Index.47.gif)

Go to Interfaces tab and impl**ement the interf**ace IF\_WORKFLOW

![](http://www.saptechnical.com/Tutorials/Workflow/Class/Index.48.jpg)

Go events tab and create a event trigger with parameter i\_kunnr.

![](http://www.saptechnical.com/Tutorials/Workflow/Class/Index.49.gif)  
Go to methods tab and and implement the SET\_CUTOMER method with I\_KUNNR as importing parameter.

![](http://www.saptechnical.com/Tutorials/Workflow/Class/Index.50.gif)

Set\_customer method write the below code.  

method set\_customer.

* Data Declarations  
  DATA: lv\_class            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.

  lv\_class = 'ZCL\_WEBDYNPRO\_WF'.  
  lv\_event   = 'TRIGGER'.

* Instantiate an empty event container  
  CALL METHOD cl\_swf\_evt\_event=&gt;get\_event\_container  
    EXPORTING  
      im\_objcateg  = cl\_swf\_evt\_event=&gt;mc\_objcateg\_cl  
      im\_objtype   = lv\_class  
      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  = 'I\_KUNNR'.  " parameter name of the event  
  lv\_id          =  i\_kunnr.

  TRY.  
      CALL METHOD lr\_event\_parameters-&gt;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 event container  
  TRY.  
      CALL METHOD cl\_swf\_evt\_event=&gt;raise  
        EXPORTING  
          im\_objcateg        = cl\_swf\_evt\_event=&gt;mc\_objcateg\_cl  
          im\_objtype         = lv\_class  
          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.  

Go to SWDD transaction and create a new workflow called ZTEST\_WF  

![](http://www.saptechnical.com/Tutorials/Workflow/Class/Index.51.jpg)

Go to header and Start events tab and enter the below details  

![](http://www.saptechnical.com/Tutorials/Workflow/Class/Index.52.jpg)

 

Now if we call the SET\_CUSTOMER method it will trigger the ZTEST\_WF workflow.