Hello SAPians,
Below are some handy function modules (along with sample code), transactions, programs & macros used in SAP Business Workflows. Also some important points to remember which I put together from my experience.
So here we go!!!
Function Modules
- Trigger Workflow FM – SAP_WAPI_CREATE_EVENT
What we need?
- Business Object ( Eg. BUS2012 for Purchase Order Workflow)
- Object Key (Eg. Purchase Order Number)
- Event (Event to be triggered. Eg. RELEASED)
- Input Container value (Optional, required only if you want to pass some mandatory value. Eg. Release Code in PO)
CALL FUNCTION ‘SAP_WAPI_CREATE_EVENT’
EXPORTING
object_type = ‘BUS2012’
object_key = v_ebeln
event = ‘RELEASED’
IMPORTING
return_code = lv_ret_code
TABLES
input_container = lt_container.
Note: Mandatory parameters has to be passed via container
- Complete Workitem FM – SAP_WAPI_WORKITEM_COMPLETE
What we need?
- WorkItem ID ( WorkItem ID of the decision step)
- Container Value (To pass any value from program to workflow container)
CALL FUNCTION ‘SAP_WAPI_WORKITEM_COMPLETE’
EXPORTING
workitem_id = lv_wi_id
IMPORTING
return_code = lv_ret_code
TABLES
simple_container = lt_container.
- Get All Workflow instances – SAP_WAPI_WORKITEMS_TO_OBJECT
What we need?
- Business Object ( Eg. BUS2012 for Travel Request Workflow)
- Object Key (It should be unique for each scenario. Eg. Travel Request Number)
- If we pass the task number, we can get filtered information
CALL FUNCTION ‘SAP_WAPI_WORKITEMS_TO_OBJECT’
EXPORTING
objtype = ‘BUS2089’
objkey = lv_tripno
top_level_items = ‘ ‘
selection_status_variant = 0004
text = ‘X’
language = sy-langu
determine_task_filter = ‘X’
TABLES
task_filter = task
worklist = worklist.
Note: To get Workitem completion time, use table SWWLOGHIST by passing Workitem ID and METHOD (SWW_WI_STATUS_TO_COMPLETED).
- Read Workitem container – SAP_WAPI_READ_CONTAINER
What we need?
- Workitem ID of the intance required
CALL FUNCTION ‘SAP_WAPI_READ_CONTAINER’
EXPORTING
workitem_id = lv_wi_id
language = sy-langu
TABLES
simple_container = lt_container.
- Read Workitem header – SWW_WI_HEADER_READ
CALL FUNCTION ‘SWW_WI_HEADER_READ’
EXPORTING
wi_id = wi_id
IMPORTING
wi_header = ls_head.
- Check function module – SWE_TEMPLATE_CHECK_FB
- This is a template which can be copied to a custom function module, to check the start condition of Workflow
- This FM can be configured in Transaction SWE2
“” IMPORTING
*” VALUE(OBJTYPE) LIKE SWETYPECOU-OBJTYPE
*” VALUE(OBJKEY) LIKE SWEINSTCOU-OBJKEY
*” VALUE(EVENT) LIKE SWETYPECOU-EVENT
*” VALUE(RECTYPE) LIKE SWETYPECOU-RECTYPE
*” TABLES
*” EVENT_CONTAINER STRUCTURE SWCONT
*” EXCEPTIONS
*” ANY_EXCEPTION
- Get User Inbox – RH_LOCAL_INBOX_GET
CALL FUNCTION ‘RH_LOCAL_INBOX_GET’
EXPORTING
user_id = lv_user_id
user_langu = sy-langu
TABLES
wi_list = lt_workitem
task_filter = lt_task_filter
EXCEPTIONS
user_cannot_get_wi = 1
OTHERS = 2.
- Start Workflow without Event Linkage & BO – SAP_WAPI_START_WORKFLOW
CALL FUNCTION ‘SAP_WAPI_START_WORKFLOW’
EXPORTING
task = lv_workflow
do_commit = ‘X’
user = sy-uname
IMPORTING
return_code = lv_rc
workitem_id = lv_wf_id
TABLES
message_struct = lt_message_tab.
Important T-Codes
SWU3 – Workflow Customizing
SWDD, PFTC, PFAC – Workflow/Task Builder
SWEC, SWE2 – Event & event linkage
SWEINST – Instance Linkage
SWEQADM – Event Queue Administration (Make sure below dropdown (or 3 Do not change linkage) is selected)
SWDM – Workflow Explorer
SWPR – Restart Workflow after Error
SWPC – Restart Workflow after System Crash
SWWL, SWWL_TOPLEVEL – Mass Delete Workitem (DO NOT USE SWWL IN PRODUCTION SYSTEM)
SWELS, SWEL – Trace Events
SWUE – Trigger Event
SWI5 – User Inbox
SWU_OBUF – Buffer Synchronization
SWF_GMP – Administrator Overview of workflows
SWU7 – Workflow Consistency Check
SWO1 – Business Object Builder
SWLO – Display work items for workflow object
SWI2_FREQ – Workitem Analysis (Workflow instances can be filtered based on task)
OOCU_RESP – Maintain rule with responsibilities
SWIA – Workflow processing as admin (Forward Workitem, complete manually, logically delete)
SWNADMIN – Extended Notification
Program (RSWUWFML2) – Send mail notification for Workitem
Program (RMPS_SET_SUBSTITUTE) – Substitution of Workitem agent (Admin)
SWFVISU – Task Visualization (For Webdynpro /BSP Approval Application)
Workitem ID will be available in Event Handler method (HANDLEDEFAULT) of the WDA Application Window.
Sample Code Below
DATA: loc_parameter TYPE ihttpnvp,
loc_line_parameter TYPE tihttpnvp.
wdevent->get_data(
EXPORTING
name = if_wd_application=>all_url_parameters
IMPORTING
value = loc_line_parameter ).
READ TABLE loc_line_parameter INTO loc_parameter WITH KEY name = ‘WI_ID’.
Frequently used macros in BO
SWC_GET_ELEMENT – Eg.: swc_get_element container ‘WI_ID’ lv_id.
SWC_SET_ELEMENT – Eg.: swc_set_element container ‘LOOP_COUNT’ lv_count.
SWC_GET_TABLE –
SWC_SET_TABLE –
SWC_CREATE_OBJECT – Instantiate BO – swc_create_object lo_dms_doc ‘ZDMS_DOC’ lv_dms_key.
Remember
- Maintain agent assignment – If you select attribute as ‘General Task’, Workitem will flow to all if no actual agent is found. So make sure you assign possible agents by not selecting General task. But remember, a Responsible agent can only process a work item if he is a possible agent and if he is not an excluded agent.
- Refresh Organizational Environment in SBWP / run transaction SWU_OBUF if new agents are assigned to Workflows
- Capture Event Linkages in customizing TRs
- Always create new version when changing the existing workflow template
- Check SM58 for WF-BATCH. Since all workflow tasks run in tRFCs then a crash will display an error there if the SWI1 error is not enough. (ST22 serves the purpose, but errors are stored only for 1 month or so based on basis setup)
- In SM59, test the logical connection WORKFLOW_LOCAL_<client> to see if it can connect. This is the RFC destination that the workflow uses to submit tasks
- Use SAP_WAPI*s instead of internal function modules (and tables)
- Consider all possible terminating events – ‘Approved’, ‘Withdrawn’, ‘Changed’, ‘Deleted’ etc.
- Set Workitem deadlines based on the factory calendar
Some Frequent Issues
- WF: Transported workflow template does not appear in the target system.
Reason: Changed version of the workflow is not generated properly in target system.
Solution: Run the Function Module SWD_WFD_REPLICATE_FROM_9999 in the target system by giving the import parameter as Workflow Template number.
- WF: New version doesn’t get picked during run time in the target system after transport.
Reason: The new version is not activated in the target system.
Solution: Activate the new version of the template using the program RSWDACTIVATE.
"a handy GUIDE"?!?!? There was not GUIDE to it....just looks like a info dump. Would have been nice if you organized it better, explained what items are used for and "how" (like your functions dump), etc. This is of little use to anyone (new to WF or not).
Hi Christopher,
Thanks for your feedback. Being my first post, there is always room for improvement. I will be updating the blog to make it more useful based on your suggestions.
Thanks,
Anas
First off: Thanks Anas for the effort of putting all of this together / online!
Regarding your post: I agree with Christopher. It's a lot of information and definitely useful, if used in the right context. My issue is: what is the context? 😉
Therefore my proposal:
KR,
Hermann
Hi Hermann,
Thanks for your feedback. Being my first post, there is always room for improvement.
I will be updating the blog to make it more useful based on your suggestions.
I have changed the title already (Thanks!).
Thanks,
Anas
Anas ,
You helped me alot in creating my first complex workflow.
Thank you so much
Thanks for sharing the useful information, it helps a lot..