Workflow Demo For Custom BO
Workflow Demo For Custom BO
Applies to:
SAP R/3 version 4.6c and onwards. For more information, visit the Business Process Modeling homepage.
Summary
The article describes the procedure to create a workflow with custom business object, having custom
methods and custom events.
Author: Saba Sayed
Company: Larsen & Toubro Infotech Limited
Created on: 07th August 2009
Author Bio
Saba Sayed is SAP certified NetWeaver ABAP Consultant, working in Larsen & Toubro Infotech
Limited. She has more than three years of SAP experience and has worked extensively in
ABAP, OO ABAP, Workflow, ALE / IDoc and SAP SRM.
Table of Contents
1. Scenario ................................................................................................................................................ 3
2. Flowchart ............................................................................................................................................... 3
3. Step-by-step procedure.......................................................................................................................... 4
3.1 Create business object .................................................................................................................. 4
3.2 Create Event.................................................................................................................................. 4
3.3 Trigger Event ................................................................................................................................. 5
3.4 Create Method ............................................................................................................................... 7
3.5 Create Step ................................................................................................................................... 9
3.5.1 Activity Step-Display PO ................................................................................................................................ 9
3.5.2 User Decision Step - Provide Approve or Reject Option .............................................................................. 10
3.5.3 Steps to Approve PO ................................................................................................................................... 10
3.5.4 Steps to Reject PO....................................................................................................................................... 12
3.6 Create Task ................................................................................................................................. 12
3.7 Code for Method .......................................................................................................................... 13
3.8 Workflow Completed .................................................................................................................... 14
3.9 Test Workflow .............................................................................................................................. 14
3.10 Business Workspace ................................................................................................................... 15
3.11 Workflow Log ............................................................................................................................... 16
3.12 Workflow Transactions ................................................................................................................. 16
3.13 Purchase Order Transactions ...................................................................................................... 16
Related Content .......................................................................................................................................... 17
Disclaimer and Liability Notice ..................................................................................................................... 18
Scenario
Create a workflow having custom Business object referencing standard Business Object for Purchase Order
(BUS2012). In this BO, create a custom method for displaying PO (PODisplayNew) similar to standard
method „Display‟ and a custom event (POChanged) that should be raised whenever you save the PO.
When the user approves/rejects the PO, a background task should run updating the custom [„Z‟] table with
status of PO as approved/rejected respectively.
1. Flowchart
Update custom „Z‟ table with PO Update custom „Z‟ table with PO
status as approved. status as rejected.
End Workflow
2. Step-by-step procedure
2.1 Create business object
Create a custom business object referencing the standard business object „BUS2012‟ and custom
event for changed PO.
a. Copy the standard business object and create a new business object OR you can create
business object by creating standard business object as supertype and new one as subtype.
b. Enter the required details for the event and click the green arrow.
d. Change the status of Event as implemented and also change the status of business
object as implemented „Edit Change release status Object type To
Implemented‟. Then generate the business object by clicking on red and white circle
„Generate‟ on application toolbar. Now your business object will be available for use.
Go to „Container‟ tab and enter the elements required for your workflow. Note that in
properties select atleast one parameter.
Finally in the „Triggering Events‟ tab, enter the event details, do the binding and
activate the event line item.
This completes your event creation process in workflow. Now for raising and
triggering the event follow step ii.
Check in „Workflow builder‟ [click on „Workflow builder‟ button in „Basic Data‟ tab or
go to „SWDD‟ transaction and enter the workflow template id] you will see the event
is created.
ii. Find out the user exit that is available for PO in case of „Save‟ event.
Please note that only when the PO is saved the event should get
triggered. In this case the exit is EXIT_SAPMM06E_013 that is invoked
prior to “commit work”. Create and raise the event for POChanged in the
above mentioned exit. [Include ZXM06U44]
b. Now whenever a PO is changed and saved, the above custom event will be
triggered.
c. Select the method and click on „Program‟ button. It will ask you if you want to generate a
template automatically for the missing section. Click on „Yes‟. It will navigate you to program with
begin and end of method block. Write the code for the method in this block.
d. Once this is done click on „Generate‟ button. Now this method could be used in the workflow
task.
b. Create a new task in the step and enter the business object details in it. Save it.
c. Do the binding. Once binding is done you can see green color.
d. Assign the agents as workflow initiator or any user whose inbox this display PO activity
should go.
e. In „Task Properties‟, set the attribute of „Agent Assignment‟ as „General Task‟ by clicking
red button next to it.
b. After creation of above step, you will find 2 options one as approve and other as reject.
b. Create a „Z‟ database table with fields‟ mandt, po number, date, time, status and description.
c. To get the value of approval or rejection from User Decision (UD) step, you will have to
create additional step between UD step and approval activity step. This step could be
created by double clicking [or right click and create] *‘PO Approved’ i.e. the outcome name
as highlighted below. Select this step as „ContainerOperation‟ *[zapp_po]. After creation of
this step your workflow will look like as given below:
[P.S.: * indicates check the below screenshot for step information]
d. To capture the status of PO create container element status. In properties, check import and
export parameter.
e. Now in the „ContainerOperation‟ step for approval, enter the following details:
Select execution method as background as we want the update should happen in background.
In the task container, create container as „Status‟ so that you can bind this task container element with
the container operation step‟s Status value.
Do the binding for the task linking status of workflow container with the status
of task container. (Note that datatype and length of both the container elements should be the same
otherwise binding will not happen.)
b. Do the same for rejection activity also. Take the same task name as created for approved
activity. No need to create a new task as the properties of both the tasks will be same.
Write the above code in business object program. Above we are declaring a variable „Status‟ to accept
approve/reject i.e. A or R value. Next get the value of „Status‟ [container element declared in task]. This will
contain the value that will be obtained from „ContainerOperation‟ step from the workflow container element
„Status‟ [as we have done binding for task container and workflow container].
[In the command, “SWC_GET_ELEMENT CONTAINER „STATUS‟ STATUS”, container is the container for
the element, first „status‟ is the element name and second status is the field/variable that you have declared
in the method.]
It could be seen that in the method, we are calling F.M „ZPO _UPDATE_TABLE‟. It will have the following
code in it:
b. Select this workitem and click on execute button next to refresh button on right hand side or just
double click „Display new PO‟. It will take you to the PO display screen.
c. When you come out of this transaction by clicking on any of these buttons, it will call next screen
for PO approval or rejection.
d. When you select „Approve‟ it will update database table with status as „A‟ and if you „Reject‟
then status will be „R‟. In this case, I have approved the PO.
Check the table ZAPP_REJ, to see if the values are reflected correctly in the table.
Transaction Description
Code
ME21N/ME21 PO Create
ME22N/ME22 PO Change
ME23N/ME23 PO Display
Related Content
https://wiki.sdn.sap.com/wiki/display/ABAP/SAP+Business+Workflow
https://wiki.sdn.sap.com/wiki/display/ABAP/SAP+Workflow+EVENTS
For more information, visit the Business Process Modeling homepage.