Skip to Content

Change ME21N PO header Vendor address using ME_PROCESS_PO_CUST - PROCESS_HEADER

HI Experts,

In the PO creation from Transaction ME21N, When we give vendor it will pick one of the addresses(Standard address) from vendor master, but i need to populate it with another address apart from that from address usage of that vendor, So i have enhanced it through BADI ME_PROCESS_PO_CUST - PROCESS_HEADER to pick other address but it is giving error

'Specify either address number or address handle'.

following is the code in the BADI implmentation

lr_po_header TYPE REF TO cl_po_header_handle_mm,
lm_header TYPE REF TO if_purchase_order_mm,
lt_partners TYPE mmpur_partner_all_tab,
lv_rfc_po_create TYPE boolean.

IF sy-tcode = 'ME21N'

" Get the existing data
CALL METHOD im_header->get_data
re_data = DATA(ls_mepoheader).

IF ls_mepoheader-lifnr IS NOT INITIAL
AND ls_mepoheader-adrnr IS INITIAL.

lm_header = im_header.
lr_po_header ?= lm_header.

" Get Partners
CALL METHOD lr_po_header->if_purchasing_document~get_partners
re_part = lt_partners.

SELECT SINGLE addrnumber
FROM but021_fs
INTO @DATA(lv_addrnumber)
WHERE partner EQ @ls_mepoheader-lifnr AND
adr_kind EQ 'SHIPPING'.
IF sy-subrc EQ 0.
ls_mepoheader-adrnr = lv_addrnumber.
LOOP AT lt_partners ASSIGNING FIELD-SYMBOL(<fs_partners>) .
<fs_partners>-data-addrnumber = lv_addrnumber.

" Set New Data
CALL METHOD im_header->set_data
im_data = ls_mepoheader.


Shiva K

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Nov 08, 2018 at 10:11 PM

    method IF_PURCHASE_ORDER_MM~SET_DATA( ) does a lot of checks before calling the method CL_PO_HEADER_HANDLE_MM~SET_DATA( ). You might want to call the second method directly, but it makes changes without any checks and the header status is not updated, so it is dangerous! IN NO EVENT SHALL I BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ARISING FROM, OUT OF OR IN CONNECTION WITH THIS CODE

     DATA ls_header_new TYPE mepoheader.
     DATA lo_header TYPE REF TO cl_po_header_handle_mm.
     DATA ls_datax_new TYPE mepoheaderx.
     DATA lo_model TYPE REF TO if_model_mm.
    * Get and set data in PO Header:
     lo_header ?= io_header.
     lo_header->get_data( IMPORTING ex_data = DATA(ls_data_old) ).
     lo_header->get_datax( IMPORTING ex_data = DATA(ls_datax_old) ).
     ls_header_new = ls_data_old.
    *!! CHANGE the header fields Here !!
     lo_header->set_data( ls_header_new ).
     lo_header->check_badi_datax( EXPORTING im_data_old = ls_data_old
                                            im_data_new = ls_header_new
                                            im_datax_old = ls_datax_old 
                                  IMPORTING ex_datax_new = ls_datax_new ).
     lo_header->set_datax( im_data = ls_datax_new ).
     mmpur_dynamic_cast lo_model lo_header.
     IF NOT line_exists( lo_header->my_recheck_queue[ model = lo_model ] ).
    * Update recheck queue at header level:
       APPEND VALUE #( model = lo_model ) TO lo_header->my_recheck_queue.


    Add comment
    10|10000 characters needed characters exceeded

    • Hi Jacques,

      Thanks for your suggestion, but if it is the case so please help me in achieving my requirement of replacing the vendor address with address of other usage type.might be some relevant BADI or enhancement to achieve this.