When I came across the requirement to add business partner PO, I tried to search for solution is SDN and I only found few posts un-answered/Assumed Answered on somewhat similar requirement but there was no definite solution mentioned.

Adding Partner into Purchase Order (ME21N, ME22N)

How to update Partner function tab in ME21N Transaction

Business Requirement: Add Ordering address partner while PR is getting converted to PO via ME21N/ME59N.

Comment: We can add partner except for ‘VN’ using the below approach via code.

Solution: We can achieve this requirement via creating an implementation of the BADI ME_PROCESS_PO_CUST, Method PROCESS_ITEM. This method is called for every item hence in case we need to add business partners based on PR Item this method will be appropriate otherwise we can use similar code in method PROCESS_HEADER

Sample Code:

   DATA: gr_header          TYPE REF TO if_purchase_order_mm.

   DATA: gs_header         TYPE mepoheader.

   DATA: gt_mmpa           TYPE mmpur_t_mmpa,

              gt_ekpa              TYPE mmpur_t_ekpa,

              gs_mmpa           TYPE mmpa,

              gs_ekpa             TYPE ekpa,

              gs_ekpa_temp   TYPE ekpa,

              gv_atlast_event TYPE flag,

              gv_pargr            TYPE pargr. “Partner Determination Procedure

   CONSTANTS : gc_appli         TYPE char1 VALUE ‘P’,

                            gc_parvw_ba TYPE parvw VALUE ‘BA’,

                            gc_parvw_oa TYPE parvw VALUE ‘OA’,

                            gc_flag           TYPE char1 VALUE ‘X’.

   REFRESH: gt_mmpa[].

* Get PO Header Object

   CALL METHOD im_item->get_header


       re_header = gr_header.

* Read PO Header Data

   CLEAR gs_header.

   CALL METHOD gr_header->get_data


       re_data = gs_header.

* Read PO Header Partners from Buffer

   REFRESH: gt_ekpa[].



       application = gc_appli


       x_ekpa      = gt_ekpa.

   CLEAR gv_pargr.


   FROM t161

   INTO gv_pargr

   WHERE bsart EQ gs_headerbsart

   AND   bstyp EQ gs_headerbstyp.


* To Ensure that Current Ordering Address Partner is already added to Partners Tab.

   CLEAR gs_ekpa_temp.

   READ TABLE gt_ekpa INTO gs_ekpa_temp WITH KEY  parvw = gc_parvw_ba

                                                                                              lifn2    = <Partner No.>.

   IF NOT sysubrc IS INITIAL.

     CLEAR gs_ekpa.

     LOOP AT gt_ekpa INTO gs_ekpa.

       CLEAR gs_mmpa.

       MOVE-CORRESPONDING gs_ekpa TO gs_mmpa.

*     We to add all the existing partner which are auto-populated to lt_mmpa[].     

       APPEND gs_mmpa TO gt_mmpa.

       CLEAR gv_atlast_event.

       AT LAST.

         gv_atlast_event = gc_flag.


       IF gv_atlast_event EQ gc_flag.

         MOVE-CORRESPONDING gs_ekpa TO gs_mmpa.

         gs_mmpaparvw = gc_parvw_ba. “Ordering Addres Partner Function

         gs_mmpalifn2 = <Partner No.>.

         CLEAR gs_ekpa_temp.

         READ TABLE gt_ekpa INTO gs_ekpa_temp WITH KEY  parvw = gc_parvw_oa

                                                                                                    lifn2    = gs_ekpalifn2.

         IF NOT sysubrc IS INITIAL.

           APPEND gs_mmpa TO gt_mmpa.



       CLEAR gs_ekpa.


     IF NOT gt_mmpa[] IS INITIAL.

*     Update Partner Tab



           application           = gc_appli

           ebeln                   = gs_headerebeln

           bstyp                   = gs_headerbstyp

           ekorg                   = gs_headerekorg

           lifnr                      = gs_headerlifnr

           pargr                   = gv_pargr

           screen_invisible  = gc_flag


           x_mmpa             = gt_mmpa.



Please let me know if you have any questions on this.

To report this post you need to login first.

1 Comment

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

  1. harinadh bhupathi

    hi amit,

    Thank you very much for the useful article. It really helped me in adding new partners( in our case we tried for header level). But I have a small doubt. We are creating PO using BAPI_PO_CREATE1 from a proxy “PurchaseOrderERPCreate_In_v1”. Our requirement is to add new partners which we achieved using in above manner in badi ME_PROCESS_PO_CUST( PROCESS_HEADER method). But we also want to modify the existing determined partners. For example we want to modify invoicing partner to new vendor, can you please suggest  on this…? Will it work if we try to change ‘(SAPLEKPA)XMMPA[]’ using field symbol in our code after the above code?

    Thanks a lot


Leave a Reply