Extending SAP Workflow Routing

Overview

The below example shows how the above integration with SAP workflow and UWL can be extended to use Rule based assignment in the SAP Workflow.

In this example we will be extending the containers in the BOR object and SAP Workflow to pass a number of additional parameters, these will be

- Form Status
- Form Type
- An Object Type
- An Object ID

These will then be passed to a newly created Rule that will call a FM to work out the assignment of the SAP Workflow Task.

Extending BOR Object

Go to Transaction SWO1 (O not zero)

And Select to Change BO ZFLMFPE

Extend the Events of the Object and Highlight the Event FORM_SUBMITTED

Select the Parameters Tab and now create the following New Parameters (when asked if you want to create with ABAP Dictionary Field Proposals Select No)

- FTYPE (Object Dictionary Type /FLM/FPE FTYPE)
- FSTATUS (Object Dictionary Type /FLM/FPE FSTATUS)
- OTYPE (Object Dictionary Type SWHACTOR OTYPE)
- OBJID (Object Dictionary Type SWHACTOR OBJID)

When Completed Click Save and Back

Now Generate the BO.
 

Adding Container Elements to Start Event on Workflow

Got to Transaction SWDD and open up the Workflow you defined above.

In the Workflow Container create the following new Elements

- FTYPE (Object Dictionary Type /FLM/FPE FTYPE)
- FSTATUS (Object Dictionary Type /FLM/FPE FSTATUS)
- OTYPE (Object Dictionary Type SWHACTOR OTYPE)
- OBJID (Object Dictionary Type SWHACTOR OBJID)

This should now look like this



From the Menu go to the Basic Data (Goto > Basic Data)

Go to the Start Event and click the Bindings Tab

Now extend the Bindings as shown below, adding FTYPE, FSTATUS, OTYPE and OBJID.



When Finished Click Execute then save the Workflow, and click Back.
 

Adding Container Elements to Standard Task

Now back in the Workflow Diagram click on the ZFLMSTDTASK Activity

Go into the Standard Task and extend the Container with the following elements

- FTYPE (Object Dictionary Type /FLM/FPE FTYPE)
- FSTATUS (Object Dictionary Type /FLM/FPE FSTATUS)
- OTYPE (Object Dictionary Type SWHACTOR OTYPE)
- OBJID (Object Dictionary Type SWHACTOR OBJID)

The Task should now look like this



Now go Back to the Workflow Builder and click the Bindings Tab under the Task



And set the Bindings to the below, adding FTYPE, FSTATUS, OTYPE and OBJID.



Click Execute and Save the Workflow.
 

Creating the Rule and Binding to Workflow.

Leaving the workflow open start a new session and go to transaction SE37

Create a new FM called Z_FLM_GET_USER with the below parameters

*"*"Local Interface:
*"     TABLES
*"          ACTOR_TAB STRUCTURE SWHACTOR
*"         AC_CONTAINER STRUCTURE SWCONT
*"     EXCEPTIONS
*"         NOBODY_FOUND

In the example we using the System Users USER1, USER2 and USER3 change these names as appropriate for your implementation. The same goes for FSTATUS, we sing the built in one S for Submitted. This will on Submit assign a new Workflow task to passed in user and also USER3 on all other statuses it will just assign the task to the passed in user.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
INCLUDE <cntain>.
CLEAR actor_tab. REFRESH actor_tab.

DATA: iv_fstatus TYPE /flm/fpe-fstatus,
            iv_otype TYPE swhactor-otype,
            iv_objid TYPE swhactor-objid.

DATA: object TYPE swc_object.

swc_get_element ac_container 'FSTATUS' iv_fstatus.

IF iv_fstatus = 'S'.
*
        swc_get_element ac_container 'OTYPE' iv_otype.
        swc_get_element ac_container 'OBJID' iv_objid.
*
        actor_tab-otype = iv_otype.
        actor_tab-objid = iv_objid.
        APPEND actor_tab.
*
        actor_tab-otype = 'US'.
        actor_tab-objid = 'USER3'.
        APPEND actor_tab.
*
ELSE.
*
        swc_get_element ac_container 'OTYPE' iv_otype.
        swc_get_element ac_container 'OBJID' iv_objid.
*
        actor_tab-otype = iv_otype.
        actor_tab-objid = iv_objid.
        APPEND actor_tab.
*
ENDIF.

Now Activate the FM.

No go to transaction PFAC and Create a new Rule and define this to execute the above FM Z_FLM_GET_USER as shown below



Now go to the Container and add the following elements.

