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

No BAPI for Purchase Order Rejection? Here is the solution, like FIORI does!

Hello,

As many of you know, to release a purchase order you can use the BAPI_PO_RELEASE as the solution, just passing the PO Number and Release Strategy Code (the standard WF uses). But if you search for the “Rejection” BAPI you will not find! ? Searching google, there are a lot of open questions about it and most of them without a solution (or giving a BDC solution)…

So based on that, i’ve created the FM below that can serve as the solution for this scenarios, using the same pieces of code that FIORI uses when rejecting the PO on the standard app.

Here it is:

function z_po_reject.
*"----------------------------------------------------------------------
*"*"Interface local:
*"  IMPORTING
*"     VALUE(I_EBELN) TYPE  EBELN
*"  TABLES
*"      T_RETURN STRUCTURE  BAPIRET2
*"----------------------------------------------------------------------
  data: lr_po           type ref to cl_po_header_handle_mm,
        ls_bapi         type bapiret2,
        l_result        type mmpur_bool,
        ls_document     type mepo_document.

*  prepare creation of PO instance
  ls_document-process     = 'PO_PROCESS'.
  ls_document-trtyp       = 'VER'.
  ls_document-doc_key(10) = i_ebeln.
  ls_document-initiator-initiator = 'RELEASE'.

  create object lr_po.
  lr_po->for_bapi = 'X'.
  lr_po->po_initialize( ls_document ).
  lr_po->set_po_number( i_ebeln ).

  try.
      lr_po->po_read( exporting im_tcode     = 'ME29N'
                                im_trtyp     = ls_document-trtyp
                                im_aktyp     = ls_document-trtyp
                                im_po_number = i_ebeln
                                im_document  = ls_document
                      importing ex_result    = l_result ).  "2212877
    catch cx_root.                                       "#EC CATCH_ALL
      l_result = mmpur_no.                                  "2212877
  endtry.

  if l_result = mmpur_no.
    "Error here...
    return.
  endif.

  if lr_po->if_releasable_mm~is_rejection_allowed( ) eq 'X'.
    lr_po->if_releasable_mm~reject(
                       exporting  im_reset = ''
                       exceptions failed   = 0 ).
    if sy-subrc eq 0.
      "Success here...
      lr_po->po_post( exceptions failure = 1
                                 others  = 2 ).
      if sy-subrc gt 0.
        lr_po->po_initialize( ).
      else.
        lr_po->po_close( ).
        free lr_po.
      endif.
    else.
      "Error here...
      call function 'BALW_BAPIRETURN_GET2'
        exporting
          type   = sy-msgty
          cl     = sy-msgid
          number = sy-msgno
          par1   = sy-msgv1
          par2   = sy-msgv2
          par3   = sy-msgv3
        importing
          return = ls_bapi.
      append ls_bapi to t_return.
    endif.
  endif.
endfunction.

Testing:

Running:

Rejected:

Enjoy it! ??

Regards.

Assigned Tags

      10 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Saikat Chakraborty
      Saikat Chakraborty

      Amazing!

      Author's profile photo Fausto Motter
      Fausto Motter

      Well, as usual, a great content and great blog. Congrats,

      FM

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

      Thanks, stay tuned for more!

      Author's profile photo Ged Hurst
      Ged Hurst

      Nice and simple. Thanks!

      Author's profile photo Łukasz Pęgiel
      Łukasz Pęgiel

      Nice work!

      Here you can find similar solution for the purchase requisitions:

      https://abapblog.com/articles/how-to/58-reset-rejection-of-purchase-requisition
      https://abapblog.com/articles/how-to/57-other-checks-on-purchase-requisition-state
      https://abapblog.com/articles/how-to/56-how-to-check-if-for-purchase-requisition-wf-rejection-can-be-reset

      At the end it is only the interface if_releasable_mm in both cases (PO/PR) that needs to be used.

      Cheers
      Łukasz

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

      Hello Łukasz Pęgiel , how are you?

      That's right! I've created one as well regarding PR:

      https://blogs.sap.com/2020/03/12/reject-purchase-requisition-item-just-like-fiori-does/

      Also one on how to reverse engineer FIORI for this kind of solutions:

      https://blogs.sap.com/2020/03/16/reverse-engineering-onpremise-fiori-for-key-source-code/

      Regards.

      Author's profile photo CRISTIANO MACHADO
      CRISTIANO MACHADO

      e ai mano.. você é o cara... show isso ai... mais um pra lista

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

      CRISTIANO MACHADO , tudo bem? Obrigado!

      Author's profile photo Balaji Peethani
      Balaji Peethani

      Hi,

      I was trying to build logic from standard program. Luckily found this page on my last trial. It saved my time. Thank you for providing this one.

       

      Thank you,

      Balaji P.

      Author's profile photo Vasu G
      Vasu G

      Great article and very helpful in completion of my workflow development.

      Thank you and appreciate.. Jose Sequeira,.

       

      Regards,

      Vasu