SAP Workflow. Dialog Tasks for the User and Their Substitute

In this note, I’d like to present, if I may, a solution map for scenarios where you might be fortunate enough to search for dialog tasks awaiting approval by a user or their substitute in an ABAP program, Web Dynpro, or Fiori application.

Initial Context

You have an ABAP program / Web Dynpro / Fiori application through which you need to display information about all dialog tasks available to a user for approval at a certain point in time (or over a defined period). Naturally, substitution rules must also be taken into account.

See also: Workflow. Использование правил замещения для обработчиков задач

Regardless of the implementation approach, the user’s worklist on the backend can be generated using the function module SAP_WAPI_CREATE_WORKLIST.

Example Use of SAP_WAPI_CREATE_WORKLIST

To demonstrate, I will use the following ABAP program:

REPORT zwf_test.
 
DATA: et_workflist           TYPE TABLE OF swr_wihdr,
      et_im_task_filter      TYPE  swrttask,
      em_im_status_filter    TYPE swrtstatus,
      et_worklist_attributes TYPE TABLE OF swr_wiaddattr.
 
 
APPEND VALUE #( wi_rh_task = 'TS96000355' ) TO et_im_task_filter.
 
CLEAR: et_workflist, et_worklist_attributes.
 
CALL FUNCTION 'SAP_WAPI_CREATE_WORKLIST'
  EXPORTING
    user                 = sy-uname
    language             = sy-langu
    translate_wi_text    = abap_false
    passive_substitution = abap_true
    im_task_filter       = et_im_task_filter
*    im_status_filter     = em_im_status_filter
  TABLES
    worklist             = et_workflist
    worklist_attributes  = et_worklist_attributes.
 
IF sy-subrc EQ 0.
 
ENDIF.

The workflow consists of a single dialog task, and its processors are specified in a multi-line container USERS. The number of entries in this container determines how many instances of the dialog task are created in the workflow.

Starting the Workflow for a Single User

The video clip below shows the sequence where a workflow is started for a single user. After the workflow is triggered, I run the ABAP program to check the output of the function module SAP_WAPI_CREATE_WORKLIST.

0:00
/0:39

The resulting internal table et_workflist contains one entry for the dialog task present in the user's worklist.

Activating a Substitute and Re-running the Workflow/Program

Let’s complicate the scenario by adding a substitute for the task processor, as defined in table HRUS_D2 with an active substitution rule.

Re-running the Workflow

The video clip below shows the sequence where I use transaction SBWP for each of the users designated as task processors. It demonstrates that the workflow task is available to both users for selection and processing.

See also: Business Workplace: Workflow Functions
0:00
/1:03

Problem Description

As shown above, each user designated as a processor sees the dialog task. However, while user YUSER1 sees a single instance of the task, user YUSER2 sees it twice. That is, YUSER1 sees only the task assigned directly to them, while YUSER2 sees both their own and YUSER1’s task—because YUSER2 is defined as a substitute for YUSER1.

This same behavior is observable in the ABAP program by analyzing the output of SAP_WAPI_CREATE_WORKLIST.

0:00
/0:40

Such duplications may raise concerns among key business users.

Solution

For example:

REPORT zwf_test.
 
DATA: et_workflist           TYPE TABLE OF swr_wihdr,
      et_im_task_filter      TYPE  swrttask,
      em_im_status_filter    TYPE swrtstatus,
      et_worklist_attributes TYPE TABLE OF swr_wiaddattr.
 
APPEND VALUE #( wi_rh_task = 'TS96000355' ) TO et_im_task_filter.
 
CLEAR: et_workflist, et_worklist_attributes.
 
CALL FUNCTION 'SAP_WAPI_CREATE_WORKLIST'
  EXPORTING
    user                 = sy-uname
    language             = sy-langu
    translate_wi_text    = abap_false
    passive_substitution = abap_true
    im_task_filter       = et_im_task_filter
*   im_status_filter     = em_im_status_filter
  TABLES
    worklist             = et_workflist
    worklist_attributes  = et_worklist_attributes.
 
SELECT SINGLE us_name FROM hrus_d2 INTO @DATA(lv_user) WHERE rep_name = @sy-uname AND endda >= @sy-datum AND active = @abap_true.
 
IF lv_user IS NOT INITIAL.
  DATA(lv_rep) = abap_true.
ENDIF.
 
IF lv_rep IS NOT INITIAL.
  DELETE ADJACENT DUPLICATES FROM et_workflist COMPARING wi_chckwi.
  WRITE:/ 'deleted' , sy-dbcnt, 'dublicates'.
ENDIF.

Checking:

0:00
/1:02

Winter will be long, but it’ll be fine. Hugs. Yours, ignatov.