- FTYPE (Object Dictionary Type /FLM/FPE FTYPE)
- FSTATUS (Object Dictionary Type /FLM/FPE FSTATUS)
- OTYPE (Object Dictionary Type SWHACTOR OTYPE)
- OBJID (Object Dictionary Type SWHACTOR OBJID)



Save the Rule and close the session

Back in your Workflow Select in the Agent Tab Rule and then selected the newly created Rule, as shown below



Click the Bindings Tab here and then set them as below, adding FTYPE, FSTATUS, OTYPE and OBJID.



Click Execute on the Bindings Panel.

Now click the Green Tick in the Activity Window and you be taken back to the Workflow Diagram.

Save and Activate your Workflow.

Adding Elements to BOR in FLM Routing

Navigate to the FLM Routing User Exit for your FLM Form.

In the code before you call the FORM_SUBMITTED event on the BO ZFLMFPE you need to set-up the container elements and then pass into the calling Function as shown below

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
CLEAR l_swr_cont.
l_swr_cont-element = 'OBJID'.
l_swr_cont-value = w_new_user.
APPEND l_swr_cont TO t_swr_cont.
*
CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
    EXPORTING
        object_type = 'ZFLMFPEV3'
          object_key = l_key
        event = 'FORM_SUBMITTED'
        user = 'USER3'
    TABLES
    input_container = t_swr_cont.

In our example we use the below code.

If the routing is set as S then we assign to user USER2 otherwise we set this to USER1. At this stage we also set the new FLM user as the same.

Then before we call the event to trigger the workflow we set-up our container elements for FTYPE, FTATUS, OTYPE and OBJID

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
    DATA w_new_user TYPE swhactor-objid.
    *
    IF im_status = 'S'.
        w_new_user = 'USER2'.
        ex_owner = 'USER2'.
        ex_status = 'S'.
    ELSEIF im_status = 'X'.
        w_new_user = 'USER1'.
        ex_owner = 'USER1'.
        ex_status = 'X'.
    ENDIF.
    *
    DATA: l_key TYPE swo_typeid,
                l_key1 TYPE char24,
                l_key2 TYPE sibfboriid.

    * Build the Key

    CONCATENATE im_instance-ccode im_instance-ftype im_instance-flang im_instance-fver im_instance-id '*' INTO lv_key RESPECTING BLANKS.

    DATA: r_key TYPE RANGE OF sibfboriid,
                r_key_line LIKE LINE OF r_key.

    r_key_line-sign = 'I'.
    r_key_line-option = 'CP'.
    r_key_line-low = l_key.
    APPEND r_key_line TO r_key.

    DATA: t_objkey TYPE TABLE OF swo_typeid,
                l_objkey TYPE swo_typeid,
                l_swr_cont TYPE swr_cont,
                t_swr_cont TYPE TABLE OF swr_cont.

    * Now Make sure all old items have been deleted
    SELECT objkey FROM swfdevinst INTO TABLE t_objkey WHERE objkey IN r_key.

    DELETE ADJACENT DUPLICATES FROM t_objkey.

    LOOP AT t_objkey INTO l_objkey.

        CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
            EXPORTING
                object_type = 'ZFLMFPE'
                object_key = l_objkey
                event = 'FORM_DELETED'
                user = 'USER3'.
    *
    ENDLOOP.

    * Create new workitem.
    * Need to use latest variant here - as in im_instance.

    CONCATENATE im_instance-ccode im_instance-ftype im_instance-flang im_instance-fver im_instance-id im_instance-id_var INTO lv_key RESPECTING BLANKS.

    *
    * Make sure if we are at final status we do not create a new workflow task
    *
    IF im_status NE 'R'.
    *
    * Now create the parameters to pass into the BOR Event
    *
        CLEAR l_swr_cont.

        l_swr_cont-element = 'FTYPE'.
        l_swr_cont-value = 'UWL2'.
        APPEND l_swr_cont TO t_swr_cont.
    *
        CLEAR l_swr_cont.
        l_swr_cont-element = 'FSTATUS'.
        l_swr_cont-value = im_status.
        APPEND l_swr_cont TO t_swr_cont.
    *
        CLEAR l_swr_cont.
        l_swr_cont-element = 'OTYPE'.
        l_swr_cont-value = 'US'.
        APPEND l_swr_cont TO t_swr_cont.
    *
        CLEAR l_swr_cont.
        l_swr_cont-element = 'OBJID'.
        l_swr_cont-value = w_new_user.
        APPEND l_swr_cont TO t_swr_cont.
    *
        CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
            EXPORTING
                object_type = 'ZFLMFPE'
                object_key = l_key
                event = 'FORM_SUBMITTED'
                user = 'USER3'
            TABLES
                input_container = t_swr_cont.

    ENDIF.