Step by step guide on adding a new tab in ME21N using a BADI

By Krishna Chaitanya Gogineni, Deloitte Consulting

Introduction:  

The requirement is to add below screen fields in the ME21N, ME22N, ME23N (Header Section) …New tab called “Other Data” using a BADI.  

 

Step by step procedure:  

First, add the new fields required in the extension structure for EKKO table (CI_EKKODB). These fields will reflect in the new tab which we are going create in the ME21N screen.  

Now, Implement the BADI (ME_GUI_PO_CUST).  

First method: SUBSCRIBE  

DATA: ls_subscriber LIKE LINE OF re_subscribers.
* we want to add a customer subscreen on the Header tab
    CHECK im_application = 'PO'.
    CHECK im_element     = 'HEADER'.
* each line in re_subscribers generates a subscreen. We add one subscreen in this example
    CLEAR re_subscribers[].
* the name is a unique identifier for the subscreen and defined in this class definition
    ls_subscriber-name = subscreen1.
* the dynpro number to use
    ls_subscriber-dynpro = '0001'.
* the program where the dynpro can be found
    ls_subscriber-program = 'SAPLZKMMM_KAU86037'.
* each subscreen needs his own DDIC-Structure
    ls_subscriber-struct_name = 'CI_EKKODB'.
* a label can be defined
    ls_subscriber-label = text-001.
* the position within the tabstrib can be defined
    ls_subscriber-position = 13.
* the height of the screen can be defined here. Currently we suport two screen sizes:
* value <= 7 a sevel line subscreen
* value > 7  a 16 line subscreen
    ls_subscriber-height = 7.
    APPEND ls_subscriber TO re_subscribers.

Here, parameter ‘im_element’ is defined as ‘HEADER’ as we are adding new tab in header section of PO.  

Define a function group and take the main program and define it in ls_subscriber-program.

Also define a sub screen with the required fields and assign it to the parameter ls_subscriber-dynpro.  

Then method MAP_DYNPRO_FIELDS  

FIELD-SYMBOLS: <mapping> LIKE LINE OF ch_mapping.
    LOOP AT ch_mapping ASSIGNING <mapping>.
    CASE <mapping>-fieldname.
      WHEN 'ZZPAYMENT_AGRE'.      <mapping>-metafield = mmmfd_cust_03.
      WHEN 'ZZPROJECT'.                     <mapping>-metafield = mmmfd_cust_04.
    ENDCASE.
  ENDLOOP.  

TRANSPORT_FROM_MODEL:

DATA:     l_header       TYPE REF TO if_purchase_order_mm,
              ls_mepoheader  TYPE mepoheader,
              ls_customer    TYPE CI_EKKODB.
*--------------------------------------------------------------------*
* system asks to transport data from the business logic into the view
*--------------------------------------------------------------------*
    CASE im_name.
      WHEN subscreen1.
* is it an Header? im_model can be header or item.
        mmpur_dynamic_cast l_header im_model.
        CHECK NOT l_header IS INITIAL.
* transport standard fields
        ls_mepoheader = l_header->get_data( ).
* store info for later use
        MOVE-CORRESPONDING ls_mepoheader TO dynp_data_pbo.
      WHEN OTHERS.
* ...
    ENDCASE.    

TRANSPORT_TO_DYNP:

Define a FM 'ZK_KAU86037_PUSH' to push the values.
CASE im_name.
      WHEN subscreen1.
        CALL FUNCTION 'ZK_KAU86037_PUSH'
          EXPORTING
            im_dynp_data = dynp_data_pbo.
      WHEN OTHERS.
    ENDCASE.    

TRANSPORT_FROM_DYNP:

  Define another FM 'ZK_KAU86037_POP'.
CASE im_name.
      WHEN subscreen1.
        CALL FUNCTION 'ZK_KAU86037_POP'
          IMPORTING
            ex_dynp_data = dynp_data_pai.
        IF dynp_data_pai NE dynp_data_pbo.
* something has changed therefore we have to notify the framework
* to transport data to the model
          re_changed = mmpur_yes.
        ENDIF.
      WHEN OTHERS.
    ENDCASE.  

TRANSPORT_TO_MODEL:     

        DATA: l_header             TYPE REF TO if_purchase_order_mm,
          ls_mepoheader        TYPE mepoheader,
          ls_customer          TYPE CI_EKKODB,
          l_po_header_handle   TYPE REF TO cl_po_header_handle_mm.
*--------------------------------------------------------------------*
* data have to be transported to business logic
*--------------------------------------------------------------------*
    CASE im_name.
      WHEN subscreen1.
* is it an item? im_model can be header or item.
        mmpur_dynamic_cast l_header im_model.
        CHECK NOT l_header IS INITIAL.
        ls_mepoheader = l_header->get_data( ).
* standard fields changed?
        IF dynp_data_pbo-zzpayment_agre   NE dynp_data_pai-zzpayment_agre
        OR dynp_data_pbo-zzproject        NE dynp_data_pai-zzproject.
* update standard fields
          ls_mepoheader-zzpayment_agre   = dynp_data_pai-zzpayment_agre.
          ls_mepoheader-zzproject  = dynp_data_pai-zzproject.
          CALL METHOD l_header->set_data
            EXPORTING
              im_data = ls_mepoheader.
        ENDIF.
      WHEN OTHERS.
    ENDCASE.  

Then we have to implement one more BADI to display the tab and update the values.

Implement the BADI ME_PROCESS_PO_CUST. This cannot be used multiple times.  

In this, we have methods (PROCESS_HEADER,PROCESS_ITEM).if we need to any validations for the fields we can write the logic here in this methods. In my case I need to check for the document type which I implemented in the method (PROCESS_HEADER).  

FIELDSELECTION_HEADER: I have implemented this method as my requirement is to show the fields for particular document types only.  

Final output:  

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image