Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Purchase order reject function

luscruz
Participant
0 Kudos

Hi all,

I need to reject a PO with abap code.

Since i didn't found any function module for that, i tried to create a BDC with ME29N but it doesn't seem to work.

Any other ideas?

Thanks,

Luis Cruz

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Plz check this thread.

15 REPLIES 15

Former Member
0 Kudos

Hi,

Plz check this thread.

0 Kudos

Hi senthil,

I don't have those BADI's. I searched in SE37 and SE19.

SAP_BASIS = SAPKB70015

Thanks,

Luis Cruz

Former Member
0 Kudos

Hello Luis,

Did you check BAPI_PO_CHANGE ??

Bye

Gabriel P,.

0 Kudos

Hi Gabriel,

I can't find any field on that function to set PO document as rejected.

Can you help me on what field should i change?

Thanks

0 Kudos

Hello,

On structure BAPIMEPOHEADER there is a field named REASON_CANCEL....I think that one will work.

Anyways ask your functional team which fields are required to reject a PO, take the data element from tcode me29n and look for it on the structures attached to the bapi.

cheers,

Gabriel P.-

0 Kudos

Looks like it didn't worked.

I always receive the following message:

Change Reas. for Canc. could not be effected

The PO is not locked.

I'm doing the following code:

call function 'BAPI_PO_GETDETAIL1'
  exporting
    purchaseorder            = lv_PURCHASEORDER
 IMPORTING
   POHEADER                 = ls_poheader
 TABLES
   RETURN                   = lt_RETURN
   POITEM                   = lt_pOITEM.

ls_poheader-REASON_CANCEL = '1'.
ls_poheaderx-REASON_CANCEL = 'X'.

append INITIAL LINE TO lt_pOITEMX.

call function 'BAPI_PO_CHANGE'
  exporting
    purchaseorder                = lv_PURCHASEORDER
    POHEADER                     = ls_poheader
    POHEADERX                    = ls_poheaderx
 TABLES
   RETURN                       = lt_RETURN
   POITEM                       = lt_pOITEM
   POITEMX                      = lt_pOITEMX.

COMMIT WORK AND WAIT.
CALL FUNCTION 'DEQUEUE_ALL'.

0 Kudos

Hello,

Sorry It didnt work. Ask your functional team how to fill that field, or how is the procedure to reject...and look on bapi structures the corresponding fields; as I said before.

So far, that is the only help I could give you.

Let me know if you need something else.

Bye,

Gabriel P-.

0 Kudos

After some debugs on ME29N, i manage to reject PO documents, here's the code, if anyone needs it:


*  prepare creation of PO instance
  ls_document-doc_type    = 'F'.
  ls_document-process     = mmpur_po_process.
  ls_document-trtyp       = 'V'.
  ls_document-doc_key(10) = lv_ponumber.
  ls_document-initiator-initiator = mmpur_initiator_rel.

*  object creation and initialization
  lv_ponumber = im_ebeln.
  lv_ebeln = lv_ponumber.
  create object lc_po.
  lc_po->for_bapi = mmpur_yes.
  call method lc_po->po_initialize( im_document = ls_document ).
  call method lc_po->set_po_number( im_po_number = lv_ebeln ).
  call method lc_po->set_state( cl_po_header_handle_mm=>c_available ).

*  read purchase order from database
  call method lc_po->po_read
    exporting
      im_tcode     = lv_tcode
      im_trtyp     = ls_document-trtyp
      im_aktyp     = ls_document-trtyp
      im_po_number = lv_ebeln
      im_document  = ls_document.

  if lc_po->if_releasable_mm~is_rejection_allowed( ) = 'X'.
    call method lc_po->if_releasable_mm~reject
      exporting
        im_reset = space
      exceptions
        failed   = 1
        others   = 2.
  endif.

  call method lc_po->po_post
    exceptions
      failure = 1
      others  = 2.
  

0 Kudos

Hi Cruz,

Could you please provide me the entire code to reject the Purchase Order

0 Kudos

Luiz, I just wanted to thank you! It works perfectly and saved me hours of painful debug...

Thank's again!

Regards,

Flavio Rasseli

0 Kudos

By the way, the types used there are:

DATA: lc_po       TYPE REF TO cl_po_header_handle_mm,
        ls_document TYPE mepo_document.

Regards,

Flavio Rasseli

0 Kudos

I love you mate, you save my life........

Daniel

0 Kudos

Hi,

i need also to reject a purchase order, thanks for object code but it don't work, the system tell me 'Purchasing document 1200000031 cannot be released'.

When i debug the problem comes from the method get_transaction_state(), it return type A.

0 Kudos

Sorry, it's work, transaction code is ME29N.

0 Kudos

Thanks mate it works.