Application Development and Automation 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: 
Read only

BADI ME_PROCESS_PO_CUST Method Post

AlexGiguere
Contributor
4,676

Hi, how can we know in the method post of the BADI ME_PROCESS_PO_CUST if we are in creation mode (me21n) or change mode (me22n), I need to do some coding only at the creation of the PO but this method is call anytime we click save!

thanks!

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
3,041

Hello Alexandre

It would be possible to check the transaction. However, if the BAPI BAPI_PO_CREATE is used the BAdI is also processed yet the transaction is most likely wrong.

An <u>unambigous </u>approach is to check IMPORTING parameter IM_TRTYP in method IF_EX_ME_PROCESS_PO_CUST~OPEN:


METHOD if_ex_me_process_po_cust~open.
* define local data
  DATA:
    lo_po          TYPE REF TO cl_po_header_handle_mm,
    ls_header      TYPE mepoheader.

  me->md_trtyp = im_trtyp.  " save transaction type

  IF ( im_trtyp = 'H' ).  " add new purchase order
...

I would add an instance attribute MD_TRTYP to the BAdI implementing class and save the transaction type in method IF_EX_ME_PROCESS_PO_CUST~OPEN (see above).

Now you can simply add the following IF condition to your POST method:

METHOD if_ex_me_process_po_cust~open.

  CASE me->md_trtyp.  
    WHEN 'H'.    " add new purchase order
  ...  " do required action for CREATE

    WHEN ... .

    WHEN others.
      ...
  ENDCASE.
...

The possible transaction types can be found at: im_trtyp -> data element -> <b>domain </b>(fixed values).

Regards

Uwe

Hi, how can we know in the method post of the BADI ME_PROCESS_PO_CUST if we are in creation mode (me21n) or change mode (me22n), I need to do some coding only at the creation of the PO but this method is call anytime we click save!

thanks!

6 REPLIES 6
Read only

Former Member
0 Likes
3,041

I think you can check Transaction Code in BADI.

Read only

uwe_schieferstein
Active Contributor
3,042

Hello Alexandre

It would be possible to check the transaction. However, if the BAPI BAPI_PO_CREATE is used the BAdI is also processed yet the transaction is most likely wrong.

An <u>unambigous </u>approach is to check IMPORTING parameter IM_TRTYP in method IF_EX_ME_PROCESS_PO_CUST~OPEN:


METHOD if_ex_me_process_po_cust~open.
* define local data
  DATA:
    lo_po          TYPE REF TO cl_po_header_handle_mm,
    ls_header      TYPE mepoheader.

  me->md_trtyp = im_trtyp.  " save transaction type

  IF ( im_trtyp = 'H' ).  " add new purchase order
...

I would add an instance attribute MD_TRTYP to the BAdI implementing class and save the transaction type in method IF_EX_ME_PROCESS_PO_CUST~OPEN (see above).

Now you can simply add the following IF condition to your POST method:

METHOD if_ex_me_process_po_cust~open.

  CASE me->md_trtyp.  
    WHEN 'H'.    " add new purchase order
  ...  " do required action for CREATE

    WHEN ... .

    WHEN others.
      ...
  ENDCASE.
...

The possible transaction types can be found at: im_trtyp -> data element -> <b>domain </b>(fixed values).

Regards

Uwe

Read only

0 Likes
3,041

Thanks Uwe, this is what I was searching for, I never thought to look in the open method.

I give you 10

Regards,

Alex

Read only

0 Likes
3,041

Hello Alexandre

You are welcome!

Since BAdI interface usually do not have that many methods I usually "browse" through all methods and their parameters to get an idea about the function of the methods (because, sadly enough, they are poorly documented).

Regards

Uwe

Read only

0 Likes
3,041

I face the same problem as I need to have some logic implemented in the close method if it is a create PO action.

When I try your coding in METHOD if_ex_me_process_po_cust~open.

me->md_trtyp = im_trtyp.

I get 'Field "MD_TRTYP" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement.

Besides, I would like to ask if I can declare a global variable to be shared within the different methods in the BADI ME_PROCESS_PO_CUST.

Read only

0 Likes
3,041

Hello Gundam

I have defined MD_TRTYP (most like of TYPE trtyp) as <i>private </i>instance attribute of the class implementing the BAdI interface. This way the transaction type is available in all methods of the BAdI.

Regards

Uwe