I_BANFN TYPE EBAN-BANFN -> Purchase Requistion number
C_FACTORY TYPE REF TO IF_PURCHASE_REQ_FACTORY -> Purchase requisition factory
E_RESET TYPE FLAG -> Reset was successful
HEADER_COULDNT_BE_CREATED
ERROR_DURING_RESET
CANNOT_RESET
method reject_refusal.
data: fo_req type ref to if_purchase_requisition.
data: f_document type mepo_document.
data: fo_resetable type ref to if_releasable_mm.
data: f_success type mmpur_bool.
"get requisition factory
if c_factory is initial.
call function 'MEREQ_GET_FACTORY'
importing
ex_factory = c_factory.
endif.
* Create header object
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.
* creation of header fails
if fo_req is initial.
raise header_couldnt_be_created.
endif.
* Header status data
fo_req->get_transaction_state( importing ex_document = f_document ).
fo_resetable ?= fo_req.
if fo_resetable->is_reset_rej_allowed( ) eq mmpur_yes.
fo_resetable->reject(
exporting im_reset = mmpur_yes
exceptions
failed = 1 ).
if sy-subrc ne 0.
raise error_during_reset.
endif.
else.
raise cannot_reset.
endif.
"Final checks
call method fo_req->check
importing
ex_success = f_success.
call method fo_req->post
exporting
im_uncomplete = mmpur_no
importing
ex_success = f_success.
"commit changes
if f_success eq mmpur_yes.
call method c_factory->commit( im_no_commit = mmpur_no ).
commit work and wait.
e_reset = mmpur_yes.
endif.
endmethod.