转 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.
Next the pop up appears where we need to mention the detail as follows:
Save it and the class is created.
Now the class is to implement IF_WORKFLOW interface. For this go to the 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.
The ZCL_TEST class now contains the existing methods of IF_WORKFLOW interface.
Also, 2 new interfaces will be automatically added once you add IF_WORKFLOW interface in the class as shown below:
Each method of the IF_WORKFLOW Interface has its distinct functionality, which is discussed below.
BI_PERSISTENT~FIND_BY_LPOR Method:
Here, to create object, constructor of class needs to be implemented as follows:
Here, SET_ATTRIBUTES method is called which will be implemented as follows :
BI_PERSISTENT~LPOR Method:
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.
BI_OBJECT~DEFAULT_ATTRIBUTE_VALUE Method:
BI_OBJECT~EXECUTE_DEFAULT_METHOD Method:
BI_OBJECT~RELEASE Method:
Now, the attributes need to be developed to implement above methods are as follows:
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 :
Before implementing above methods, a local type needs to be created. To do this, click on LOCAL TYPES as shown below:
Now write the below code :
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 :
Give an abbreviation and Short Description to workflow as follows :
Now click on START EVENTS tab and specify the following standard event of the standard class :
Now go back and right click in between the WORKFLOW STARTED and WORKFLOW COMPLETED.
Select CREATE. A list of available step types will be displayed as follows:
Select ACTIVITY from this list. The following screen will appear:
Specify the following details here:
Click on Binding tab. Binding will be as follows:
Click on task description. Automatically following details will show :
Click on the green button for binding above and confirm the bindings must be as follows :
SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :
Click on ATTRIBUTES:
Select General Task and click on TRANSFER
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.
Create a new custom method RAISE_EVENT in the class implemented for BAdi.
Following method will be called to raise event:
Activate class and go back.
Now go in CHECK_DATE method and write the below code:
Output
Create a new material. To do this, go to MM01.
Press Enter and the following screen will appear :
Specify the above details and press Enter. On the next screen, enter the following details :
Click on SAVE button.
As soon as the material gets created, the workflow will trigger as shown below in the workflow log :