cancel
Showing results for 
Search instead for 
Did you mean: 

Flexi Workflow : Reject Work Item Using FM: SAP_WAPI_WORKITEM_COMPLETE

dp_prasad
Participant
0 Kudos

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.

dp_prasad
Participant
0 Kudos

Issue Resolved.We can use FM SAP_WAPI_WORKITEM_COMPLETE for both Approve and Reject Actions. But need to pass the container with Decision elements.

Thank you .

Accepted Solutions (0)

Answers (2)

Answers (2)

laszlo_haladin
Active Participant
0 Kudos

Hi,

There is a standard mass approval option in my inbox with standard delivered /IWWRK/ES_WF_WI_BEFORE_UPD_IB BADI implementations:

MM_PUR_PO_APPROVE_ACTIONSMM_PUR_PO_APPROVE_ACTIONSS4COREMM-

SAP_WAPI_WORKITEM_COMPLETE will always complete the related WI, and the later steps are depending on the used workflow logic.

Use BadI Implementation MM_PUR_PO_APPROVE_ACTIONS method - /IWWRK/IF_WF_WI_BEFORE_UPD_IB~BEFORE_UPDATE example as a reference:

CALL METHOD me->set_decision_reject
EXPORTING
iv_po_number = ls_object-instid(10)
iv_release_code = lv_release_code.

SET_DECISION_REJECT method contains the rejection logic for standard MM workflows.

Best Regards
Laszlo

dp_prasad
Participant
0 Kudos

Thank you Laszlo.I have gone through the BADI Implementation class. Based on RELEASECODE Element from Container, they are calling method set_decision_reject. However , The container for my Work Item doesn't have RELEASECODE element.

What release code shall we use there?

Thank you

Code from: /IWWRK/IF_WF_WI_BEFORE_UPD_IB~BEFORE_UPDATE

  "Read the workflow's container data
    CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'
      EXPORTING
        workitem_id      = is_wi_details-wi_id
      IMPORTING
        return_code      = lv_retcode
      TABLES
        simple_container = lt_container.


    " Check which release code is necessary for the current approval step
    READ TABLE lt_container INTO ls_container WITH KEY element = 'RELEASECODE'.
    IF sy-subrc EQ 0.
      lv_release_code = ls_container-value.
    ENDIF.

    SET UPDATE TASK LOCAL.

* now we react on the decision the user has taken in the MyInbox
* 0001 should be approve, 0002 reject
    CASE iv_decision_key.

   WHEN 0002. "Rejected

        TRY.
            CALL METHOD me->set_decision_reject
              EXPORTING
                iv_po_number    = ls_object-instid(10)
                iv_release_code = lv_release_code.

0 Kudos

In Fiori My Inbox app SAP has provided option for Mass Approval also. That seems to be matching with your requirement.

dp_prasad
Participant
0 Kudos

Before Mass Approval, user wanted to see a report with Certain z-fields that are there in pur Purchase Order Custom Screen.But Fiori Inbox Mass Approval only have 2-3 standard fields. So we wanted to write a program to meet that requirement