Wednesday 12 August 2015

Adding Custom Field In MB51 (Material Document List)


This is the topic to add custom field in MB51(Material Document List)

Requirement:Add material group and material description in MB51






Step:go to MSEG table add two fields like ZZMAT_GROUP & ZZMAT_DESC with structure




step2-then find out the program name for the transaction code MB51 which is RM07DOCS double click on that program name and on that click on spiral button to find the implicit enhancement position. when you find the position you have to add custom field to the LIST internal table.



step-3:then you search the perform name 'PERFORM output_list.' and double click on it and some logic on that part like this.



on this part write the code:


DATA l_v_name TYPE THEAD-TDNAME,
       it_line TYPE STANDARD TABLE OF TLINE,
       wa_line TYPE TLINE,
       l_v_text TYPE char100,
       index TYPE sy-tabix.
****add by sujit on dt:10.08.2015
types:begin of ty_makt,
      matnr type matnr,
      matkl type matkl,
      end of ty_makt,
      BEGIN OF ty_desc,
      MATKL  type MATKL,
      WGBEZ  type WGBEZ,
      end of ty_desc.


data:lt_matkl TYPE TABLE OF ty_makt,
     lt_desc  type TABLE OF ty_desc.


FIELD-SYMBOLS<lfs_matkl> type ty_makt,
               <lfs_desc>  type ty_desc.
******end of addition mat group and description on dt:10.08.2015


**************add by sujit on dt:10.08.2015
******add mat group and description by sujit on dt 10.08.2015
data lt_itab1 LIKE list[].
FIELD-SYMBOLS <lfs_itab> like LINE OF lt_itab1.
lt_itab1[] list[].
if lt_itab1 is NOT INITIAL.
  select matnr
         matkl
    from mara INTO TABLE lt_matkl
    FOR ALL ENTRIES IN lt_itab1
    WHERE matnr lt_itab1-matnr.
  if sy-subrc eq 0.
    sort lt_matkl by matnr.
      select
           matkl
           WGBEZ
      from T023T INTO table lt_desc
      FOR ALL ENTRIES IN lt_matkl
      where spras sy-langu and
            matkl lt_matkl-matkl.
      if sy-subrc eq 0.
        sort lt_desc by matkl.
      endif.
   endif.
  endif.

  LOOP at lt_itab1 ASSIGNING <lfs_itab>.

    READ TABLE lt_matkl ASSIGNING <lfs_matkl> with key
                                      matnr <lfs_itab>-matnr BINARY SEARCH.
    if sy-subrc eq 0.
      <lfs_itab>-zzmat_group <lfs_matkl>-matkl.
     READ TABLE lt_desc ASSIGNING <lfs_desc> WITH key
                                      matkl <lfs_matkl>-matkl  BINARY SEARCH.
     if sy-subrc eq 0.
       <lfs_itab>-zzmat_desc <lfs_desc>-wgbez.
     endif.
    endif.

  ENDLOOP.

  list[] lt_itab1[].
*************end of addition mat group and description on dt:10.08.2015
ENDENHANCEMENT.



step-4: then double click on Include structure ITAB and custom field on that declaration to show the fields in output list.



when double click on itab then you go to include RM07DOCS_GENERATED then you click on the spiral button append the fields to g_t_fields through enhanment.



this is the end of enhancement after that you run the tcode-MB51 and get the details on the out put.



if anyone face any problem post your comments the i will update you.

9 comments:

  1. Hello,
    thanks for your amazing sharing. I ve done everything what you tell but it doesn't show in ALV list. Do I need to add my Z field into some where else. When I checked ITAB table, everything is ok but when I checked filed catalog but Z field does not shown there. So do i miss some point? thanks again

    ReplyDelete
  2. Lo unico que falta es modificar el LAYOUT para visualizar los campos que fueron agregados.

    Me resulto todo correctamente.

    Saludos
    Gracias.

    ReplyDelete
  3. In my version you have to add another ENHANCEMENT in RM07DOCS_GENERATED.
    After line
    501 rx'MKPF XBLNR 00 00'.

    rx'MSEG ZZMAT_GROUP 00 00'.
    rx'MSEG ZZMAT_DESC 00 00'.

    Otherwise it is not working - you don't get the extra fields in MB51.

    ReplyDelete
  4. Allah senin belanı versin!!! Senin yüzünden yandı sistem...

    ReplyDelete
  5. Hello,
    thanks for your amazing sharing.

    ReplyDelete
  6. Hi, I want to add vendor name and old material no in output list of mb51 plz tell me how to add

    ReplyDelete
  7. Its wonderful blog really very nice site and blog facility.every title is very nice and very fatastic concept.Private tutor in Florida Thanks for sharing the information.

    ReplyDelete