cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

PR item reject from code

Cnv88
Explorer
0 Likes
638

Helloooo!

I have implemented approval WF for BUS2009, and enabled a functionality to APPROVE/REJECT from a Link (using SICF)

Approval goes creat with BAPI_REQUISTION_RELEASE, but there is nothing similar for reject. I tried using CL_REQ_ITEM_PROXY_MM object and calling if_releasable_mm~reject  method, but nothing happens.

In addition, users that approve have no access to ME52n, so use BAPI CHANGE is not an option 😞

Any ideas or if_releasable_mm~reject  example? 

Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

Cnv88
Explorer
0 Likes

Hi folks!

I found answer in this topic:

https://community.sap.com/t5/technology-blogs-by-members/reject-purchase-requisition-item-just-like-...

 

Basically, the DEMO FM below can accomplish that for you using the mmpur_purchase_req_factory class.

function z_pr_reject.
*"----------------------------------------------------------------------
*"*"Interface local:
*"  IMPORTING
*"     REFERENCE(IM_BANFN) TYPE  BANFN
*"     REFERENCE(IM_BNFPO) TYPE  BNFPO OPTIONAL
*"  TABLES
*"      T_RETURN STRUCTURE  BAPIRET2
*"----------------------------------------------------------------------
  data: l_factory        type  mmpur_purchase_req_factory,
* Header related:
        lo_req           type ref to if_purchase_requisition,
        ls_return        type bapiret2,
        l_hdr_data       type mereq_header,
        l_document       type mepo_document,
* Item related:
        lo_item          type ref to if_purchase_requisition_item,
        lt_hdr_items_tab type mmpur_requisition_items,
        ls_hdr_item      like line of  lt_hdr_items_tab,
        ls_item_data     type mereq_item,
        lv_error         type c,
        l_allowed        type        mmpur_bool,
        l_success        type        mmpur_bool.

* Get requisition factory reference:
  call function 'MEREQ_GET_FACTORY'
    importing
      ex_factory = l_factory.

* Create header object:
  clear lo_req.
  l_document-trtyp = 'V'.            " V is change txn type
  l_document-doc_key(10) = im_banfn.
  l_document-doc_type = 'B'.
  l_document-initiator-initiator = mmpur_initiator_rel.

  call method l_factory->create_header
    exporting
      im_tcode           = 'ME54N' "just to read T160!!
      im_document        = l_document
      im_protect         = 'X'
    importing
      ex_instance        = lo_req
    exceptions
      failure            = 1
      already_registered = 2.

* IF create_header() fails:
  if lo_req is initial.
    message i004(fmfg_mm01). return.
  endif.

* Header status data
  l_hdr_data = lo_req->get_data( ).
  lo_req->get_transaction_state( importing ex_document = l_document   ).

* Get items data
  lt_hdr_items_tab = lo_req->get_items( ).

* Process Items
  loop at lt_hdr_items_tab into ls_hdr_item.
*   "Get Item (Model+data)
    lo_item = ls_hdr_item-item.
    check not lo_item is initial.

    ls_item_data = lo_item->get_data( ).

    if ls_item_data-bnfpo ne im_bnfpo.
      continue.
    endif.

    l_allowed = mmpur_no.
    l_success = mmpur_no.

    if lo_item->if_releasable_mm~is_rejection_allowed( ) = mmpur_yes.
      lo_item->if_releasable_mm~reject( exporting im_reset = mmpur_no
                                        exceptions failed   = 1 others   = 2 ).

      "Final checks
      call method lo_req->check
        importing
          ex_success = l_success.

      "error message occured
      if l_success eq mmpur_no.
        ls_return-type    = 'E'.
        ls_return-message = text-001.
        append ls_return to t_return.
        return.
      endif.

      "post document
      call method lo_req->post
        exporting
          im_uncomplete = mmpur_no
        importing
          ex_success    = l_success.

      if l_success eq mmpur_yes.
        call method l_factory->commit( ).
      else.
        ls_return-type    = 'E'.
        ls_return-message = text-002.
        append ls_return to t_return.
        return.
      endif.

    else.
      ls_return-type    = 'E'.
      ls_return-message = text-003.
      append ls_return to t_return.
      return.
    endif.

    call function 'BAPI_TRANSACTION_COMMIT'
      exporting
        wait = 'X'.

  endloop.

endfunction.

 

001	Rejection check Error!	22	30
002	Rejection Error!	16	16
003	Rejection not allowed!	22	132

Answers (0)