I_BANFN TYPE EBAN-BANFN ->Purchase Requisition Number
E_RESETABLE TYPE FLAG -> If rejection can be reset this parameter will be set to 'X'
CO_FACTORY TYPE REF TO IF_PURCHASE_REQ_FACTORY -> Purchase requisition factory
HEADER_COULDNT_BE_CREATED
method check_requisition_resetable.
data: fo_req type ref to if_purchase_requisition.
data: f_document type mepo_document.
data: fo_releasable type ref to if_releasable_mm.
if co_factory is initial.
" Get requisition factory if we don't pass one
call function 'MEREQ_GET_FACTORY'
importing
ex_factory = co_factory.
endif.
clear fo_req.
f_document-trtyp = 'V'. "Change mode
f_document-doc_key+0(10) = i_banfn.
f_document-doc_type = 'B'. "Purchase requisition type
f_document-initiator-initiator = space. "empty initiator
"create header
call method c_factory->create_header
exporting
im_tcode = 'ME52N'
im_document = f_document
im_protect = ' '
im_bapi = ' '
importing
ex_instance = fo_req
exceptions
failure = 1
already_registered = 2.
if sy-subrc eq 1 or fo_req is initial.
raise header_couldnt_be_created.
endif.
"check state of transaction
fo_req->get_transaction_state( importing ex_document = f_document ).
"cast to releasable object
fo_releasable ?= fo_req.
if fo_releasable->is_reset_rej_allowed( ) eq mmpur_yes.
e_resetable = 'X'.
else.
e_resetable = space.
endif.
free: fo_req.
endmethod.
EnjoY!