Integrating Workflow Programming With Abap Objects PDF
Integrating Workflow Programming With Abap Objects PDF
Applies to:
SAP Workflow Programming with ABAP OO Objects – Interfacing Workflow with ABAP Classes and Methods
For more information, visit the ABAP homepage.
Summary
Programming inside the workflow is often needed for complex workflow development. This document
provides a description of how to write ABAP classes and methods to use in a workflow. It is a comprehensive
“step-by-step” for a template that can be used to write own classes and methods to use in workflow.
There are several ways to call ABAP OO methods from a workflow step. The two basic techniques are either
the implementation as a BOR object or the implementation as an ABAP Objects class and method. When
you create a Class that will implement the workflow interface and use it inside of a workflow task, you need
to implement an Interface IF_WORKFLOW inside your custom class. Without this implementation you will
not be able to select your ABAP OO class in a Workflow step, this is the basic communication interface
between your methods and the workflow.
We will cover two topics in this article:
Workflow with ABAP OO in Static method scenario
This article will start with an easy scenario where we have a static method. The method will be the workflow
equivalent of “Hello World” and will just say hello to us.
Workflow with ABAP OO in Instance method scenario
This article is about implementing an Instance Method in a Workflow Class. Why use an instance method?
An instance method is only valid and unique inside the workflow that implements the method. It cannot be
shared and therefore specific to the workflow
Author Bio
Holger Stumm started as a Logistics Consultant and ABAP programmer way back in 1988 on
good old mainframe R/2. Later, with R/3 , he spent six years in the US, working as a
Managament Consultant for KPMG and Deloitte in Silicon Valley, Palo Alto, CA, USA . He
worked on worldwide projects on all five continents as project lead, programmer, and consultant.
Worked for SAP in Walldorf on ecommerce and SRM. Since 2001, Holger Stumm has his own
SAP consulting company together with hisy wife in Darmstadt, Germany.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 1
Integrating Workflow Programming with ABAP Objects
Table of Contents
General ............................................................................................................................................................... 3
Static method scenario.................................................................................................................................... 3
Create ABAP Class ...................................................................................................................................................... 3
Create Workflow Task .................................................................................................................................................. 4
Workflow Design ............................................................................................................................................. 7
Workflow design........................................................................................................................................................... 7
Test Workflow ................................................................................................................................................. 8
Start testing .................................................................................................................................................................. 8
Instance method scenario 1 ............................................................................................................................ 9
Implement IF_WORKFLOW ......................................................................................................................................... 9
Implement an instance Method .................................................................................................................................. 10
Instance method scenario 2 .......................................................................................................................... 11
Create instance method ............................................................................................................................................. 11
Instance Method Implementation ............................................................................................................................... 12
Related Content ................................................................................................................................................ 18
Disclaimer and Liability Notice .......................................................................................................................... 19
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 2
Integrating Workflow Programming with ABAP Objects
General
Workflow is a broad topic and programming inside the workflow is often needed for complex workflow
development.
There are several ways to call ABAP OO methods from a Workflow Step. The two basic techniques are
either the implementation as a BOR object or the implementation as an ABAP Objects class and method.
When you create a Class that will implement the workflow interface and use it inside of a workflow task, you
need to implement an Interface IF_WORKFLOW inside your custom classs. Without this implementation you
will not be able to select your ABAP OO class in a Workflow step, this is the basic communication interface
between your methods and the workflow.
We keep it simple and use only a character export parameter. If you want, you can also use
structures or other dictionary objects.
method SAYHELLO.
DATA: l_message TYPE char32.
CONCATENATE 'Hello, ' sy-uname INTO l_message.
e_message = l_message.
endmethod.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 3
Integrating Workflow Programming with ABAP Objects
Move to Method tab and we see some methods which have been automatically inherited.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 4
Integrating Workflow Programming with ABAP Objects
3. Save your task and confirm the popup which is asking to transfer missing element.
4. After you have saved your task we should check Synchronous object method. This will also
create an exit to the workflow step.
Let´s look at the Container tab here we can see our export parameter E_MESSAGE is available in
the container.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 5
Integrating Workflow Programming with ABAP Objects
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 6
Integrating Workflow Programming with ABAP Objects
Workflow Design
In this chapter, we will create a workflow embed the ABAP Objects classes in a task
Workflow design
1. Call transaction SWDD and create new Workflow.
2. Double-click on the undefined step in the middle of the window and insert an Activity step.
4. Choose the small transfer icon on the left side of the Activity step
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 7
Integrating Workflow Programming with ABAP Objects
Test Workflow
In this chapter, we will actually test the wlow
Start testing
1. Press F8 for testing your workflow.
After you have run the workflow we can use the Workflow log to check the execution.
2. Choose Workflow Log on the next window press Shift+F9
Now we are in the technical details View, here we can drill down all step of our workflow and check
the values of the Container elements.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 8
Integrating Workflow Programming with ABAP Objects
Implement IF_WORKFLOW
1. Open each method inherited form IF_WORKFLOW and activate the empty source code.
This means you have to click in every method (even if it is empty) and activate it.
The most important methods are FIND_BY_LPOR and LPOR. If Workflow needs to instantiate an
ABAP Class, Workflow will call the FIND_BY_LPOR Method. The simplest implementation has to
return only a new instance of our ABAP Object.
2. Implement FIND_BY_LPOR
method BI_PERSISTENT~FIND_BY_LPOR.
CREATE OBJECT result TYPE Z_CL_HELLO.
endmethod.
The FIND_BY_LPOR method contains an import parameter LPOR which is passed from Workflow to
our ABAP class. This Local Persistence Object Reference (LPOR) has three parameters.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 9
Integrating Workflow Programming with ABAP Objects
Parameters
method ADDVALUES.
DATA: l_calcval type num4.
l_calcval = i_val1 + i_val2.
e_calculatedvalue = l_calcval.
endmethod.
Now we are able to call our ABAP instance method from a Workflow task. The configuration of the
Workflow Task to call an instance Method is the same like in “Static method scenario”.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 10
Integrating Workflow Programming with ABAP Objects
The difference to the previous example is the use of the method FIND_BY_LPOR, which enables
you to search the instantiated methods.
How to instantiate a Class and pass INSTID to FIND_BY_LPOR? We will create a static method which
returns an instance of our class then we can define a mapping to _WI_OBJECT_ID in workflow.
Let´s create a small scenario where we read the client table and show the text of the client. This is
really not the best way to read the client, but our intension is to illustrate how you can implement
FIND_BY_LPOR and LPOR.
At the end our workflow looks like below picture
CONSTRUCTOR Parameter
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 11
Integrating Workflow Programming with ABAP Objects
GETMTEXT Parameter
m_mandt = i_client.
m_por-INSTID = i_client.
m_por-CATID = 'CL'.
m_por-TYPEID = 'Z_CL_READ_MANDT'.
IF sy-subrc = 0.
LOOP AT i_tab INTO i_tabstr.
me->m_mtext = i_tabstr-mtext.
ENDLOOP.
ENDIF.
endmethod.
method GETMTEXT.
e_mtext = me->m_mtext.
endmethod.
method CREATE.
CREATE OBJECT e_instance type z_cl_read_mandt exporting i_id = i_clientid.
endmethod.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 12
Integrating Workflow Programming with ABAP Objects
4. Implement BI_PERSISTENT~FIND_BY_LPOR
method BI_PERSISTENT~FIND_BY_LPOR.
CREATE OBJECT result type z_cl_read_mandt exporting i_id = lpor-instid(3).
endmethod.
5. Implement LPOR
method BI_PERSISTENT~LPOR.
result = me->m_por.
endmethod.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 13
Integrating Workflow Programming with ABAP Objects
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 14
Integrating Workflow Programming with ABAP Objects
Accept the popup Window which appear when transfer the Task
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 15
Integrating Workflow Programming with ABAP Objects
10. Insert a second activity which point to the GETMTEXT Method Task
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 16
Integrating Workflow Programming with ABAP Objects
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 17
Integrating Workflow Programming with ABAP Objects
Related Content
http://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=60654596
http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/3907
https://weblogs.sdn.sap.com/pub/wlg/3948
For more information, visit the ABAP homepage.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 18
Integrating Workflow Programming with ABAP Objects
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 19