1 1 1 1 1 Rating 0% (0 Votes)
Working with Purchase Requisitions in ABAP is quite pleasant job, but sometimes it's not so easy like with other documents types. You cannot easily say if Requisition is rejected and can be reset by checking EBAN table. You have to use OO PR objects to be able to do so. Bellow you can find a method how to check if you can reset the rejection of the requisition done in the WF. 
 
Importing:

I_BANFN TYPE EBAN-BANFN ->Purchase Requisition Number

Exporting:

E_RESETABLE TYPE FLAG -> If rejection can be reset this parameter will be set to 'X'

Changing:

CO_FACTORY TYPE REF TO IF_PURCHASE_REQ_FACTORY -> Purchase requisition factory

Exception:

HEADER_COULDNT_BE_CREATED

Implementation:

method check_requisition_resetable.

  datafo_req        type ref to if_purchase_requisition.
  dataf_document    type mepo_document.
  datafo_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 or fo_req is initial.
    raise header_couldnt_be_created.
  endif.

  "check state of transaction
  fo_req->get_transaction_stateimporting 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.


  freefo_req.


endmethod.

EnjoY!