Skip to Content
0
Feb 03, 2021 at 02:49 PM

Flexi Workflow : Reject Work Item Using FM: SAP_WAPI_WORKITEM_COMPLETE

711 Views Last edit Feb 03, 2021 at 02:54 PM 2 rev

Hi

We have a configured the Flexi Workflow with 2 Steps( 2 levels of approval) for Purchase Order. Users wanted to Mass Approval or Rejection using an ABAP program instead of approval/rejection individually from Fiori Inbox.

So we have created a program using FM : SAP_WAPI_WORKITEM_COMPLETE to Approve or Reject Based on Users Decision. Approval is working fine with our code. But Rejection of Work Item is not working even though we have passed the Container Information with Element: _WI_RESULT = 'R'.The Work Item always getting Approved irrespective of the wi_result value.

we have also tried SAP_WAPI_DECISION_COMPLETE but not working.

Is the Container Element: _WI_RESULT for WI Decision(Approve/Reject) correct? Please advise on how to Reject Work Item using BAPI or FM?

We are on SAP S/4HANA 1909.

My Code is as below:

1. For SAP_WAPI_DECISION_COMPLETE., i have passed the Wi_id ( wi_type W) along with the Decision as below:

*    call function 'SAP_WAPI_DECISION_COMPLETE'
*      exporting
*        workitem_id    = lv_wid  " Wi id of type W
*        language       = sy-langu
*        user           = sy-uname       " Approver ID
*        decision_key   = lv_decision     " 0002
*        do_commit      = 'X'
*      importing
*        return_code    = lv_returncode
*        new_status     = lv_wf_status
*      tables
*        message_struct = it_returns.

But it failed(SAP_WAPI_DECISION_COMPLETE) with Error Message : Work item 000001000171 is not a user decision


2. By using Function Module: SAP_WAPI_WORKITEM_COMPLETE ( Approval is working fine but Rejection of Work Item is not Working).

* Read Container
    refresh lt_cont.
    call function 'SAP_WAPI_READ_CONTAINER'
      exporting
        workitem_id      = p_out-wi_id
      tables
        simple_container = lt_cont.


* Add the Approval or Rejection decision to container element
    clear     ls_cont.
*    ls_cont-element = 'STATUS'.
    ls_cont-element = '_WI_RESULT'.
    if function = 'RELEASE'.
      lv_decision = gc_approve.
      ls_cont-value = 'A'.
    elseif function = 'REJECT'.
      lv_decision = gc_REJECT.
      ls_cont-value = 'R'.
    endif.
    append ls_cont to lt_cont.


*Tried to write the container before competing work item But not working


*    call function 'SAP_WAPI_WRITE_CONTAINER'
*      exporting
*        workitem_id      = p_out-wi_id
*        do_commit        = 'X'
*      importing
*        return_code      = lv_ret_cont
*      tables
*        simple_container = lt_cont.


* Complete Work item by passing decision in Container
    call function 'SAP_WAPI_WORKITEM_COMPLETE'
      exporting
        workitem_id      = p_out-wi_id
        actual_agent     = sy-uname
        language         = sy-langu
*       SET_OBSOLET      = ' '
       do_commit        = 'X'
*       DO_CALLBACK_IN_BACKGROUND       = 'X'
*       IFS_XML_CONTAINER               =
*       CHECK_INBOX_RESTRICTION         = ' '
      importing
        return_code      = lv_returncode
*        new_status       = lv_wf_status
      tables
        simple_container = lt_cont
*       MESSAGE_LINES    =
        message_struct   = it_returns.

Using Above Code, The work item is always getting Approved(completed status) even though we " Reject" the Work item.

In 2nd method, i have tried passing " Decision_key' etc Container Elements but not working( No Error though, it will always approve Work item).

Is there anyway to pass the Rejection status to Work Item.? Or are there any other Function modules are methods to achieve Rejection of Work Item?

Thank you in advance.

Attachments

wf-header.png (27.4 kB)