Skip to Content

Autofill Purchasing Group in ME21n (Create Purchase Order)


In transaction ME21n, if a vendor is entered, we have to manually fill the purchasing group. It is more time consuming. So a BADI is implemented which retrieve the purchasing group of the vendor from the table LFM1 (Vendor master record purchasing organization data) and sets it to the field ‘Purchasing Group’ in the screen.


The BADI used is ME_PROCESS_PO_CUST. Both vendor number (LIFNR) and purchasing group (EKGRP) is in the table LFM1.

Detailed Process

Go to the transaction SE19. Enter the BADI and click in Create Implementation.


Give the name for the implementation.



Check for the method PROCESS_HEADER.


Double Click on the method PROCESS_HEADER. Assign a package and transport request.

The method PROCESS_HEADER has only 1 parameter, IM_HEADER, which is an object reference to the interface IF_PURCHASE_ORDER_MM. Inside the interface, there are several methods. Among that methods, GET_DATA is used to retrieve the data and SET_DATA is used to write the data back.

So the above interface methods should be called from the method PROCESS_HEADER.


DATA: lw_mepho TYPE mepoheader,
TYPE ekgrp.

CLEAR lw_mepho.

CALL METHOD im_header->get_data
= lw_mepho.

FROM lfm1
INTO lv_ekgrp
WHERE lifnr EQ lw_mepholifnr.

lw_mephoekgrp = lv_ekgrp.

CALL METHOD im_header->set_data
= lw_mepho.


The parameter for the interface method GET_DATA is a structure of type MEPHOHEADER. So, a workarea of the same type is declared. The method GET_DATA is called which returns the data which is saved in lw_mepho. The vendor number entered is in the field LIFNR in the structure lw_mepho. So the purchasing group (EKGRP) is retrieved from the table LFM1 and stored to the variable lv_ekgrp. The structure lw_mepho is updated with the purchasing group and is written back using the method SET_DATA.

Go back and activate the BADI Implementation.

1 Comment
You must be Logged on to comment or reply to a post.