Skip to Content

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

  1. Trigger Workflow FM – SAP_WAPI_CREATE_EVENT

CALL FUNCTION ‘SAP_WAPI_CREATE_EVENT’
EXPORTING
object_type     = ‘XXXX’
object_key      = lv_objkey
event           = ‘RELEASED’
IMPORTING
return_code     = lv_ret_code
TABLES
input_container = lt_container.

Mandatory parameters has to be passed via container

 

  1. Complete Workitem FM – SAP_WAPI_WORKITEM_COMPLETE

CALL FUNCTION ‘SAP_WAPI_WORKITEM_COMPLETE’
EXPORTING
workitem_id      = lv_wi_id
IMPORTING
return_code      = lv_ret_code
TABLES
simple_container = lt_container.

 

  1. Get All Workflow instances – SAP_WAPI_WORKITEMS_TO_OBJECT

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).

 

  1. Read Workitem container – SAP_WAPI_READ_CONTAINER

CALL FUNCTION ‘SAP_WAPI_READ_CONTAINER’
EXPORTING
workitem_id      = lv_wi_id
language         = sy-langu
TABLES
simple_container = lt_container.

 

  1. Read Workitem header – SWW_WI_HEADER_READ

CALL FUNCTION ‘SWW_WI_HEADER_READ’
EXPORTING
wi_id     = wi_id
IMPORTING
wi_header = ls_head.

 

  1. Check function module – SWE_TEMPLATE_CHECK_FB

 

  1. 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.

 

  1. 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

SWLO – Display work items for workflow object

SWI2_FREQ –

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        – swc_get_element container ‘WI_ID’ lv_id.

SWC_SET_ELEMENT         – 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

  1. 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.

 

  1. 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.

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Christopher Solomon

    “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).

     

    (0) 
  2. Hermann Ebert

    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:

    • Rename it to “Workflow: Function Modules, Transactions, Hints”
    • Also add: What workflow are you talking about? I assume it’s the SAP Business Workflow – add this to the title as well
    • Restructure the different parts using tables and more information
    • Alternatively split up the blog entry and make it a 3-series: How to implement a workflow in process xxx
      • Part 1: Process description & setup
      • Part 2: Implementation
      • Part 3: Troubleshooting

    KR,
    Hermann

    (0) 

Leave a Reply