Add custom fields in MM17 in SAP ABAP

                             Refer:  Add custom fields in MM01 under basic data1 tab

Step 1: To add custom fields in table level (Check in above link).

                    - Goto T-Code MASSOBJ and mark BUS1001, Double click on field list folder.

                    - Confirm work area by clicking continue button.

                    - Click on new entries and add ZZ custom fields.

Step 2: Assign fields to field selection group.

            Path: SPRO-> Logistics General -> material Master -> Field selection -> Assign Fields to field selection.

        * Click on new entries.

        * Give filed name MARA-ZZ field.

        * Select propose field content.

        * Give maintenance status as K.

        * Give ALE field group as GR_K.

        * Click on Save.

        * Add like for all fields.


Step 3: Create new segment for ZZ fields.

            * Goto WE31.

            * Give segment name ZE1MARAM and click on create.

            * Add fields.

            * Click on Save.

Step 4: Create and link Extension IDoc type.

            * Goto WE30.

            * Give object name (ZMM00001) and select extension.

            * Click on create give basic type as MATMAS02.

            * Insert ZE1MARAM segment under E1MARMM.

            * Click on Save.

Step 5: Link message type, IDOC type and Extension type.

         * Goto WE82.

        * Click on new entries.

            - Message type: MATMAS

            - IDOC type: MATMAS02

            - Extension Type: ZMM00001

            - Release: 757

        * Click on Save

Step 6: Create implementation for BADI.

            * Goto SE18.

            * Give BADI(MG_MASS_NEWSEG) name and click on display.

            * Goto implementation and click on create in menu bar.

            * Give implementation name and click on create.

            * Select implementation and create enhancement.

            * Write code in method add new segment, another method RETURN_IDOC_TYPE as empty.

            * Activate the implementation once coding part completes

METHOD if_ex_mg_mass_newseg~add_new_segment .

  TYPES: lty_idoc_data TYPE edidd.

  TYPES: BEGIN OF lty_e1maram,
           docnum  TYPE edidc-docnum,
           pointer TYPE sy-tabix.
           INCLUDE TYPE e1maram AS data.
  TYPES: END OF lty_e1maram.
  TYPES: lty_e1maram_tab TYPE STANDARD TABLE OF lty_e1maram.
  TYPES: BEGIN OF lty_ze1maram,
           docnum  TYPE edidc-docnum,
           pointer TYPE sy-tabix.
           INCLUDE TYPE ze1maram AS data.                       
  TYPES: END OF lty_ze1maram.
  TYPES: lty_ze1maram_tab TYPE STANDARD TABLE OF lty_ze1maram.

  FIELD-SYMBOLS <f1> TYPE any.
  FIELD-SYMBOLS <f2> TYPE any.
  DATA: t1(32), t2(32), findex LIKE sy-tabix.
  DATA: ls_smara     LIKE LINE OF smara,
        ls_idoc_data TYPE lty_idoc_data,
        we1maram     TYPE lty_e1maram,
        e1maram      TYPE lty_e1maram,
        lt_e1maram   TYPE lty_e1maram_tab,
        wze1maram    TYPE lty_ze1maram,                 "customer specific
        ze1maram     TYPE lty_ze1maram,                  "customer specific
        lt_ze1maram  TYPE lty_ze1maram_tab.           "customer specific

  DATA: fname     TYPE dcobjdef-name, fname2 TYPE fname,
        segname   TYPE dcobjdef-name,
        wsegname  TYPE dcobjdef-name,
        tabix     TYPE sy-tabix,
        wa_tab    TYPE mass_wa_tabdata,
        wa_newseg LIKE LINE OF wa_tab-newsegments,
        wa_msg    TYPE mass_msg,
        docnum    TYPE edidc-docnum, found,
        doccnt    TYPE edidc-docnum VALUE 1,
        newstat   TYPE mara-pstat,
        l_findex  TYPE sy-tabix,
        l_findex2 TYPE sy-tabix.

* copy the IDoc segment tables from BADI interface to local tables
  lt_e1maram = t_e1maram.
*  customer specific MARA Appendfields in MM17 mass change
  segname = 'ZE1MARAM' .
  READ TABLE seldata INTO wa_tab
    WITH KEY tabname-name = 'MARA' .
  LOOP AT smara INTO ls_smara.
    CLEAR: ze1maram , docnum.
    CLEAR newstat.
    READ TABLE wa_tab-newsegments INTO wa_newseg INDEX sy-tabix.
    IF NOT sy-subrc IS INITIAL.        "old segment
      DO.
        sy-index = sy-index + 2.
        ASSIGN COMPONENT sy-index OF
          STRUCTURE ze1maram  TO <f1>.
        IF sy-subrc NE 0. EXIT. ENDIF.
        <f1> = '/'.
      ENDDO.
*fill key fields
*      e1maram-matnr = smara-matnr .
*fill data fields
      LOOP AT wa_tab-fieldnames INTO fname.
        CONCATENATE 'LS_S' wa_tab-tabname-name
          '-' fname INTO t1.
        ASSIGN (t1) TO <f1>.
        IF NOT sy-subrc IS INITIAL.
          CONTINUE.
        ENDIF.
        CONCATENATE  segname '-' fname INTO t2.
        ASSIGN (t2) TO <f2>.
        IF NOT sy-subrc IS INITIAL.
          CONTINUE.
        ENDIF.
        <f2> = <f1>.
      ENDLOOP.
    ELSE.                              "new segment, take all fields
      MOVE-CORRESPONDING ls_smara TO ze1maram .
    ENDIF.
*work our way up the hierachy, if there is one
    CLEAR: found, findex.
    IF found IS INITIAL.
