转 Demo on Workflow using Classes

Demo on Workflow using Classes

By Richa Gupta, Sparta Consulting from Link

Purpose

To develop workflow using OOPS concept instead of using standard Business Object.  

NOTE: Before following this document, one must have a basic knowledge of OOPS Concepts.

Steps to follow to use Classes in Workflow  

 How to Create Custom Class  

Here we will be creating a custom class for MATERIAL.

Go to transaction SE24 and create a customized class.

转 Demo on Workflow using Classes

Next the pop up appears where we need to mention the detail as follows:

转 Demo on Workflow using Classes

Save it and the class is created.

Now the class is to implement IF_WORKFLOW interface. For this go to the  转 Demo on Workflow using Classes  tab and declare the IF_WORKFLOW as the interface there and press Enter; two sub-interfaces appear: BI_OBJECT and BI_PERSISTENT. Save the Class.

转 Demo on Workflow using Classes

The ZCL_TEST class now contains the existing methods of IF_WORKFLOW interface. 

转 Demo on Workflow using Classes

Also, 2 new interfaces will be automatically added once you add IF_WORKFLOW interface in the class as shown below:

转 Demo on Workflow using Classes

Each method of the IF_WORKFLOW Interface has its distinct functionality, which is discussed below.  

 BI_PERSISTENT~FIND_BY_LPOR Method:  

转 Demo on Workflow using Classes

 Here, to create object, constructor of class needs to be implemented as follows:  

转 Demo on Workflow using Classes

Here, SET_ATTRIBUTES method is called which will be implemented as follows :  

转 Demo on Workflow using Classes

BI_PERSISTENT~LPOR Method:

转 Demo on Workflow using Classes

BI_PERSISTENT~REFRESH Method:  

If we do not need the method in our class, then we need only to carry out a “dummy” implementation (without further coding) to avoid program errors when the system calls the method. 

 

转 Demo on Workflow using Classes

 BI_OBJECT~DEFAULT_ATTRIBUTE_VALUE Method:  

转 Demo on Workflow using Classes

 BI_OBJECT~EXECUTE_DEFAULT_METHOD Method:  

转 Demo on Workflow using Classes

 BI_OBJECT~RELEASE Method:  

转 Demo on Workflow using Classes

Now, the attributes need to be developed to implement above methods are as follows:  

转 Demo on Workflow using Classes

To trigger the workflow using event of class, we must also create an event of the class. To do this, go to EVENTS tab, and there create a new event CREATED as shown below :  

转 Demo on Workflow using Classes

Before implementing above methods, a local type needs to be created. To do this, click on LOCAL TYPES as shown below:  

转 Demo on Workflow using Classes

Now write the below code :  

转 Demo on Workflow using Classes

How to use Class in a Workflow  

Here, the workflow needs to be triggered as soon as a material is created. And then a workitem should go to initiator to edit the same material.  

Go to SWDD to create a new workflow.

Click on Basic Data Tab :  

转 Demo on Workflow using Classes

Give an abbreviation and Short Description to workflow as follows :

转 Demo on Workflow using Classes

Now click on START EVENTS tab and specify the following standard event of the standard class :

转 Demo on Workflow using Classes

Now go back and right click in between the WORKFLOW STARTED and WORKFLOW COMPLETED.

转 Demo on Workflow using Classes

Select CREATE. A list of available step types will be displayed as follows:  

转 Demo on Workflow using Classes  

Select ACTIVITY from this list. The following screen will appear:  

转 Demo on Workflow using Classes

Specify the following details here:  

转 Demo on Workflow using Classes

Click on Binding tab. Binding will be as follows:  

转 Demo on Workflow using Classes

Click on task description. Automatically following details will show :  

转 Demo on Workflow using Classes

Click on the green button for binding above and confirm the bindings must be as follows :

转 Demo on Workflow using Classes

SET AGENT ASSIGNMENT:  

Click on yellow button coming besides Agent Assignment :  

转 Demo on Workflow using Classes

Click on ATTRIBUTES:  

转 Demo on Workflow using Classes  

Select General Task and click on TRANSFER  

转 Demo on Workflow using Classes  

How to trigger event of Class  

To trigger event of a class, we need to call method RAISE of standard class CL_SWF_EVT_EVENT. This method can be called in a user exit, BAdi, or a custom report depending on the requirement.  

In our case, we are calling the method in a BAdi ‘BADI_MATERIAL_CHECK’.  

The method in which event will be raised is CHECK_DATA.  

转 Demo on Workflow using Classes

Create a new custom method RAISE_EVENT in the class implemented for BAdi.

Following method will be called to raise event:  

转 Demo on Workflow using Classes

Activate class and go back.

Now go in CHECK_DATE method and write the below code:  

转 Demo on Workflow using Classes

Output 

Create a new material. To do this, go to MM01.  

转 Demo on Workflow using Classes  

Press Enter and the following screen will appear :  

转 Demo on Workflow using Classes  

Specify the above details and press Enter. On the next screen, enter the following details :  

转 Demo on Workflow using Classes

Click on SAVE 转 Demo on Workflow using Classesbutton.  

转 Demo on Workflow using Classes  

As soon as the material gets created, the workflow will trigger as shown below in the workflow log :

转 Demo on Workflow using Classes

 

 

相关推荐