Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
jose_sequeira
Active Participant
5,129
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.
10 Comments
Labels in this area