Skip to Content

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

     RECEIVING

       re_header = gr_header.

* Read PO Header Data

   CLEAR gs_header.

   CALL METHOD gr_header->get_data

     RECEIVING

       re_data = gs_header.

* Read PO Header Partners from Buffer

   REFRESH: gt_ekpa[].

   CALL FUNCTION ‘MM_READ_PARTNERS’

     EXPORTING

       application = gc_appli

     TABLES

       x_ekpa      = gt_ekpa.

   CLEAR gv_pargr.

   SELECT SINGLE pargr

   FROM t161

   INTO gv_pargr

   WHERE bsart EQ gs_headerbsart

   AND   bstyp EQ gs_headerbstyp.

   CHECK NOT gv_pargr IS INITIAL.

* 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.

       ENDAT.

       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.

         ENDIF.

       ENDIF.

       CLEAR gs_ekpa.

     ENDLOOP.

     IF NOT gt_mmpa[] IS INITIAL.

*     Update Partner Tab

       CALL FUNCTION ‘MM_MAINTAIN_PARTNERS’

         EXPORTING

           application           = gc_appli

           ebeln                   = gs_headerebeln

           bstyp                   = gs_headerbstyp

           ekorg                   = gs_headerekorg

           lifnr                      = gs_headerlifnr

           pargr                   = gv_pargr

           screen_invisible  = gc_flag

         TABLES

           x_mmpa             = gt_mmpa.

     ENDIF.

   ENDIF.


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

    (0) 

Leave a Reply