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: 

Cancel PO Rejection using BADI ME_PROCESS_PO_CUST not working

former_member210118
Participant
0 Kudos

Hello ABAPER's.

I need your help please.

The client wants that in ME29N when SAVING the PO, the program to make the same as the "CANCEL REJECTION" button.

I managed to create a code to make the CANCEL REJECTION part (in a Ztest program) and it works very well with this code:

REPORT  zteste_rjm.


DATA: lc_po       TYPE REF TO cl_po_header_handle_mm,
      ls_document TYPE mepo_document,
      lv_ponumber LIKE ekko-ebeln,
      lv_ebeln LIKE ekko-ebeln.

PARAMETERS im_ebeln LIKE ekko-ebeln.

*  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.

*  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     = 'ME29N' "lv_tcode
    im_trtyp     = ls_document-trtyp
    im_aktyp     = ls_document-trtyp
    im_po_number = lv_ebeln
    im_document  = ls_document.

  CALL METHOD lc_po->if_releasable_mm~reject
    EXPORTING
      im_reset = 'X'
    EXCEPTIONS
      failed   = 1
      OTHERS   = 2.

CALL METHOD lc_po->po_post
  EXCEPTIONS
    failure = 1
    OTHERS  = 2.

This works fine as a standalone program, but as I said they want it when saving in the ME29N, so I found a BADI ME_PROCESS_PO_CUST and made an implementation of it and in the POST method i put my code, but what happens is that the program enters in a loop and never comes out. so one thing I changed was taking out of my code the last call method. The programs doesn't enter in loop but doesn't executes the CANCEL REJECTION.

Can anyone help me please ?

Best regards,

Ricardo Monteiro

1 ACCEPTED SOLUTION

former_member210118
Participant
0 Kudos

Hi there.

Thank you for your reply, but i found a way of doing the "thing" :).

What i did was in the CLOSE method if the Tcode is ME22N and sy-ucomm is MESAVE then I submit a Zprogram and there i'll do the CANCEL REJECTION and it works

Best Regards,

Ricardo Monteiro

2 REPLIES 2

Former Member
0 Kudos

Hi,


so I found a BADI ME_PROCESS_PO_CUST and made an implementation of it and in the POST method i put my code, but what happens is that the program enters in a loop and never comes out.

After calling "lc_po->po_post" method inside the BADi, export a flag to memory id and at the begining of the BADI method code, IMPORT this flag from memory id and check whether this flag is not having any value then only execute your code inside the BADI method.


import flag value from memory.
if flag value is initial , execute the code for rejection....
...............
...............
lc_po->po_post
..............
export flag value to memory.

I am not sure about the result, but a trail and error method only.

Regards,

Harish

former_member210118
Participant
0 Kudos

Hi there.

Thank you for your reply, but i found a way of doing the "thing" :).

What i did was in the CLOSE method if the Tcode is ME22N and sy-ucomm is MESAVE then I submit a Zprogram and there i'll do the CANCEL REJECTION and it works

Best Regards,

Ricardo Monteiro