Skip to Content

This is the fifth instalment in the ambitious 73-part series ‘The Overworked Workflow Administrator’. In this episode, we contradict what we said earlier, by implementing a custom workflow report. But we think this one fills a much-needed gap.

 

 

Problem:

SWI1 can be used to list workitems in READY status (i.e. those that no one has processed yet), but it doesn’t tell you whose inboxes they are in.

 

All you get is the alarming text ‘No Agent Available’.

 

/wp-content/uploads/2013/09/1_278902.png

 

Sure, you can drill down into each workitem separately and press the ‘Agents’ button, but our support staff would rather see all the agents listed in one report.

 

Something like this:

 

/wp-content/uploads/2013/09/2_278903.png

 

 

Solution:

In this document, we create a report that has the same look and feel as SWI1, but this report also lists – for all dialog items in status ‘READY’ – the full list of users that have this item in their inbox.

 

Happily, all we need to do is copy a standard SAP program and make some minor adjustments.

 

Step 1. Copy the SAP report

SE38: Copy program RSWIWILS to ZRSWIWILS.

 

/wp-content/uploads/2013/09/3_278905.png

 

Activate the program. Then, in the attributes, change the title of the program to ‘Agents of Workitems’.

 

(If you see a message about “Different original and logon languages” then click on the “Change orig.language” button and continue to agree with whatever SAP asks you until you get to the “ABAP: Program Attributes ZRSWIWILS Change” window, where you can change the Title.)

 

 

Step 2. Create a new report transaction

SE93: Create a ‘report transaction’ ZWF_AGENTS and link it to program ZRSWIWILS.

 

/wp-content/uploads/2013/09/4_278906.png

/wp-content/uploads/2013/09/5_278908.png

 

Step 3. Edit the program

SE38: Make some simple code changes to ZRSWIWILS – see attached document.

(We simply add a call to SAP_WAPI_GET_WI_AGENTS to determine all current agents)

2017 UPDATE: The attachment has been lost, but I have added an explanation of the code changes at the bottom of this post.

 

Step 4.  Activate the program

(I told you these steps were simple )

 

Step 5.  Test the program

 

You can test it by running transaction ZWF_AGENTS. The selection screen is the one we are all familiar with:

/wp-content/uploads/2013/09/6_278915.png

But now, in the output listing, there are multiple lines for dialog workitems  that no one has processed yet.

/wp-content/uploads/2013/09/7_278916.png

Scroll along and you can see all the agents who currently have this workitem in their inbox.

 

/wp-content/uploads/2013/09/8_278917.png

 

cheers

Paul Bakker

 

PS If you are just getting into workflows, you may also like to read some of the previous instalments:

 

http://scn.sap.com/community/bpm/business-workflow/blog/2013/02/07/the-top-10-mistakes-made-by-workflow-beginners

http://scn.sap.com/community/bpm/business-workflow/blog/2013/02/25/more-common-mistakes-made-by-workflow-beginners

http://scn.sap.com/community/bpm/business-workflow/blog/2013/01/14/how-to-logically-delete-workflows

http://scn.sap.com/community/bpm/business-workflow/blog/2013/01/21/sap-workflow-as-abap-dont-program-it-workflow-it

 

2017 EDIT: Summary of code changes.

Steps:

SE38: Copy program RSWIWILS to ZRSWIWILS.
Copy all components, except Includes.
In the attributes, change the title to 'Agents of Workitems'.

SE93: Create transaction ZWF_AGENTS as a 'Report Transaction' (program and selection screen).
Transaction text = 'Agents of Workitems'
Program = ZRSWIWILS
Selection Screen = 1000
Click 'SAPGUI for WIndows'.

SE38: Make the following simple code changes to ZRSWIWILS 

(1) At the beginning of the program

REPORT zrswiwils MESSAGE-ID swf_rep_base.
*------------------------------------------------------------------
* This is a copy of program RSWIWILS, which underlies SWIA, 
* SWI1_USER etc.
*
* We have adapted it to provide an Agents report: list all current
* agents for a workitem. This reported is executed via transaction 
* ZWF_AGENTS.
*
* Changes are marked with the text 'Agents'
*------------------------------------------------------------------

(2)  about line 25

* DATA: g_report_name TYPE sy-repid VALUE 'RSWIWILS'.
DATA: g_report_name TYPE sy-repid VALUE 'ZRSWIWILS'.   "Agents


(3)  about line 56 - set the default values to only pick up 'READY' dialog workitems

SELECT-OPTIONS:
    type   FOR swfawrkitm-wi_type default 'W',       "Agents - Dialog workitem
    state  FOR swfawrkitm-wi_stat default 'READY',   "Agents - Ready 


(4) about line 109 - set the title of the program
  ELSEIF tcode = 'SWIA_BATCH'.    "Context
    SET TITLEBAR '1006'.          "Context
  ELSEIF tcode = 'ZWF_AGENTS'.    "Agents
    SET TITLEBAR '1099'.          "Agents of Workitems
  ENDIF.
You also need to create the text element 1099 (double-click on it) and give it the value 'Agents of Workitems'. 
If you are asked to change the original language of the program, do so.


(5) about line 259 (after the call to 'get_workitem_header')

*-- begin Agents
* If the (dialog) workitem does not have an agent, then we want to
* list all current users who have this workitem in their inbox.
  if sy-tcode = 'ZWF_AGENTS'.
    PERFORM get_workitem_agents CHANGING g_wiheader.
  endif.
*-- end Agents

(6) At the very end of the program, add this subroutine

