Skip to Content
Technical Articles
Author's profile photo Jose Sequeira

Reject Purchase Requisition Item, just like FIORI does!

Hello,

When SAP® FIORI or the standard WF for Purchase requisition is releasing a item Code, they use the standard BAPI:  BAPI_REQUISITION_RELEASE.

But what happens when SAP® FIORI rejects a PR item? You will search for the “REJECT” BAPI for PR item, but you’ll not find. ?

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

Testing:

 

Release Refused status, just like FIORI does.

So if you need to develop any sort of solution that rejects PR itens, that’s a way out! Enjoy!

Regards.

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Cristiano Marques
      Cristiano Marques

      Good text, Jose! Simple and useful.

      Author's profile photo Jose Sequeira
      Jose Sequeira
      Blog Post Author

      Hello Cristiano Marques , thanks... Working on the PO scenario as well.

      Regards.

       

       

      Author's profile photo Michael Keller
      Michael Keller

      Hi Jose. I find your contribution very valuable not only from a technical point of view. It shows nicely that ABAP works under the surface (Fiori / UI5) 🙂

      Author's profile photo Jose Sequeira
      Jose Sequeira
      Blog Post Author

      Thanks, stay tuned for more!

      Author's profile photo Josiane Cristina Correa
      Josiane Cristina Correa
      Hello Sequeira, how are you?
      
      Thank you for sharing. I used the example of the purchase order and works very well.
      
      But for purchase requisition it didn't work, this line returns false:
      
      
      if lo_item->if_releasable_mm~is_rejection_allowed( ) = mmpur_yes.
      
      
      Any more tips?
      
      Thank you very much.
      Author's profile photo Derek Wong
      Derek Wong

      Hi

       

      Have you solved your problem yet?

      Author's profile photo Sachin Shinde
      Sachin Shinde

      Hello Sequeira,

      Very important scenario.
      However I am also getting the same issue as Josiane.
      Please advise.

      Thank you.