This website is not affiliated with, sponsored by, or approved by SAP AG.

BAdI to change EKPO-TXZ01 in ME21N

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

BAdI to change EKPO-TXZ01 in ME21N

Postby bart jongen » Thu Aug 28, 2014 10:15 am

Hello,

I am trying to find a BAdI that can change the Short Text (EKPO-TXZ01) during ME21N.
We want the Short Text to be filled with the Material number (AFKO-PLNBEZ) from the Production order (EKKN-AUFNR), in case the Account Assignment is for a Production order (EKPO-KNTTP = 'F'.)
I tried Method PROCESS_ITEM of BAdI ME_PROCESS_PO_CUST but this BAdI doesn't do the trick..

Can anyone help me find the right BAdI (and ideally have the code I am looking for)?
Thanks a lot in advance,
Kind regards,
Bart Jongen
Eindhoven, the Netherlands
bart jongen
 
Posts: 209
Joined: Mon Sep 12, 2005 3:26 am
Location: Eindhoven, The Netherlands

Re: BAdI to change EKPO-TXZ01 in ME21N

Postby Gothmog » Mon Sep 01, 2014 3:51 am

This should be the right BAdI - maybe share your code and see if we can spot something wrong with it?
68 74 74 70 3a 2f 2f 74 69 6e 79 75 72 6c 2e 63 6f 6d 2f 62 64 6f 37 6d 77 67
Gothmog
 
Posts: 1941
Joined: Wed Sep 12, 2007 4:46 am
Location: Probably not home

Re: BAdI to change EKPO-TXZ01 in ME21N

Postby bart jongen » Mon Sep 01, 2014 6:29 am

Hi Gothmog,

My code is as follows (I have only created some code for testing so far):

Code: Select all
METHOD if_ex_me_process_po_cust~process_item.

  break jongenb.

  DATA : lo_header TYPE REF TO if_purchase_order_mm.
  DATA : ls_mepoitem TYPE mepoitem.
  DATA:  ls_mepoheader TYPE mepoheader.

  lo_header = im_item->get_header( ).
  ls_mepoheader = lo_header->get_data( ).
  ls_mepoitem = im_item->get_data( ).

  IF ls_mepoheader-bsart = 'ZSC'.
    ls_mepoitem-txz01 = 'test'.
  ENDIF.

ENDMETHOD.

When I debug the code, the txz01 is indeed changed to 'test' (in case of BSART = ZSC), but after debugging is done, the Short Text from the Material is determined and displayed again in the field txz01.
This remains so also after saving the PO.

Thanks once again very much for your help.
Kind regards,
Bart Jongen
Eindhoven, the Netherlands
bart jongen
 
Posts: 209
Joined: Mon Sep 12, 2005 3:26 am
Location: Eindhoven, The Netherlands

Re: BAdI to change EKPO-TXZ01 in ME21N

Postby Gothmog » Mon Sep 01, 2014 6:34 am

The get_data method gets the value of the item data, not a reference to the item data in the object.
You need to use the set_data method to actually change it in the object once you've modified it:
Code: Select all
im_item->set_data( ls_mepoitem ).
68 74 74 70 3a 2f 2f 74 69 6e 79 75 72 6c 2e 63 6f 6d 2f 62 64 6f 37 6d 77 67
Gothmog
 
Posts: 1941
Joined: Wed Sep 12, 2007 4:46 am
Location: Probably not home

Re: BAdI to change EKPO-TXZ01 in ME21N

Postby bart jongen » Mon Sep 01, 2014 7:48 am

Hi Gothmog,

I changed the code as follows:


Code: Select all
METHOD if_ex_me_process_po_cust~process_item.

  break jongenb.

  DATA : lo_header TYPE REF TO if_purchase_order_mm.
  DATA : ls_mepoitem TYPE mepoitem.
  DATA:  ls_mepoheader TYPE mepoheader.

  lo_header = im_item->get_header( ).
  ls_mepoheader = lo_header->get_data( ).
  ls_mepoitem = im_item->get_data( ).
  im_item->set_data( ls_mepoitem ).

  IF ls_mepoheader-bsart = 'ZSC'.
    ls_mepoitem-txz01 = 'test'.
  ENDIF.

ENDMETHOD.


But this does not solve the problem..
Last edited by Baz on Mon Sep 01, 2014 8:31 am, edited 2 times in total.
Kind regards,
Bart Jongen
Eindhoven, the Netherlands
bart jongen
 
Posts: 209
Joined: Mon Sep 12, 2005 3:26 am
Location: Eindhoven, The Netherlands

Re: BAdI to change EKPO-TXZ01 in ME21N

Postby Gothmog » Mon Sep 01, 2014 8:49 am

You did it too soon!
First change ls_mepoitem, then apply the changes to the object data:
Code: Select all
METHOD if_ex_me_process_po_cust~process_item.

  break jongenb.

  DATA : lo_header TYPE REF TO if_purchase_order_mm.
  DATA : ls_mepoitem TYPE mepoitem.
  DATA:  ls_mepoheader TYPE mepoheader.

  lo_header = im_item->get_header( ).
  ls_mepoheader = lo_header->get_data( ).

  IF ls_mepoheader-bsart = 'ZSC'.
    ls_mepoitem = im_item->get_data( ).
    ls_mepoitem-txz01 = 'test'.
    im_item->set_data( ls_mepoitem ).
  ENDIF.

ENDMETHOD.
68 74 74 70 3a 2f 2f 74 69 6e 79 75 72 6c 2e 63 6f 6d 2f 62 64 6f 37 6d 77 67
Gothmog
 
Posts: 1941
Joined: Wed Sep 12, 2007 4:46 am
Location: Probably not home

Re: BAdI to change EKPO-TXZ01 in ME21N

Postby bart jongen » Wed Sep 03, 2014 2:17 am

Hello Gothmog,

Thanks so much for your reply; it works now!
(FYI: I am a functional consultant with some ABAP skills)
Kind regards,
Bart Jongen
Eindhoven, the Netherlands
bart jongen
 
Posts: 209
Joined: Mon Sep 12, 2005 3:26 am
Location: Eindhoven, The Netherlands


Return to ABAP

Who is online

Users browsing this forum: Snowy and 7 guests





loading...


This website is not affiliated with, sponsored by, or approved by SAP AG.