*-- begin Agents
*---------------------------------------------------------------*
*       FORM get_workitem_agents                                *
*---------------------------------------------------------------*
* Augment the workitem list with agent information:
* if a DIALOG workitem is in status READY and has
* NO CURRENT AGENT, find all (responsible) agents
* who have this item in their inbox.
* Add one line to the list for each agent found.
*---------------------------------------------------------------*
*  <->  PT_WIHEADER                                             *
*---------------------------------------------------------------*
form get_workitem_agents changing pt_wiheader type swfatalvitm.

types: begin of ty_user_name,
         user type SYUNAME,
         name type AD_NAMTEXT,
       end of ty_user_name.
data: lt_user_names type sorted table of ty_user_name
                    with UNIQUE key user,
      ls_user_name type ty_user_name.

data: lt_wi_agents type SWRTWIAGENT,
      ls_wi_agents type SWR_WIAGENT,
      lt_wiheader type swfatalvitm,
      ls_wiheader type SWFAALVITM,
      lt_wi_ids type SWRTWIID,
      lv_user_id type XUBNAME,
      ls_user_address type ADDR3_VAL.

check pt_wiheader is not initial.

loop at pt_wiheader into ls_wiheader.
  clear: lt_wi_ids, lt_wi_agents.
* Dialog workitem in status READY with no agents?
  if ls_wiheader-wi_type EQ 'W' and         "dialog workitem
     ls_wiheader-WI_AAGENT is initial and   "no agents
     ls_wiheader-WI_STAT EQ 'READY'.         "ready
    append ls_wiheader-wi_id to lt_wi_ids.
* Get the current (responsible) agents, who would
* have the workitem in their inbox
    CALL FUNCTION 'SAP_WAPI_GET_WI_AGENTS'
      EXPORTING
*       LANGUAGE               = SY-LANGU
        WORKITEMS              = lt_wi_ids
*       USER                   = SY-UNAME
        WITH_SUBSTITUTES       = 'X'
      IMPORTING
*       RETURN_CODE            =
*       TIMESTAMP              =
        WI_AGENTS              = lt_wi_agents
*     TABLES
*       MESSAGE_LINES          =
*       MESSAGE_STRUCT         =
              .
* For every agent found, add a new line to the WI list
    if lt_wi_agents[] is initial.
      "just add a line with no agent
      append ls_wiheader to lt_wiheader. 
    else.
      loop at lt_wi_agents into ls_wi_agents.  
        "add a new line for each agent
        ls_wiheader-wi_aagent = ls_wi_agents-user.
* get the user name
        clear ls_user_address.
        lv_user_id = ls_wi_agents-user.
* try a local buffer first
        read table lt_user_names into ls_user_name
           with key user = lv_user_id.
        if sy-subrc = 0.
          ls_wiheader-WI_AA_NAME = ls_user_name-name.
        else.
* get the user name from the user address
          CALL FUNCTION 'SUSR_USER_ADDRESS_READ'
               EXPORTING
                    user_name              = lv_user_id
               IMPORTING
                    user_address           = ls_user_address
               EXCEPTIONS
                    user_address_not_found = 1
                    OTHERS                 = 2.
          if sy-subrc = 0.
            ls_wiheader-WI_AA_NAME = ls_user_address-name_text.
* store in a buffer table
            clear ls_user_name.
            ls_user_name-user = lv_user_id.
            ls_user_name-name = ls_user_address-name_text.
            insert ls_user_name into table lt_user_names.
          endif.
        endif.
        append ls_wiheader to lt_wiheader.
        clear ls_wiheader-wi_aagent.
      endloop.
    endif.
  else.  "if its not a dialog workitem, or already has an agent, 
         "just append it
    append ls_wiheader to lt_wiheader.
  endif.
endloop.

*Replace the original table with the extended table
if lt_wiheader[] is not initial.
  pt_wiheader[] = lt_wiheader[].
endif.
endform. "get_workitem_agents
*-- end Agents
To report this post you need to login first.

19 Comments

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

  1. Susan Keohan

    How did I not find this earlier?  Great job, Paul.  I have a new mission for the day – to implement this!

    I also wish SAP would deliver a report on workitems executed by substitutes.   What a pain that is.

    Cheers,
    Sue

    (0) 
    1. Paul Bakker Post author

      Thanks for the kind words Sue!

      So what is your requirement – to report on any substitute agents that have executed a dialog workitem? I’ve never heard that one before…?

      cheers

      Paul

      (0) 
      1. Paul Bakker Post author

        Arghadip,

        I’m not sure what you mean.

        A workitem can only be ‘assigned’ to one person (ie reserved by that person), or assigned to no-one (because no-one has grabbed it yet; it may appear in multiple inboxes).

        The report above handles both cases.

        Or have I misunderstood?

        cheers

        Paul

        (0) 
        1. Arghadip Kar

          Yaa you are right I missed some points on the arcticle.

          Related with susbstitution I think now the SAp Inbox has the Substitute for field that gets populated in the susbtituted SAP Inbox. We can build some logic like Paul build on the same way playing with table HRUS_D2

          Thanks

          Arghadip

          (0) 
          1. Paul Bakker Post author

            Hi,

            If you are concerned about substitutes, the report already caters for them.

                  CALL FUNCTION ‘SAP_WAPI_GET_WI_AGENTS’
                  EXPORTING
                    WORKITEMS              = lt_wi_ids
                    WITH_SUBSTITUTES       = ‘X’                                <——–

            cheers

            Paul

            (0) 
    1. Paul Bakker Post author

      The document is lost forever (thank you very much, SCN migration :-), but I have now attached a note to the bottom of the post that explains the required code changes.

      (1) 

Leave a Reply