Technical Articles
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.
Amazing!
Well, as usual, a great content and great blog. Congrats,
FM
Thanks, stay tuned for more!
Nice and simple. Thanks!
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
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.
e ai mano.. você é o cara... show isso ai... mais um pra lista
CRISTIANO MACHADO , tudo bem? Obrigado!
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.
Great article and very helpful in completion of my workflow development.
Thank you and appreciate.. Jose Sequeira,.
Regards,
Vasu
Thanks master ! works perfect.
Regards from Chile 🙂
Great Job! Jose
Thansk a lot for publish it .
Best Regards,
Yonys.