*fill parent key fields
      CLEAR e1maram.
      e1maram-matnr_long = ls_smara-matnr .
      we1maram-matnr_long = ls_smara-matnr .
      MOVE '004' TO e1maram-msgfn .
      READ TABLE lt_e1maram WITH KEY matnr_long = e1maram-matnr_long
                            INTO e1maram.
      IF sy-subrc EQ 0. "existing entry, check higher levels
        found = 'X'.
        CALL FUNCTION 'I_MASS_GET_INDEX'
          EXPORTING
            pointer = e1maram-pointer
          IMPORTING
            tabix   = findex.
        findex = findex + 1.
      ENDIF.                           "sy-subrc eq 0
      IF found = 'X'.
        docnum = e1maram-docnum .
      ELSE.                            "create an entry
        CLEAR e1maram-docnum .
        DO.
          sy-index = sy-index + 2.
          ASSIGN COMPONENT sy-index OF
            STRUCTURE e1maram  TO <f1>.
          IF sy-subrc NE 0. EXIT. ENDIF.
          IF <f1> IS INITIAL. <f1> = '/'. ENDIF.
        ENDDO.
        MOVE-CORRESPONDING ls_smara
        TO e1maram .
        MOVE ls_smara-matnr TO e1maram-matnr_long.
        CALL FUNCTION 'MG_GETPSTAT'
          EXPORTING
            tabname = 'MARA'
            segment = smara
            newstat = newstat
          CHANGING
            data    = e1maram-data.
      ENDIF.
    ENDIF.
    IF docnum IS INITIAL.
      docnum = doccnt.
      ADD 1 TO doccnt.
    ENDIF.
    IF ze1maram-docnum IS INITIAL.
      ze1maram-docnum = docnum.
      ls_idoc_data-segnam = 'ZE1MARAM' .
      ls_idoc_data-sdata = ze1maram-data .
      ls_idoc_data-docnum = docnum.
      IF findex IS INITIAL. findex = 1. ENDIF.
      INSERT ls_idoc_data INTO t_idoc_data INDEX findex.
      CALL FUNCTION 'I_MASS_SET_INDEX'
        EXPORTING
          tabix   = findex
        IMPORTING
          pointer = ze1maram-pointer.
      APPEND ze1maram TO lt_ze1maram .
    ENDIF.
    IF e1maram-docnum IS INITIAL.
      e1maram-docnum = docnum.
      ls_idoc_data-segnam = 'E1MARAM' .
      ls_idoc_data-sdata = e1maram-data .
      ls_idoc_data-docnum = docnum.
      IF findex IS INITIAL. findex = 1. ENDIF.
      INSERT ls_idoc_data INTO t_idoc_data INDEX findex.
      CALL FUNCTION 'I_MASS_SET_INDEX'
        EXPORTING
          tabix   = findex
        IMPORTING
          pointer = e1maram-pointer.
      APPEND e1maram TO lt_e1maram.
    ENDIF.
  ENDLOOP.
ENDMETHOD.

Step 7: Add enhancement and create programs.

        * Goto T code: CMOD.

        * Give project name and click on create.

        * Give enhancement as MGV00001 and Save.

        * Click on components and double click on function exits.

        * Implement 2 functions exits and activate.

        *  Program - ZXMGVU03.

                    DATA: lr_ze1maram LIKE ze1maram.

        IF segment_name EQ 'E1MARAM'.
          MOVE f_mara-zz_veh_type TO lr_ze1maram-zz_veh_type.
          MOVE f_mara-zz_sale_ord TO lr_ze1maram-zz_sale_ord.
          MOVE f_mara-zz_body_num TO lr_ze1maram-zz_body_num.
          CLEAR idoc_data.
          idoc_data-segnam = 'ZE1MARAM'.
          idoc_data-sdata = lr_ze1maram.
          APPEND idoc_data.
        ENDIF.

      *  Program - ZXMGVU04.

    DATA: lr_ze1maram LIKE ze1maram.
    IF f_cust_segment-segnam EQ 'ZE1MARAM'.
      " Vehicle type
      lr_ze1maram = f_cust_segment-sdata.
      IF lr_ze1maram-zz_veh_type = c_nodata.
        CLEAR lr_ze1maram-zz_veh_type.
      ELSE.
        IF lr_ze1maram-zz_veh_type IS INITIAL.
          res_fields-feldname = 'MARA-ZZ_VEH_TYPE'.
          APPEND res_fields.
        ENDIF.
      ENDIF.
      f_mara_ueb-zz_veh_type = lr_ze1maram-zz_veh_type.

      "Sale order
      IF lr_ze1maram-zz_sale_ord = c_nodata.
        CLEAR lr_ze1maram-zz_sale_ord.
      ELSE.
        IF lr_ze1maram-zz_sale_ord IS INITIAL.
          res_fields-feldname = 'MARA-ZZ_SALE_ORD'.
          APPEND res_fields.
        ENDIF.
      ENDIF.
      f_mara_ueb-zz_sale_ord = lr_ze1maram-zz_sale_ord.

      " Body number
      IF lr_ze1maram-zz_sale_ord = c_nodata.
        CLEAR lr_ze1maram-zz_body_num.
      ELSE.
        IF lr_ze1maram-zz_body_num IS INITIAL.
          res_fields-feldname = 'MARA-ZZ_BODY_NUM'.
          APPEND res_fields.
        ENDIF.
      ENDIF.
      f_mara_ueb-zz_body_num = lr_ze1maram-zz_body_num.
    ENDIF.

Testing: 

        * Goto MM03 and check the values for material.

            * Goto MM17.

            * Select require fields and give new values.

            * Click on perform mass change and click on save.

           
        * Check in MM03 the values are updated or not.


******************************Thank you*******************************

Comments

Popular posts from this blog

Custom entity/Action dialog in RAP using Unmanaged scenario

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).