Relation b/w MSEG AFKO

Hi all,
What is the relation b/w MSEG AFKO?
please suggest me with sample code.
regards,
AJ

Hi,
Take the EBELN and EBLP fields from MSEG table
which are PO no and Item
pass them to EKKN table and take the VBELN and POSNR fields from it which are SALES ORDER and ITEM number
and pass this VBELN to AFPO and take the AUFNR field
AFPO is the item table for AFKO
Regards,
Satish

Similar Messages

  • Urgent: Regarding Inner join relation b/w MSEG, MKPF, MARA and MAKT

    I have written o code like below for inner join. However, The program has take much more time to give out put. Could any one please correct the below inner join statement. Its very urgent.
    Thanks for your help.
    SELECT  mseg~mblnr
              mseg~matnr
              mseg~werks
              mseg~charg
              mseg~lifnr
              mseg~bualt
              mseg~erfmg
              mseg~ebeln
              mseg~ebelp
              mkpf~budat   
              mara~zzshelf_life                              
              makt~maktx
              FROM mseg
              INNER JOIN mkpf
                ON mkpfmblnr EQ msegmblnr
              INNER JOIN mara
                ON msegmatnr EQ maramatnr
              INNER JOIN makt
                ON maramatnr EQ maktmatnr
              INTO TABLE gt_mat_doc
              WHERE  mseg~matnr IN s_matnr
                AND  mseg~werks IN s_werks
                AND  mseg~lifnr IN s_lifnr
                AND  mseg~bwart EQ p_bwart
                AND  ( msegebeln NE ' ' AND msegebeln IN s_ebeln )
                AND  mkpf~budat IN s_budat
                AND  mara~mtart IN s_mtart
                AND  makt~spras EQ sy-langu.

    Hi,
    Do like this
    Types: begin of ty_mesg_mkpf,
             mblnr type mseg-mblnr,
             matnr type mseg-matnr,
             werks type mseg-werks,
             charg type mseg-charg,
             lifnr type mseg-lifnr,
             bualt type mseg-bualt,
             erfmg type mseg-erfmg,
             ebeln type mseg-ebeln,
             ebelp type mseg-ebelp,
             budat type mkpf-budat,
           end of ty_mseg_mkpf,
           Begin og ty_mara_makt,
            matnr type mara-matnr,
            zzshelf_life type mara-zzshelf_life,
            maktx type makt-maktx,
           end of ty_mara_makt.
    Data: it_mseg_mkpf type table of ty_mseg_mkpf,
          wa_mseg_mkpf type ty_mseg_mkpf,
          it_mara_makt type table of ty_mara_makt,
          wa_mara_makt type ty_mara_makt.
    SELECT m1~mblnr
    m1~matnr
    m1~werks
    m1~charg
    m1~lifnr
    m1~bualt
    m1~erfmg
    m1~ebeln
    m1~ebelp
    m2~budat
    FROM mseg
    INTO TABLE it_mseg_mkpf
    INNER JOIN mkpf
    ON m1mblnr EQ m2mblnr
    WHERE m1~matnr IN s_matnr
    AND m1~werks IN s_werks
    AND m1~lifnr IN s_lifnr
    AND m1~bwart EQ p_bwart
    AND ( m1ebeln NE ' ' AND m1ebeln IN s_ebeln )
    AND m2~budat IN s_budat
    if sy-subrc = 0.
    Select m3~matnr
    m3~zzshelf_life
    m4~maktx from mara as m3
    INNER JOIN makt as m4
    ON m3matnr EQ m4matnr
    INTO TABLE it_mara_makt
    where m3~mtart IN s_mtart
    AND m4~spras EQ sy-langu.
    endif.
    loop at it_mseg_mkpf into wa_mseg_mkpf.
    Move necessary field values from wa_mseg_mkpf to wa_mat_doc.
    Read table it_mara_makt into wa_mara_makt with key matnr = wa_mseg_mkpf-matnr.
    if sy-subrc = 0.
      move remaining field values to wa_mat_doc.
      append wa_mat_doc to gt_mat_doc.
      clear wa_mat_doc.
    endif.
    endloop.
    Regards,
    Satish

  • Secondary Index for the table MSEG

    Hi folks,
             One of my report is comparetively very slow when it is executed in the production server. when i chked, a query related to the MSEG table is taking more time to execute. I want to create a secondary index for that table. Could any body tell  me the procedure of creating the seconday index for the table MSEG, as i am not aware of that.
    Thanks in advance,
    Shyam.

    Dear shyam,
    Search SDN before posting any thread their are 10k threads available for your question anyhow for your reference here is one link
    http://help.sap.com/search/highlightContent.jsp
    Cheers
    fareed

  • Relation between Maintenance Order No. and Operation Number

    Hi all,
    I have to make a module pool in which i want to display the following field
    Order No.                                               
    Operation no. | Operation Description |
    Now my problem is that i m not getting the tables from which i have to select data basically i want to extract the data on the basis of Maintenance Order No. and Operation Number.
    I have checked the following tables
    AFKO , AFVu , AFVC, CAUFV.
    But i m not able to find any relation between Maintenance Order No. and Operation Number.
    Please help!!!
    Thanks and regards,
    Rachit khanna

    Hello Rachit,
    The relation is as follows
    AFKO-AUFPL (Routing number is Order header)
    Use this routing number to get operations from AFVC
    AFVC-VORNR gives operation number
    AFVC-LTXA1 gives operation description
    For sub-operations, VORNR will be sub-operation number, and AFVC-SUMNR for this sub-operation corresponds to the respective superior operation(refers to AFVC-APLZL).
    AFVC-APLZL is a unique number for each operation.
    Hope this helps. You can check with some existing/new orders as well.
    let me know if you need anything about split operations as well.
    Best Regards,
    Subhakanth

  • Determination of Consumption indicator in Material document (MSEG)

    My question is about how the Consumption indicator gets set in a material document.  Everything comes from somewhere in SAP...
    I have two movement types, 901 and 900.  900 is configured to be the reversal movement for 901.  Both these movement types have Consumption posting indicator "G - Planned withdrawal (total consumption)" in OMJJ movement type configuration (field T156X-KZVBR).
    When the 901 movement is done, the consumption indicator in MSEG is [[blank]] (field MSEG-KZVBR).  When the 900 movement is done, the consumption indicator in MSEG is V = Consumption.  Why are they not the same?  How does the entry in MSEG-KZVBR get determined, if not from T156X-KZVBR?
    Other information:  both movements are delivery movements.  901 is typically done from transaction VL02N Delivery change or VL06G Goods issue due list, while 900 is done using transaction VL09 Reverse delivery goods issue.
    Thank you in advance if you are able to help.

    @Esther,
    For the delivery in question, LIPS-KZVBR is blank.  This corresponds fine to the related field in MSEG being blank on the goods issue.  But where could the the "V" indicator on the GI reversal come from?  Both movements are for the same delivery item. 
    I have tried clearing out the "G" indicator in the movement type config (T156X-KZVBR) for first the 900 reversal movement, and then the 901 GI movement too, and still they post the same way, with the 901 GI having a blank and the 900 reverse GI having a V.  Based on this I'm ready to conclude that the movement type config Consumption indicator does nothing, which shouldn't be the case?
    @Indraneel,
    I'm aware of the configuration of account assignment categories in Purchasing (in table T163K) and the Consumption indicator there, but how could that be playing a role in these Delivery-related movements?  If there's a connection, maybe that's the missing link I'm seeking?
    Thank you both for your replies!

  • Reg : BOM and production order

    Hi all,
    I have created two production orders for the same material but with diffrent BOM explosion date. now can any one please let me know how will i find which version of alternate BOM of the material is used in the production order.
    In the production order header table ( AFKO) i am getting only the alternate BOM number, i am ubable to find which version of alternate BOM is used for Production order.
    Thanks .
    VIJAY

    the relation is as below
    AFKO-STLNR = STAS-STLNR
    AFKO-STLTY = STAS-STLTY
    AFKO-STLAL= STAS-STLAL
    FROM HERE TAKE ALL
    STAS-STLKN AND STAS-STLTY
    PASS IT TO STPO
    STPO-STLNR = STAS-STLNR
    SPO-STLTY = STAS-STLTY
    STAS-STLKN-= STPO-STKLN
    THIS WILL GIVE YOU ALL THE BOM ITEMS USED IN THAT PROD ORDER.
    IS IT OKAY?

  • Hi Question On Alv Report

    Hi Abapers,
                         I am having a requirement that having  Check boxe in REUSE_ALV_GRID_DISPLAY ,so i need to select the records Required using the check box.  how to Track the records selected using the check box......
    Thanks & Regards
    Bhaskar Rao.M

    hi
    good
    go through this
    tables used -
    tables: mkpf,
            mseg,
            lfa1,
            makt.
    global hashed tables used
    data: begin of wa_mkpf, "header
          mblnr like mkpf-mblnr,
          mjahr like mkpf-mjahr,
          budat like mkpf-budat,
          xblnr like mkpf-xblnr,
          end of wa_mkpf.
    data: ht_mkpf like hashed table of wa_mkpf
          with unique key mblnr mjahr
          with header line.
    data: st_mkpf like standard table of wa_mkpf
          with header line.
    data: begin of wa_mseg, " line items
          mblnr like mseg-mblnr,
          mjahr like mseg-mjahr,
          zeile like mseg-zeile,
          bwart like mseg-bwart,
          charg like mseg-charg,
          matnr like mseg-matnr,
          lifnr like mseg-lifnr,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          end of wa_mseg.
    data ht_mseg like hashed table of wa_mseg
          with unique key mblnr mjahr zeile
          with header line.
    data st_mseg like standard table of wa_mseg
          with header line.
    cache structure for lfa1 records
    data: begin of wa_lfa1,
          lifnr like lfa1-lifnr,
          name1 like lfa1-name1,
          end of wa_lfa1.
    data ht_lfa1 like hashed table of wa_lfa1
          with unique key lifnr
          with header line.
    cache structure for material related data
    data: begin of wa_material,
          matnr like makt-matnr,
          maktx like makt-maktx,
          end of wa_material.
    data: ht_material like hashed table of wa_material
            with unique key matnr
            with header line.
    result table
    data: begin of wa_lst, "
          budat like mkpf-budat,
          mblnr like mseg-mblnr,
          lifnr like mseg-lifnr,
          name1 like lfa1-name1,     
          xblnr like mkpf-xblnr,
          zeile like mseg-zeile,
          charg like mseg-charg,
          matnr like mseg-matnr,
          maktx like makt-maktx,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          mjahr like mseg-mjahr,
          end of wa_lst.
    data: ht_lst like hashed table of wa_lst
            with unique key mblnr mjahr zeile
            with header line.
    data: begin of wa_lst1, " sumary by material
          matnr like mseg-matnr,
          maktx like makt-maktx,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          color_line(4) TYPE c,           " Line color
          color_cell    TYPE lvc_t_scol,  " Cell color
          celltab type LVC_T_STYL,
          end of wa_lst1.
    data: ht_lst1 like hashed table of wa_lst1
            with unique key matnr
            with header line.
    structures for alv grid display.
    itabs
    type-pools: slis.
    data: it_lst            like standard table of wa_lst with header line,
          it_fieldcat_lst   type slis_t_fieldcat_alv with header line,
          it_sort_lst       type slis_t_sortinfo_alv,
          it_lst1           like standard table of wa_lst1 with header line,
          it_fieldcat_lst1  type slis_t_fieldcat_alv with header line,
          it_sort_lst1      type slis_t_sortinfo_alv.
    structures
    data: wa_sort         type slis_sortinfo_alv,
          ls_layout       type slis_layout_alv.
    color management.
    DATA  : wa_color    TYPE lvc_s_scol.
    Internal table for color management.
    DATA : it_color    TYPE TABLE          OF lvc_s_scol.
    itab for input enabling.
    DATA: lt_celltab TYPE lvc_t_styl. "
    global varialbes
    data: g_lines type i.
    data: g_repid like sy-repid,
          ok_code       like sy-ucomm.
    selection-screen
    "text: Dates:
    select-options: so_budat for mkpf-budat default sy-datum.
    "text: Material numbers.
    select-options: so_matnr for mseg-matnr.
    selection-screen uline.
    selection-screen skip 1.
    "Text: show summary by material.
    parameters: gp_bymat as checkbox default ''.
    parameters: gp_hier  as checkbox default 'X'.
    start-of-selection.
      perform get_data.
      perform show_data.
    end-of-selection.
          FORM get_data                                                 *
    form get_data.
           select mblnr mjahr budat xblnr
                into table ht_mkpf
               from mkpf
              where budat in so_budat. " make use of std index.
    have we retrieved data from mkpf?
      describe table ht_mkpf lines g_lines.
      if g_lines > 0.
    if true then retrieve all related records from mseg.
    Doing this way we make sure that the access is by primary key
    of mseg.
    The reason is that is faster to filter them in memory
    than to allow the db server to do it.
        select mblnr mjahr zeile bwart charg
                 matnr lifnr erfmg erfme
          into table ht_mseg
          from mseg
            for all entries in ht_mkpf
         where mblnr = ht_mkpf-mblnr
           and mjahr = ht_mkpf-mjahr.
      endif.
    fill t_lst or t_lst1 according to user's choice.
      if gp_bymat = ' '.
        perform fill_ht_lst.
      else.
        perform fill_ht_lst1.
      endif.
    endform.
    form fill_ht_lst.
      refresh ht_lst.
    Example: how to discard unwanted data in an efficient way.
      loop at ht_mseg.
      filter unwanted data
        check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
        check ht_mseg-matnr in so_matnr.
      read header line.
        read table ht_mkpf with table key mblnr = ht_mseg-mblnr
        mjahr = ht_mseg-mjahr.
        clear ht_lst.
    * note : this may be faster if you specify field by field.
        move-corresponding ht_mkpf to ht_lst.
        move-corresponding ht_mseg to ht_lst.
        perform read_lfa1 using ht_mseg-lifnr changing ht_lst-name1.
        perform read_material using ht_mseg-matnr changing ht_lst-maktx.
        insert table ht_lst.
      endloop.
    endform.
    form fill_ht_lst1.
    data: colorear.
      refresh ht_lst1.
    Example: how to discard unwanted data in an efficient way.
             hot to simulate a collect in a faster way
      loop at ht_mseg.
      filter unwanted data
        check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
        check ht_mseg-matnr in so_matnr.
    * note : this may be faster if you specify field by field.
        read table ht_lst1 with table key matnr = ht_mseg-matnr
        transporting erfmg.
        if sy-subrc <> 0. " if matnr doesn't exist in sumary table
        " insert a new record
          clear ht_lst1.
          ht_lst1-matnr = ht_mseg-matnr.
          perform read_material using ht_mseg-matnr changing ht_lst1-maktx.
          ht_lst1-erfmg = ht_mseg-erfmg.
          ht_lst1-erfme = ht_mseg-erfme.
          if colorear = ''.
            colorear = 'X'.
            refresh it_color.
            ht_lst1-color_cell[] = it_color[].
            MOVE 'C410' TO ht_lst1-color_line.
          else.
            colorear = ' '.
            refresh it_color. clear it_color.
            MOVE 'MATNR' TO wa_color-fname.
            MOVE '6'         TO wa_color-color-col.
            MOVE '1'         TO wa_color-color-int.
            MOVE '1'         TO wa_color-color-inv.
            APPEND wa_color TO it_color.
            MOVE 'MAKTX' TO wa_color-fname.
            MOVE '3'         TO wa_color-color-col.
            MOVE '1'         TO wa_color-color-int.
            MOVE '1'         TO wa_color-color-inv.
            APPEND wa_color TO it_color.
            MOVE 'ERFMG' TO wa_color-fname.
            MOVE '5'         TO wa_color-color-col.
            MOVE '1'         TO wa_color-color-int.
            MOVE '1'         TO wa_color-color-inv.
            APPEND wa_color TO it_color.
            ht_lst1-color_cell[] = it_color[].
            clear ht_lst1-color_line.
          endif.
          insert table ht_lst1.
        else." a record was found.
        " collect erfmg.  To do so, fill in the unique key and add
        " the numeric fields.
          ht_lst1-matnr = ht_mseg-matnr.
          add ht_mseg-erfmg to ht_lst1-erfmg.
          modify table ht_lst1 transporting erfmg.
        endif.
      endloop.
    endform.
    implementation of cache for lfa1.
    form read_lfa1 using p_lifnr changing p_name1.
           read table ht_lfa1 with table key lifnr = p_lifnr
            transporting name1.
      if sy-subrc <> 0.
        clear ht_lfa1.
        ht_lfa1-lifnr = p_lifnr.
        select single name1
           into ht_lfa1-name1
          from lfa1
        where lifnr = p_lifnr.
        if sy-subrc <> 0. ht_lfa1-name1 = 'n/a in lfa1'. endif.
        insert table ht_lfa1.
      endif.
      p_name1 = ht_lfa1-name1.
    endform.
    implementation of cache for material data
    form read_material using p_matnr changing p_maktx.
      read table ht_material with table key matnr = p_matnr
      transporting maktx.
      if sy-subrc <> 0.
        ht_material-matnr = p_matnr.
        select single maktx into  ht_material-maktx
          from makt
         where spras = sy-langu
           and matnr = p_matnr.
        if sy-subrc <> 0. ht_material-maktx = 'n/a in makt'. endif.
        insert table ht_material.
      endif.
      p_maktx = ht_material-maktx.
    endform.
    form show_data.
      if gp_hier = 'X'. "no anda.
       perform show_hierarchicalALV.
      else.
        if gp_bymat = ' '.
          perform show_ht_lst.
        else.
          perform show_ht_lst1.
        endif.
      endif.
    endform.
    form show_hierarchicalALV.
    st_mkpf[] = ht_mkpf[].
    st_mseg[] = ht_mseg[].
    call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    exporting
      I_INTERFACE_CHECK              = ' '
      I_CALLBACK_PROGRAM             =
      I_CALLBACK_PF_STATUS_SET       = ' '
      I_CALLBACK_USER_COMMAND        = ' '
      IS_LAYOUT                      =
      IT_FIELDCAT                    =
      IT_EXCLUDING                   =
      IT_SPECIAL_GROUPS              =
      IT_SORT                        =
      IT_FILTER                      =
      IS_SEL_HIDE                    =
      I_SCREEN_START_COLUMN          = 0
      I_SCREEN_START_LINE            = 0
      I_SCREEN_END_COLUMN            = 0
      I_SCREEN_END_LINE              = 0
      I_DEFAULT                      = 'X'
      I_SAVE                         = ' '
      IS_VARIANT                     =
      IT_EVENTS                      =
      IT_EVENT_EXIT                  =
       i_tabname_header               =
       i_tabname_item                 =
      I_STRUCTURE_NAME_HEADER        =
      I_STRUCTURE_NAME_ITEM          =
       is_keyinfo                     =
      IS_PRINT                       =
      IS_REPREP_ID                   =
      I_BUFFER_ACTIVE                =
      I_BYPASSING_BUFFER             =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER        =
      ES_EXIT_CAUSED_BY_USER         =
      tables
        t_outtab_header                = st_mkpf
        t_outtab_item                  = st_mseg
    EXCEPTIONS
      PROGRAM_ERROR                  = 1
      OTHERS                         = 2
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    endform.
    form show_ht_lst.
      "needed because the FM can't use a hashed table.
      it_lst[] = ht_lst[].
      perform fill_layout using 'full display'
                           changing ls_layout.
      perform fill_columns_lst.
    perform sort_lst.
      g_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program       = g_repid
                i_callback_pf_status_set = 'SET_PF_STATUS'
                is_layout                = ls_layout
                it_fieldcat              = it_fieldcat_lst[]
               it_sort                  = it_sort_lst
           tables
                t_outtab                 = it_lst
           exceptions
                program_error            = 1
                others                   = 2.
    endform.
    form show_ht_lst1.
      "needed because the FM can't use a hashed table.
      it_lst1[] = ht_lst1[].
      perform fill_layout using 'Sumary by matnr'
                           changing ls_layout.
      perform fill_columns_lst1.
    perform sort_lst.
      g_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program       = g_repid
                i_callback_pf_status_set = 'SET_PF_STATUS'
                is_layout                = ls_layout
                it_fieldcat              = it_fieldcat_lst1[]
               it_sort                  = it_sort_lst
           tables
                t_outtab                 = it_lst1
           exceptions
                program_error            = 1
                others                   = 2.
    endform.
    form fill_layout using p_window_titlebar
                   changing cs_layo type slis_layout_alv.
      clear cs_layo.
      cs_layo-window_titlebar        = p_window_titlebar.
      cs_layo-edit                   = 'X'.
      cs_layo-edit_mode              = space.
      MOVE 'COLOR_LINE' TO cs_layo-info_fieldname.
    Field that identify cell color in inetrnal table
      MOVE 'COLOR_CELL' TO cs_layo-coltab_fieldname.
    move 'CELLTAB' TO cs_layo-stylefname.
    endform.                    " armar_layout_stock
    form set_pf_status using rt_extab type slis_t_extab.
    create a new status
    and then select extras -> adjust template -> listviewer
      set pf-status 'VISTA'.
    endform.        "set_pf_status
    define add_lst.
      clear it_fieldcat_lst.
      it_fieldcat_lst-fieldname     = &1.
      it_fieldcat_lst-outputlen     = &2.
      it_fieldcat_lst-ddictxt       = 'L'.
      it_fieldcat_lst-seltext_l       = &1.
      it_fieldcat_lst-seltext_m       = &1.
      it_fieldcat_lst-seltext_m       = &1.
      if &1 = 'MATNR'.
        it_fieldcat_lst-emphasize = 'C111'.
      endif.
      append it_fieldcat_lst.
    end-of-definition.
    define add_lst1.
      clear it_fieldcat_lst.
      it_fieldcat_lst1-fieldname     = &1.
      it_fieldcat_lst1-outputlen     = &2.
      it_fieldcat_lst1-ddictxt       = 'L'.
      it_fieldcat_lst1-seltext_l       = &1.
      it_fieldcat_lst1-seltext_m       = &1.
      it_fieldcat_lst1-seltext_m       = &1.
      append it_fieldcat_lst1.
    end-of-definition.
    form fill_columns_lst.
    set columns for output.
      refresh it_fieldcat_lst.
      add_lst 'BUDAT' 10.
      add_lst   'MBLNR' 10.
      add_lst  'LIFNR' 10.
      add_lst  'NAME1' 35.
      add_lst  'XBLNR' 15.
      add_lst    'ZEILE' 5.
      add_lst    'CHARG' 10.
      add_lst   'MATNR' 18.
      add_lst   'MAKTX' 30.
      add_lst   'ERFMG' 17.
      add_lst   'ERFME' 5.
      add_lst   'MJAHR' 4.
    endform.
    form fill_columns_lst1.
    set columns for output.
      refresh it_fieldcat_lst1.
      add_lst1 'MATNR' 18.
      add_lst1 'MAKTX' 30.
      add_lst1 'ERFMG' 17.
      add_lst1 'ERFME' 5..
    endform.
    thanks
    mrutyun^

  • ALV Report in PP module

    Hi everyone.
    I need to develop an ALV report. Select options are -
    AFPO-DWERK (plant) (Obligatory)
    AFPO-AUFNR (Prd Ord Num) (optional)
    AFKO-STLBEZ (Mat Nr) (optional)
    S022-ARBPL (Work Center) (optional)
    I have extracted all open production orders from AUFK and placed them in an internal table.
    Now how can I filter this list to the select options.
    Please help me.
    Related Tables  - AUFK, AFPO, AFKO.
    Thanks,
    Lakshmi

    just go to www.alvrobot.com.ar
    and the page will generate the code for you....

  • Alv report in PP

    ·     I have a requirement to prepare alv report to know the Production order details having the status REL (Released), CSER (Error in cost calculation).
    someone let me know the tables and the fields that i need to use in this report.
    thank you.

    hi,
    check these tables related to pp.
    AFKO         Order Header
    AFPO          Order Item Detail
    AFFW         Confirmations -- Goods Movements with Errors
    AFRC          Confirmations -- Incorrect Cost Calculations .

  • Alv report please help

    Hi,
         Please help me in this.
    1) Create the selection screen with the following fields on it.
         S_REQUESTOR for ZSWAPHISTORY- REQUESTOR
         S_APPROVER for ZSWAPHISTORY- APPROVER providing range
         S_to_customer for ZSWAPHISTORY- to_customer providing range
         S_from_customer for ZSWAPHISTORY- from_customer providing range
         S_MRPC     for MARC-DISPO providing range
         S_MATNR     for MARA-MATNR providing range
         S_APPR_DATE for ZSWAPHISTORY- APPR_DATE Default to yesterdays date
         S_QUAN     for ZSWAPHISTORY-quan
    2) Validate the fields entered in the selection screen.
    3) Check the user authorizations for this report.
    4) Select the entries from the table ZSWAPHISTORY into an internal table based on the input from the selection screen and the value of the field ZSWAPHISTORY -STATUS is APPROVED.
    5) Then select the MRP Controller ID (DISPO) from the Table MARC for all entries in the internal table where MARC-MATNR equals to the internal table -material number.
    6) Move the field value of MRP Controller ID (DISPO) into the final internal table for the corresponding entries.
    7) Declare the Filed Catalogue with the fields that are to be displayed in the ALV
    Please help to create this , iam new to this area.
    Thanks
    Ali

    Hi
    See the sample code of ALV and do accordingly
    Since you are using a Z table it is not clear to create
    report ZRGRIRNA no standard page heading
           line-count 65
           line-size 255
           message-id mm.
                       GR IR Detail Report                               *
    Description          : The output has to be displayed
                           in the ALV Grid format with the Selection     *
                           screen appearing on the output. In The Output *
                           Subtotals for Vendor, Plant, Period, Material,*
                           Valuation Class, Purchase Order,Cost Center,  *
                           Cost Element and Receipt Date are displayed   *
                           after sorting the data by same fields.        *
    Declaration for Tables
    tables: t001,      " Company Codes
            t001w,     " Plants/Branches
            lfa1,      " Vendor Master
            ska1,      " GL Account Master
            mara,      " Material Master
            mbew,      " Material Valuation
            ekko,      " PO Header Data
            cska,      " Cost Elements
            csks,      " Cost Centers
            bsis,      " GL Accounts: Open Items Data
            bkpf.      " Accounting Doc: Header Data
    Type-pools
    Type pools for ALV display
    type-pools : slis.
    Global variables
    data: g_repid       like sy-repid,
          g_exit        type c,
          g_events      type slis_t_event,
          g_list_top_of_page type slis_t_listheader,
          g_exit_caused_by_caller,
          g_exit_caused_by_user type slis_exit_by_user,
          g_top_of_page  type slis_formname value 'TOP_OF_PAGE',
          g_variant like disvariant,
          g_save.
    Declaration for Constants
    constants : c_x  type c  value 'X',         " Flag
                c_c  type c  value 'C',         " Flag
                c_l  type c  value 'L',         " Flag
                c_a  type c  value 'A',         " Line Type
                c_h  type c  value 'H',         " Dr/Cr
                c_s  type c  value 'S',         " Line Type
                c_mkpf(4) type c value 'MKPF'.  " Table
    Declaration of Internal Tables
    Internal Table for BSIS Table data
    data: begin of i_bsis occurs 0,
            bukrs like bsis-bukrs,          " Company Code
            hkont like bsis-hkont,          " GR IR Account
            gjahr like bsis-gjahr,          " Fiscal Year
            belnr like bsis-belnr,          " Acc Document
            buzei like bsis-buzei,          " Item No
            budat like bsis-budat,          " Receipt Date(Posting)
            monat like bsis-monat,          " Period
          end of i_bsis.
    Internal Table for BSEG Table data
    data: begin of i_bseg occurs 0,
            bukrs like bsis-bukrs,          " Company Code
            belnr like bsis-belnr,          " Acc Document
            buzei like bsis-buzei,          " Item No
            gjahr like bsis-gjahr,          " Fiscal Year
            shkzg like bseg-shkzg,          " Dr/Cr Indicator
            lifnr like bseg-lifnr,          " Vendor Code
            matnr like bseg-matnr,          " Material No
            ebeln like bseg-ebeln,          " Purchase Order
            ebelp like bseg-ebelp,          " PO Item
            werks like bseg-werks,          " Plant
            menge like bseg-menge,          " PO Quantity
            meins like bseg-meins,          " UOM
            dmbtr like bseg-dmbtr,          " Amount in Local Currency
            wrbtr like bseg-wrbtr,          " Amount in Trans.Currency
          end of i_bseg.
    Internal Table for BKPF Table data
    data: begin of i_bkpf occurs 0,
            bukrs like bkpf-bukrs,          " Company Code
            belnr like bkpf-belnr,          " Acc Document
            gjahr like bkpf-gjahr,          " Fiscal Year
            waers like bkpf-waers,          " Trans. Currency
            awkey like bkpf-awkey,          " Object Key
            awtyp like bkpf-awtyp,          " Reference Procedure
          end of i_bkpf.
    Internal Table for MSEG Table data
    data: begin of i_mseg occurs 0,
            mblnr like mseg-mblnr,          " Material Document
            mjahr like mseg-mjahr,          " Fiscal Year
            bwart like mseg-bwart,          " Movement Type
            matnr like mseg-matnr,          " Material No
            menge like mseg-menge,          " PO Quantity
            meins like mseg-meins,          " UOM
          end of i_mseg.
    Internal Table for MBEW Table data
    data: begin of i_mbew occurs 0,
            matnr like mbew-matnr,          " Material No
            werks like mbew-bwkey,          " Plant
            bklas like mbew-bklas,          " Valuation Class
          end of i_mbew.
    Internal Table for EKPO Table data
    data: begin of i_ekpo occurs 0,
            ebeln like ekpo-ebeln,          " Purchase Order
            ebelp like ekpo-ebelp,          " PO Item
            matnr like ekpo-matnr,          " Material No
            txz01 like ekpo-txz01,          " Material Text
          end of i_ekpo.
    Internal Table for EKKN Table data
    data: begin of i_ekkn occurs 0,
            ebeln like ekkn-ebeln,          " Purchase Order
            ebelp like ekkn-ebelp,          " PO Item
            kostl like ekkn-kostl,          " Cost Center
            sakto like ekkn-sakto,          " Cost Element
          end of i_ekkn.
    Internal Table for LFA1 Table data
    data: begin of i_lfa1 occurs 0,
            lifnr like lfa1-lifnr,          " Vendor
            name1 like lfa1-name1,          " Name
          end of i_lfa1.
    Declaration of Output Internal Table
    data: begin of i_final occurs 0,
            lifnr like lfa1-lifnr,     " Vendor
            werks like bseg-werks,     " Plant
            monat like bsis-monat,     " Period
            matnr like mara-matnr,     " Material Number
            bklas like mbew-bklas,     " Val Class
            ebeln like bseg-ebeln,     " PO
            kostl like ekkn-kostl,     " Cost Center
            sakto like ekkn-sakto,     " Cost Element
            budat like bsis-budat,     " Rec. Date
            name1 like lfa1-name1,     " Vendor Name
            belnr like bsis-belnr,     " FI Document
            bwart like mseg-bwart,     " Movement Type
            txz01 like ekpo-txz01,     " Material Text
            menge like bseg-menge,     " Quantity
            meins like bseg-meins,     " UOM
            dmbtr like bseg-dmbtr,     " Local Amount
            wrbtr like bseg-wrbtr,     " Tran.Amount
            waers like bkpf-waers,     " Tran.Currency
            status type c,             " Material Status
          end of i_final.
    Internal table to hold field catgory data
    data:  i_fldcat  type slis_t_fieldcat_alv.   " Table - field catgory
    Internal table to hold Sort/Subtotals criteria data
    data:  i_sort  type slis_t_sortinfo_alv.     " Table - sort/Subtotals
    Structure
    data:  x_layout   type slis_layout_alv,      " Structure-layout
           x_fldcat   like line of i_fldcat,     " Structure-field catagory
           x_sort     like line of i_sort.       " Structure-Sort/Subtotals
           Selection screen
    selection-screen : begin of block b1 with frame title text-000.
    parameters:
       p_bukrs like t001-bukrs obligatory,          " Company Code
       p_grira like ska1-saknr default '0241101000' obligatory. " Account
    select-options:
       s_budat for bkpf-budat,        " Posting Date
       s_werks for t001w-werks,       " Plant
       s_lifnr for lfa1-lifnr,        " Vendor
       s_matnr for mara-matnr,        " Material Number
       s_kostl for csks-kostl,        " Cost Center
       s_kstar for cska-kstar,        " Cost Element
       s_ebeln for ekko-ebeln,        " Purchase Order
       s_monat for bsis-monat.        " Period
    selection-screen skip.
    parameters:
       p_incmt as checkbox default 'X',
       p_incnm as checkbox default 'X'.
    selection-screen end of block b1.
    Initialization
    initialization.
      g_repid = sy-repid.
      perform layout_init using x_layout.
      perform eventtab_build using g_events[].
      g_variant-report = g_repid.
      g_save           = 'A'.
    At selection screen
    at selection-screen.
    Validation of Selection Screen Fields
      perform validate_screen.
    Start of selection
    start-of-selection.
    Read Data from Database Tables
      perform read_data.
    End of selection
    end-of-selection.
    Build layout report layout.
      perform populate_layout_stucture.
    Perform build_field_catalog and Sort Table
      perform build_field_catalog.
      perform build_sort_totals.
    List Header for Top-Of-Page
      perform comment_build using g_list_top_of_page[].
    Call list viewer function module
      perform call_list_viewer .
    ****************Form - Routines**************************************
          Form        : layout_init
          Description : Form to Build layout for list display
    form layout_init using rs_layout type slis_layout_alv.
      rs_layout-detail_popup      = c_x.
    endform.
    Form         : Eventtab_build
    Description  : Registration of events to happen during list display
    form eventtab_build using rt_events type slis_t_event.
    Registration of events to happen during list display
      data: ls_event type slis_alv_event.
      call function 'REUSE_ALV_EVENTS_GET'
           exporting
                i_list_type = 0
           importing
                et_events   = rt_events.
      read table rt_events with key name = slis_ev_top_of_page
                               into ls_event.
      if sy-subrc = 0.
        move g_top_of_page to ls_event-form.
        append ls_event to rt_events.
      endif.
    endform.                                   "eventtab_build
          Form : top_of_page
    form top_of_page.
      call function 'REUSE_ALV_COMMENTARY_WRITE'
           exporting
             I_LOGO             = 'ENJOYSAP_LOGO'
                it_list_commentary = g_list_top_of_page.
    endform.
          Form validate_screen
    Validation of Selection Screen fields
    form validate_screen.
    Validation of Company Code
      clear t001.
      if not p_bukrs is initial.
        select single bukrs
          into t001-bukrs
          from t001
          where bukrs eq p_bukrs.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Company Code'(012).
        endif.
      endif.
    Validation of GL Account (GR/IR)
      clear ska1.
      if not p_grira is initial.
        select saknr
          into ska1-saknr
          from ska1
          up to 1 rows
          where saknr eq p_grira.
        endselect.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid GR/IR Account'(013).
        endif.
      endif.
    Validation of Vendor Code
      clear lfa1.
      if not s_lifnr[] is initial.
        select single lifnr
          into lfa1-lifnr
          from lfa1
          where lifnr in s_lifnr.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Vendor'(001).
        endif.
      endif.
    Validation of Plant Code
      clear t001w.
      if not s_werks[] is initial.
        select single werks
          into t001w-werks
          from t001w
          where werks in s_werks.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Plant'(014).
        endif.
      endif.
    Validation of Material Code
      clear mara.
      if not s_matnr[] is initial.
        select single matnr
          into mara-matnr
          from mara
          where matnr in s_matnr.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Material'(015).
        endif.
      endif.
    Validation of Purchase Order
      clear ekko.
      if not s_ebeln[] is initial.
        select single ebeln
          into ekko-ebeln
          from ekko
          where ebeln in s_ebeln.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Purchase Order'(016).
        endif.
      endif.
    Validation of Cost Center
      clear csks.
      if not s_kostl[] is initial.
        select kostl
          into csks-kostl
          from csks
          up to 1 rows
          where kostl in s_kostl.
        endselect.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Cost Center'(017).
        endif.
      endif.
    Validation of Cost Element
      clear cska.
      if not s_kstar[] is initial.
        select kstar
          into cska-kstar
          from cska
          up to 1 rows
          where kstar in s_kstar.
        endselect.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Cost Element'(018).
        endif.
      endif.
    endform.                          "validate_screen
    *&      Form  read_data
    Read the Data from the database Tables
    form read_data.
    Get the Accounting Documents for the GR/IR Account Entered on
    Selection Screen
      clear i_bsis.
      refresh i_bsis.
      select bukrs           " Company Code
             hkont           " GR IR Account
             gjahr           " Fiscal Year
             belnr           " Acc Document
             buzei           " Item No
             budat           " Receipt Date(Posting)
             monat           " Period
       into table i_bsis
       from  bsis
       where  bukrs = p_bukrs
         and  hkont = p_grira
         and  budat in s_budat
         and  monat in s_monat .
      if sy-subrc <> 0.
        message i899 with 'No data found'(043).
        g_exit = c_x.
        stop.
      endif.
      sort i_bsis by bukrs hkont gjahr belnr buzei.
    Get the Vendor,PO,Material,Qty details from BSEG Table
      if not i_bsis[] is initial.
        clear i_bseg.
        refresh i_bseg.
        select bukrs           " Company Code
               belnr           " Acc Document
               buzei           " Item No
               gjahr           " Fiscal Year
               shkzg           " Dr/Cr Indicator
               lifnr           " Vendor Code
               matnr           " Material No
               ebeln           " Purchase Order
               ebelp           " PO Item
               werks           " Plant
               menge           " PO Quantity
               meins           " UOM
               dmbtr           " Amount in Local Currency
               wrbtr           " Amount in Trans.Currency
        into table i_bseg
        from   bseg
        for all entries in i_bsis
        where  bukrs = p_bukrs
        and    belnr = i_bsis-belnr
        and    gjahr = i_bsis-gjahr
        and    buzei = i_bsis-buzei
        and    lifnr in s_lifnr
        and    werks in s_werks
        and    matnr in s_matnr
        and    ebeln in s_ebeln.
        sort i_bseg by bukrs belnr buzei gjahr.
    Select the Trans.Currency from BKPF Table
        clear i_bkpf.
        refresh i_bkpf.
        select bukrs           " Company Code
               belnr           " Acc Document
               gjahr           " Fiscal Year
               waers           " Trans. Currency
               awkey           " Object Key
               awtyp           " Reference Procedure
        into table i_bkpf
        from   bkpf
        for all entries in i_bsis
        where  bukrs = p_bukrs
        and    belnr = i_bsis-belnr
        and    gjahr = i_bsis-gjahr.
      endif.
      sort i_bkpf by bukrs belnr gjahr.
    Get the Quantity and UOM of Material from MSEG Table
      if not i_bkpf[] is initial.
        clear i_mseg.
        refresh i_mseg.
        select mblnr           " Material Document
               mjahr           " Fiscal Year
               bwart           " Movement Type
               matnr           " Material No
               menge           " PO Quantity
               meins           " UOM
          into table i_mseg
          from   mseg
          for all entries in i_bkpf
          where  mblnr = i_bkpf-awkey(10).
      endif.
      sort i_mseg by mblnr mjahr.
    Get the Material And Description from EKPO Table
      if not i_bseg[] is initial.
        clear i_ekpo.
        refresh i_ekpo.
        select ebeln           " Purchase Order
               ebelp           " PO Item
               matnr           " Material No
               txz01           " Material Text
        into table i_ekpo
        from   ekpo
        for all entries in i_bseg
        where  ebeln = i_bseg-ebeln
        and    ebelp = i_bseg-ebelp.
        sort i_ekpo by ebeln ebelp.
    Get the Valuation Class from MBEW Table
        clear i_mbew.
        refresh i_mbew.
        select matnr           " Material No
               bwkey           " Plant
               bklas           " Valuation Class
        into table i_mbew
        from   mbew
        for all entries in i_bseg
        where  matnr = i_bseg-matnr
        and    bwkey = i_bseg-werks.
        sort i_mbew by matnr werks.
    Get the Cost Center and Cost Element of the PO from EKKN Table
        clear i_ekkn.
        refresh i_ekkn.
        select ebeln           " Purchase Order
               ebelp           " PO Item
               kostl           " Cost Center
               sakto           " Cost Element
        into table i_ekkn
        from   ekkn
        for all entries in i_bseg
        where  ebeln = i_bseg-ebeln
        and    ebelp = i_bseg-ebelp
        and    kostl in s_kostl
        and    sakto in s_kstar.
        sort i_ekkn by ebeln ebelp.
    Get the Vendor Name
        clear i_lfa1.
        refresh i_lfa1.
        select lifnr            " Vendor
               name1            " Name
        into table i_lfa1
        from   lfa1
        for all entries in i_bseg
        where  lifnr = i_bseg-lifnr.
      endif.
      sort i_lfa1 by lifnr.
    Move the data to Final Output Internal Table
      loop at i_bsis.
        i_final-belnr = i_bsis-belnr.     " FI Document
        i_final-monat = i_bsis-monat.     " Period
        i_final-budat = i_bsis-budat.     " Rec. Date
    Read the Transaction Currency from BKPF Internal Table
        read table i_bkpf with key bukrs = i_bsis-bukrs
                                   belnr = i_bsis-belnr
                                   gjahr = i_bsis-gjahr
                                   binary search.
        if sy-subrc = 0.
          i_final-waers = i_bkpf-waers.     " Tran.Currency
    Read the Movement Type for all Material Related
    Documents from MSEG Internal Table
          if i_bkpf-awtyp = c_mkpf.
            read table i_mseg with key mblnr = i_bkpf-awkey(10)
                                       mjahr = i_bkpf-awkey+10(4).
            if sy-subrc = 0.
              i_final-bwart = i_mseg-bwart.     " Movement Type
            endif.
          endif.
        endif.
    Read Vendor, Plant, PO Document, Local And Trans.Amounts
    from BSEG Internal Table
        read table i_bseg with key bukrs = i_bsis-bukrs
                                   belnr = i_bsis-belnr
                                   gjahr = i_bsis-gjahr
                                   buzei = i_bsis-buzei
                                   binary search.
        if sy-subrc = 0.
          i_final-lifnr = i_bseg-lifnr.     " Vendor
          i_final-werks = i_bseg-werks.     " Plant
          i_final-ebeln = i_bseg-ebeln.     " PO
          i_final-dmbtr = i_bseg-dmbtr.     " Local Amount
          i_final-wrbtr = i_bseg-wrbtr.     " Tran.Amount
          i_final-menge = i_bseg-menge.     " Quantity
          i_final-meins = i_bseg-meins.     " UOM
    For Credit Indicator(SHKZG = H) amounts should be (-)ve
          if i_bseg-shkzg = c_h.
            i_final-dmbtr = i_final-dmbtr * -1.
            i_final-wrbtr = i_final-wrbtr * -1.
            i_final-menge = i_final-menge * -1.
          endif.
    Read the Material and its Description from EKPO Internal Table
          read table i_ekpo with key ebeln = i_bseg-ebeln
                                     ebelp = i_bseg-ebelp
                                     matnr = i_bseg-matnr
                                     binary search.
          if sy-subrc = 0.
            i_final-matnr = i_ekpo-matnr.     " Material Number
            i_final-txz01 = i_ekpo-txz01.     " Material Text
    Populate the Material Status depending on the Input Checkbox
    On Selection Screen
            if not i_ekpo-matnr is initial.
              i_final-status = c_x.
            endif.
          endif.
    Read the PO related Cost Element and Cost Centers
    from EKKN Internal Table
          read table i_ekkn with key ebeln = i_bseg-ebeln
                                     ebelp = i_bseg-ebelp
                                     binary search.
          if sy-subrc = 0.
            i_final-kostl = i_ekkn-kostl.     " Cost Center
            i_final-sakto = i_ekkn-sakto.     " Cost Element
          endif.
    Read the Valuation Class from MBEW Internal Table
          read table i_mbew with key matnr = i_bseg-matnr
                                     werks = i_bseg-werks
                                     binary search.
          if sy-subrc = 0.
            i_final-bklas = i_mbew-bklas.     " Val Class
          endif.
    Read the Vendor Name from LFA1 Internal Table
          read table i_lfa1 with key lifnr = i_bseg-lifnr
                                     binary search.
          if sy-subrc = 0.
            i_final-name1 = i_lfa1-name1.     " Vendor Name
          endif.
        endif.
        append i_final.
        clear i_final.
      endloop.
      sort i_final by lifnr werks monat matnr.
    Depending on the check Box Selected display the data
      if p_incmt = c_x and p_incnm ne c_x.
        delete i_final where matnr eq space.
      elseif p_incnm = c_x and p_incmt ne c_x.
        delete i_final where matnr ne space.
      endif.
    endform.           "Read Data
         Form        : populate_layout_stucture
         Description : Populating the layout structure
    form populate_layout_stucture.
      clear x_layout .
    Layout properties
      x_layout-zebra                = c_x.
      x_layout-detail_popup         = c_x.
      x_layout-detail_initial_lines = c_x.
      x_layout-colwidth_optimize    = c_x.
    endform.                    " populate_layout_stucture
         Form        : build_field_catalog
         Description : Building the field catalog data
    form build_field_catalog.
      call function 'REUSE_ALV_FIELDCATALOG_MERGE'
           exporting
                i_program_name         = g_repid
                i_internal_tabname     = 'I_FINAL'
                i_inclname             = g_repid
           changing
                ct_fieldcat            = i_fldcat
           exceptions
                inconsistent_interface = 1
                program_error          = 2
                others                 = 3.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
    Getting the Header text for the coloums
      loop at i_fldcat into x_fldcat where fieldname = 'LIFNR' or
                                           fieldname = 'NAME1' or
                                           fieldname = 'WERKS' or
                                           fieldname = 'MONAT' or
                                           fieldname = 'MATNR' or
                                           fieldname = 'BKLAS' or
                                           fieldname = 'EBELN' or
                                           fieldname = 'KOSTL' or
                                           fieldname = 'SAKTO' or
                                           fieldname = 'BUDAT' or
                                           fieldname = 'BELNR' or
                                           fieldname = 'BWART' or
                                           fieldname = 'TXZ01' or
                                           fieldname = 'MENGE' or
                                           fieldname = 'MEINS' or
                                           fieldname = 'DMBTR' or
                                           fieldname = 'WRBTR' or
                                           fieldname = 'WAERS' or
                                           fieldname = 'STATUS'.
        if x_fldcat-fieldname = 'LIFNR'.
          x_fldcat-seltext_l   = 'Vendor'(003).
          x_fldcat-seltext_m   = 'Vendor'(003).
          x_fldcat-seltext_s   = 'Vendor'(003).
          x_fldcat-reptext_ddic = 'Vendor'(003).
          x_fldcat-inttype   = c_c.
        endif.
        if x_fldcat-fieldname = 'NAME1'.
          x_fldcat-seltext_l   = 'Vendor Name'(002).
          x_fldcat-seltext_m   = 'Vendor Name'(002).
          x_fldcat-seltext_s   = 'Vendor Name'(002).
          x_fldcat-reptext_ddic = 'Vendor Name'(002).
          x_fldcat-inttype   = c_c.
        endif.
        if x_fldcat-fieldname = 'WERKS'.
          x_fldcat-seltext_l   = 'Plant'(010).
          x_fldcat-seltext_m   = 'Plant'(010).
          x_fldcat-seltext_s   = 'Plant'(010).
          x_fldcat-reptext_ddic   = 'Plant'(010).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'MONAT'.
          x_fldcat-seltext_l   = 'Period'(011).
          x_fldcat-seltext_m   = 'Period'(011).
          x_fldcat-seltext_s   = 'Period'(011).
          x_fldcat-reptext_ddic   = 'Period'(011).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'MATNR'.
          x_fldcat-seltext_l   = 'Material'(004).
          x_fldcat-seltext_m   = 'Material'(004).
          x_fldcat-seltext_s   = 'Material'(004).
          x_fldcat-reptext_ddic   = 'Material'(004).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BKLAS'.
          x_fldcat-seltext_l   = 'Valuation Class'(009).
          x_fldcat-seltext_m   = 'Valuation Class'(009).
          x_fldcat-seltext_s   = 'Valuation Class'(009).
          x_fldcat-reptext_ddic   = 'Valuation Class'(009).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'EBELN'.
          x_fldcat-seltext_l   = 'Purchase Order'(005).
          x_fldcat-seltext_m   = 'Purchase Order'(005).
          x_fldcat-seltext_s   = 'Purchase Order'(005).
          x_fldcat-reptext_ddic   = 'Purchase Order'(005).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'KOSTL'.
          x_fldcat-seltext_l   = 'Cost Center'(006).
          x_fldcat-seltext_m   = 'Cost Center'(006).
          x_fldcat-seltext_s   = 'Cost Center'(006).
          x_fldcat-reptext_ddic   = 'Cost Center'(006).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'SAKTO'.
          x_fldcat-seltext_l   = 'Cost Element'(007).
          x_fldcat-seltext_m   = 'Cost Element'(007).
          x_fldcat-seltext_s   = 'Cost Element'(007).
          x_fldcat-reptext_ddic   = 'Cost Element'(007).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BUDAT'.
          x_fldcat-seltext_l   = 'Receipt Date'(008).
          x_fldcat-seltext_m   = 'Receipt Date'(008).
          x_fldcat-seltext_s   = 'Receipt Date'(008).
          x_fldcat-reptext_ddic   = 'Receipt Date'(008).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BELNR'.
          x_fldcat-seltext_l   = 'Acc.Document'(100).
          x_fldcat-seltext_m   = 'Acc.Document'(100).
          x_fldcat-seltext_s   = 'Acc.Document'(100).
          x_fldcat-reptext_ddic   = 'Acc.Document'(100).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BWART'.
          x_fldcat-seltext_l   = 'Movement Type'(101).
          x_fldcat-seltext_m   = 'Movement Type'(101).
          x_fldcat-seltext_s   = 'Movement Type'(101).
          x_fldcat-reptext_ddic   = 'Movement Type'(101).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'TXZ01'.
          x_fldcat-seltext_l   = 'Material Text'(102).
          x_fldcat-seltext_m   = 'Material Text'(102).
          x_fldcat-seltext_s   = 'Material Text'(102).
          x_fldcat-reptext_ddic   = 'Material Text'(102).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'MENGE'.
          x_fldcat-seltext_l   = 'Quantity'(103).
          x_fldcat-seltext_m   = 'Quantity'(103).
          x_fldcat-seltext_s   = 'Quantity'(103).
          x_fldcat-reptext_ddic   = 'Quantity'(103).
          x_fldcat-ddictxt   = c_l.
          x_fldcat-do_sum    = c_x.
        endif.
        if x_fldcat-fieldname = 'MEINS'.
          x_fldcat-seltext_l   = 'UOM'(104).
          x_fldcat-seltext_m   = 'UOM'(104).
          x_fldcat-seltext_s   = 'UOM'(104).
          x_fldcat-reptext_ddic   = 'UOM'(104).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'DMBTR'.
          x_fldcat-seltext_l   = 'Amount in Local Curr'(105).
          x_fldcat-seltext_m   = 'Amount in Local Curr'(105).
          x_fldcat-seltext_s   = 'Amount in Local Curr'(105).
          x_fldcat-reptext_ddic   = 'Amount in Local Curr'(105).
          x_fldcat-ddictxt   = c_l.
          x_fldcat-do_sum    = c_x.
        endif.
        if x_fldcat-fieldname = 'WRBTR'.
          x_fldcat-seltext_l   = 'Amount in Trans.Curr'(106).
          x_fldcat-seltext_m   = 'Amount in Trans.Curr'(106).
          x_fldcat-seltext_s   = 'Amount in Trans.Curr'(106).
          x_fldcat-reptext_ddic   = 'Amount in Trans.Curr'(106).
          x_fldcat-ddictxt   = c_l.
          x_fldcat-do_sum    = c_x.
        endif.
        if x_fldcat-fieldname = 'WAERS'.
          x_fldcat-seltext_l   = 'Trans.Currency'(107).
          x_fldcat-seltext_m   = 'Trans.Currency'(107).
          x_fldcat-seltext_s   = 'Trans.Currency'(107).
          x_fldcat-reptext_ddic   = 'Trans.Currency'(107).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'STATUS'.
          x_fldcat-seltext_l   = 'Material Status'(019).
          x_fldcat-seltext_m   = 'Material Status'(019).
          x_fldcat-seltext_s   = 'Material Status'(019).
          x_fldcat-reptext_ddic   = 'Material Status'(019).
          x_fldcat-ddictxt   = c_l.
        endif.
        modify i_fldcat from x_fldcat index sy-tabix.
      endloop.
    endform.                    " build_field_catalog
         Form        : build_sort_totals
         Description : Building the Criteria for Sort/Subtotals
    form build_sort_totals.
      x_sort-fieldname = 'LIFNR'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  1.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'WERKS'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  2.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'MONAT'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  3.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'MATNR'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  4.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'BKLAS'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  5.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'EBELN'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  6.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'KOSTL'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  7.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'SAKTO'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  8.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'BUDAT'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  9.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
    endform.                    " build_sort_totals
      Form        : comment_build
      Description : This form is used to display the Report Header(ALV)
    form comment_build using lt_top_of_page type
                                            slis_t_listheader.
      data: l_line type slis_listheader,
            l_heading1 like rs38m-repti,
            l_date(10), l_time(8).
      clear l_line.
      l_heading1 = 'GR/IR DETAIL REPORT'(021).
      g_repid = sy-repid.
      write sy-uzeit to l_time.
      write sy-datum to l_date.
      l_line-typ = c_h.
      move l_heading1 to l_line-info.
      append l_line to lt_top_of_page.
      clear l_line.
      l_line-typ  = c_s.
      concatenate 'System:'(023) sy-sysid
                  'Date:'(024) l_date
                  ' Time:'(025)
                  l_time into l_line-info.
      append l_line to lt_top_of_page.
      concatenate 'Report:'(026) g_repid
                  ' User:'(027) sy-uname into
                  l_line-info.
      append l_line to lt_top_of_page.
      l_line-typ = c_a.
      move 'SELECTION CRITERIA:'(028) to l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Company Code : '(029)
                  p_bukrs into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' GR/IR Account: '(030)
                  p_grira into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Posting Date : '(032) s_budat-low
                  ' To: '(031) s_budat-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Plant : '(033) s_werks-low
                  ' To: '(031) s_werks-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Vendor: '(034) s_lifnr-low
                  ' To: '(031) s_lifnr-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Material: '(035) s_matnr-low
                  ' To: '(031) s_matnr-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Cost Center : '(036) s_kostl-low
                  ' To: '(031) s_kostl-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Cost Element: '(037) s_kstar-low
                  ' To: '(031) s_kstar-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Purchase Order: '(038) s_ebeln-low
                  ' To: '(031) s_ebeln-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Period : '(039) s_monat-low
                  ' To: '(031) s_monat-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Include Material Items: '(040)
                  p_incmt into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Include Non-Material Items: '(041)
                  p_incnm into l_line-info.
      append l_line to lt_top_of_page.
    endform.
         Form        : call_list_viewer
         Description : This form is used to display the grid through ALV
    form call_list_viewer.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = g_repid
                is_layout               = x_layout
                it_fieldcat             = i_fldcat[]
                i_default               = c_x
                it_sort                 = i_sort[]
                i_save                  = g_save
                is_variant              = g_variant
                it_events               = g_events[]
           importing
                e_exit_caused_by_caller = g_exit_caused_by_caller
                es_exit_caused_by_user  = g_exit_caused_by_user
           tables
                t_outtab                = i_final
           exceptions
                program_error           = 1
                others                  = 2.
      if sy-subrc <> 0.
        write: / 'Problem in calling the ALV report'(042).
      endif.
    endform.                    " call_list_viewer
    Regards
    Anji

  • REUSE_ALV_HIERSEQ_LIST_DISPLAY i_interface_check

    hello,
    I the function "REUSE_ALV_HIERSEQ_LIST_DISPLAY" exists an parameter "i_interface_check" to check the interface.
    It doesn´t work, when I use the function "REUSE_ALV_GRID_DISPLAY", but when I use "REUSE_ALV_LIST_DISPLAY" it works.
    Has anyone an idea?
    Kind regards
    Jens

    Hi
    I am attaching a code which uses both "REUSE_ALV_GRID_DISPLAY and  "REUSE_ALV_LIST_DISPLAY
    I think it will be helpful if you investigate the code.
    tables used -
    tables: mkpf,
            mseg,
            lfa1,
            makt.
    global hashed tables used
    data: begin of wa_mkpf, "header
          mblnr like mkpf-mblnr,
          mjahr like mkpf-mjahr,
          budat like mkpf-budat,
          xblnr like mkpf-xblnr,
          end of wa_mkpf.
    data: ht_mkpf like hashed table of wa_mkpf
          with unique key mblnr mjahr
          with header line.
    data: st_mkpf like standard table of wa_mkpf
          with header line.
    data: begin of wa_mseg, " line items
          mblnr like mseg-mblnr,
          mjahr like mseg-mjahr,
          zeile like mseg-zeile,
          bwart like mseg-bwart,
          charg like mseg-charg,
          matnr like mseg-matnr,
          lifnr like mseg-lifnr,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          end of wa_mseg.
    data ht_mseg like hashed table of wa_mseg
          with unique key mblnr mjahr zeile
          with header line.
    data st_mseg like standard table of wa_mseg
          with header line.
    cache structure for lfa1 records
    data: begin of wa_lfa1,
          lifnr like lfa1-lifnr,
          name1 like lfa1-name1,
          end of wa_lfa1.
    data ht_lfa1 like hashed table of wa_lfa1
          with unique key lifnr
          with header line.
    cache structure for material related data
    data: begin of wa_material,
          matnr like makt-matnr,
          maktx like makt-maktx,
          end of wa_material.
    data: ht_material like hashed table of wa_material
            with unique key matnr
            with header line.
    result table
    data: begin of wa_lst, "
          budat like mkpf-budat,
          mblnr like mseg-mblnr,
          lifnr like mseg-lifnr,
          name1 like lfa1-name1,     
          xblnr like mkpf-xblnr,
          zeile like mseg-zeile,
          charg like mseg-charg,
          matnr like mseg-matnr,
          maktx like makt-maktx,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          mjahr like mseg-mjahr,
          end of wa_lst.
    data: ht_lst like hashed table of wa_lst
            with unique key mblnr mjahr zeile
            with header line.
    data: begin of wa_lst1, " sumary by material
          matnr like mseg-matnr,
          maktx like makt-maktx,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          color_line(4) TYPE c,           " Line color
          color_cell    TYPE lvc_t_scol,  " Cell color
          celltab type LVC_T_STYL,
          end of wa_lst1.
    data: ht_lst1 like hashed table of wa_lst1
            with unique key matnr
            with header line.
    structures for alv grid display.
    itabs
    type-pools: slis.
    data: it_lst            like standard table of wa_lst with header line,
          it_fieldcat_lst   type slis_t_fieldcat_alv with header line,
          it_sort_lst       type slis_t_sortinfo_alv,
          it_lst1           like standard table of wa_lst1 with header line,
          it_fieldcat_lst1  type slis_t_fieldcat_alv with header line,
          it_sort_lst1      type slis_t_sortinfo_alv.
    structures
    data: wa_sort         type slis_sortinfo_alv,
          ls_layout       type slis_layout_alv.
    color management.
    DATA  : wa_color    TYPE lvc_s_scol.
    Internal table for color management.
    DATA : it_color    TYPE TABLE          OF lvc_s_scol.
    itab for input enabling.
    DATA: lt_celltab TYPE lvc_t_styl. "
    global varialbes
    data: g_lines type i.
    data: g_repid like sy-repid,
          ok_code       like sy-ucomm.
    selection-screen
    "text: Dates:
    select-options: so_budat for mkpf-budat default sy-datum.
    "text: Material numbers.
    select-options: so_matnr for mseg-matnr.
    selection-screen uline.
    selection-screen skip 1.
    "Text: show summary by material.
    parameters: gp_bymat as checkbox default ''.
    parameters: gp_hier  as checkbox default 'X'.
    start-of-selection.
      perform get_data.
      perform show_data.
    end-of-selection.
          FORM get_data                                                 *
    form get_data.
           select mblnr mjahr budat xblnr
                into table ht_mkpf
               from mkpf
              where budat in so_budat. " make use of std index.
    have we retrieved data from mkpf?
      describe table ht_mkpf lines g_lines.
      if g_lines > 0.
    if true then retrieve all related records from mseg.
    Doing this way we make sure that the access is by primary key
    of mseg.
    The reason is that is faster to filter them in memory
    than to allow the db server to do it.
        select mblnr mjahr zeile bwart charg
                 matnr lifnr erfmg erfme
          into table ht_mseg
          from mseg
            for all entries in ht_mkpf
         where mblnr = ht_mkpf-mblnr
           and mjahr = ht_mkpf-mjahr.
      endif.
    fill t_lst or t_lst1 according to user's choice.
      if gp_bymat = ' '.
        perform fill_ht_lst.
      else.
        perform fill_ht_lst1.
      endif.
    endform.
    form fill_ht_lst.
      refresh ht_lst.
    Example: how to discard unwanted data in an efficient way.
      loop at ht_mseg.
      filter unwanted data
        check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
        check ht_mseg-matnr in so_matnr.
      read header line.
        read table ht_mkpf with table key mblnr = ht_mseg-mblnr
        mjahr = ht_mseg-mjahr.
        clear ht_lst.
    * note : this may be faster if you specify field by field.
        move-corresponding ht_mkpf to ht_lst.
        move-corresponding ht_mseg to ht_lst.
        perform read_lfa1 using ht_mseg-lifnr changing ht_lst-name1.
        perform read_material using ht_mseg-matnr changing ht_lst-maktx.
        insert table ht_lst.
      endloop.
    endform.
    form fill_ht_lst1.
    data: colorear.
      refresh ht_lst1.
    Example: how to discard unwanted data in an efficient way.
             hot to simulate a collect in a faster way
      loop at ht_mseg.
      filter unwanted data
        check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
        check ht_mseg-matnr in so_matnr.
    * note : this may be faster if you specify field by field.
        read table ht_lst1 with table key matnr = ht_mseg-matnr
        transporting erfmg.
        if sy-subrc <> 0. " if matnr doesn't exist in sumary table
        " insert a new record
          clear ht_lst1.
          ht_lst1-matnr = ht_mseg-matnr.
          perform read_material using ht_mseg-matnr changing ht_lst1-maktx.
          ht_lst1-erfmg = ht_mseg-erfmg.
          ht_lst1-erfme = ht_mseg-erfme.
          if colorear = ''.
            colorear = 'X'.
            refresh it_color.
            ht_lst1-color_cell[] = it_color[].
            MOVE 'C410' TO ht_lst1-color_line.
          else.
            colorear = ' '.
            refresh it_color. clear it_color.
            MOVE 'MATNR' TO wa_color-fname.
            MOVE '6'         TO wa_color-color-col.
            MOVE '1'         TO wa_color-color-int.
            MOVE '1'         TO wa_color-color-inv.
            APPEND wa_color TO it_color.
            MOVE 'MAKTX' TO wa_color-fname.
            MOVE '3'         TO wa_color-color-col.
            MOVE '1'         TO wa_color-color-int.
            MOVE '1'         TO wa_color-color-inv.
            APPEND wa_color TO it_color.
            MOVE 'ERFMG' TO wa_color-fname.
            MOVE '5'         TO wa_color-color-col.
            MOVE '1'         TO wa_color-color-int.
            MOVE '1'         TO wa_color-color-inv.
            APPEND wa_color TO it_color.
            ht_lst1-color_cell[] = it_color[].
            clear ht_lst1-color_line.
          endif.
          insert table ht_lst1.
        else." a record was found.
        " collect erfmg.  To do so, fill in the unique key and add
        " the numeric fields.
          ht_lst1-matnr = ht_mseg-matnr.
          add ht_mseg-erfmg to ht_lst1-erfmg.
          modify table ht_lst1 transporting erfmg.
        endif.
      endloop.
    endform.
    implementation of cache for lfa1.
    form read_lfa1 using p_lifnr changing p_name1.
           read table ht_lfa1 with table key lifnr = p_lifnr
            transporting name1.
      if sy-subrc <> 0.
        clear ht_lfa1.
        ht_lfa1-lifnr = p_lifnr.
        select single name1
           into ht_lfa1-name1
          from lfa1
        where lifnr = p_lifnr.
        if sy-subrc <> 0. ht_lfa1-name1 = 'n/a in lfa1'. endif.
        insert table ht_lfa1.
      endif.
      p_name1 = ht_lfa1-name1.
    endform.
    implementation of cache for material data
    form read_material using p_matnr changing p_maktx.
      read table ht_material with table key matnr = p_matnr
      transporting maktx.
      if sy-subrc <> 0.
        ht_material-matnr = p_matnr.
        select single maktx into  ht_material-maktx
          from makt
         where spras = sy-langu
           and matnr = p_matnr.
        if sy-subrc <> 0. ht_material-maktx = 'n/a in makt'. endif.
        insert table ht_material.
      endif.
      p_maktx = ht_material-maktx.
    endform.
    form show_data.
      if gp_hier = 'X'. "no anda.
       perform show_hierarchicalALV.
      else.
        if gp_bymat = ' '.
          perform show_ht_lst.
        else.
          perform show_ht_lst1.
        endif.
      endif.
    endform.
    form show_hierarchicalALV.
    st_mkpf[] = ht_mkpf[].
    st_mseg[] = ht_mseg[].
    call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    exporting
      I_INTERFACE_CHECK              = ' '
      I_CALLBACK_PROGRAM             =
      I_CALLBACK_PF_STATUS_SET       = ' '
      I_CALLBACK_USER_COMMAND        = ' '
      IS_LAYOUT                      =
      IT_FIELDCAT                    =
      IT_EXCLUDING                   =
      IT_SPECIAL_GROUPS              =
      IT_SORT                        =
      IT_FILTER                      =
      IS_SEL_HIDE                    =
      I_SCREEN_START_COLUMN          = 0
      I_SCREEN_START_LINE            = 0
      I_SCREEN_END_COLUMN            = 0
      I_SCREEN_END_LINE              = 0
      I_DEFAULT                      = 'X'
      I_SAVE                         = ' '
      IS_VARIANT                     =
      IT_EVENTS                      =
      IT_EVENT_EXIT                  =
       i_tabname_header               =
       i_tabname_item                 =
      I_STRUCTURE_NAME_HEADER        =
      I_STRUCTURE_NAME_ITEM          =
       is_keyinfo                     =
      IS_PRINT                       =
      IS_REPREP_ID                   =
      I_BUFFER_ACTIVE                =
      I_BYPASSING_BUFFER             =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER        =
      ES_EXIT_CAUSED_BY_USER         =
      tables
        t_outtab_header                = st_mkpf
        t_outtab_item                  = st_mseg
    EXCEPTIONS
      PROGRAM_ERROR                  = 1
      OTHERS                         = 2
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    endform.
    form show_ht_lst.
      "needed because the FM can't use a hashed table.
      it_lst[] = ht_lst[].
      perform fill_layout using 'full display'
                           changing ls_layout.
      perform fill_columns_lst.
    perform sort_lst.
      g_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program       = g_repid
                i_callback_pf_status_set = 'SET_PF_STATUS'
                is_layout                = ls_layout
                it_fieldcat              = it_fieldcat_lst[]
               it_sort                  = it_sort_lst
           tables
                t_outtab                 = it_lst
           exceptions
                program_error            = 1
                others                   = 2.
    endform.
    form show_ht_lst1.
      "needed because the FM can't use a hashed table.
      it_lst1[] = ht_lst1[].
      perform fill_layout using 'Sumary by matnr'
                           changing ls_layout.
      perform fill_columns_lst1.
    perform sort_lst.
      g_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program       = g_repid
                i_callback_pf_status_set = 'SET_PF_STATUS'
                is_layout                = ls_layout
                it_fieldcat              = it_fieldcat_lst1[]
               it_sort                  = it_sort_lst
           tables
                t_outtab                 = it_lst1
           exceptions
                program_error            = 1
                others                   = 2.
    endform.
    form fill_layout using p_window_titlebar
                   changing cs_layo type slis_layout_alv.
      clear cs_layo.
      cs_layo-window_titlebar        = p_window_titlebar.
      cs_layo-edit                   = 'X'.
      cs_layo-edit_mode              = space.
      MOVE 'COLOR_LINE' TO cs_layo-info_fieldname.
    Field that identify cell color in inetrnal table
      MOVE 'COLOR_CELL' TO cs_layo-coltab_fieldname.
    move 'CELLTAB' TO cs_layo-stylefname.
    endform.                    " armar_layout_stock
    form set_pf_status using rt_extab type slis_t_extab.
    create a new status
    and then select extras -> adjust template -> listviewer
      set pf-status 'VISTA'.
    endform.        "set_pf_status
    define add_lst.
      clear it_fieldcat_lst.
      it_fieldcat_lst-fieldname     = &1.
      it_fieldcat_lst-outputlen     = &2.
      it_fieldcat_lst-ddictxt       = 'L'.
      it_fieldcat_lst-seltext_l       = &1.
      it_fieldcat_lst-seltext_m       = &1.
      it_fieldcat_lst-seltext_m       = &1.
      if &1 = 'MATNR'.
        it_fieldcat_lst-emphasize = 'C111'.
      endif.
      append it_fieldcat_lst.
    end-of-definition.
    define add_lst1.
      clear it_fieldcat_lst.
      it_fieldcat_lst1-fieldname     = &1.
      it_fieldcat_lst1-outputlen     = &2.
      it_fieldcat_lst1-ddictxt       = 'L'.
      it_fieldcat_lst1-seltext_l       = &1.
      it_fieldcat_lst1-seltext_m       = &1.
      it_fieldcat_lst1-seltext_m       = &1.
      append it_fieldcat_lst1.
    end-of-definition.
    form fill_columns_lst.
    set columns for output.
      refresh it_fieldcat_lst.
      add_lst 'BUDAT' 10.
      add_lst   'MBLNR' 10.
      add_lst  'LIFNR' 10.
      add_lst  'NAME1' 35.
      add_lst  'XBLNR' 15.
      add_lst    'ZEILE' 5.
      add_lst    'CHARG' 10.
      add_lst   'MATNR' 18.
      add_lst   'MAKTX' 30.
      add_lst   'ERFMG' 17.
      add_lst   'ERFME' 5.
      add_lst   'MJAHR' 4.
    endform.
    form fill_columns_lst1.
    set columns for output.
      refresh it_fieldcat_lst1.
      add_lst1 'MATNR' 18.
      add_lst1 'MAKTX' 30.
      add_lst1 'ERFMG' 17.
      add_lst1 'ERFME' 5..
    endform.
    Regards
    Praneeth
    Reward helpful answers

  • In which table the production quantity stored after confirmation

    Dear all,
                   When the production order is confirmed through co11n,then where the
    order quantity get stored in which table so I could suggest my ABAPER to create the report in which these production quantity gets displayed.
    Regards
    deepak sharma

    Dear Mr.Deepak Sharma,
    There's direct T code in SAP COOIS.
    First check with this T code,whether your requirement is getting fulfilled.
    If not go for a report generation using the tables.
    The following are the tables related to your question
    AFKO              Order Header
    AFPO               Order Item Detail
    AFVC               Order Operations Detail
    AFFL                Order Sequence Details
    AFRU               Order Completion Confirmations
    Reward points if useful.
    Regards
    Mangal

  • How to create hashed table in runtime

    hi experts
    how to create hashed table in runtime, please give me the coading style.
    please help me.
    regards
    subhasis

    Hi,
    Have alook at the code, and pls reward points.
    Use Hashed Tables to Improve Performance :
    report zuseofhashedtables.
    Program: ZUseOfHashedTables                                        **
    Author: XXXXXXXXXXXXXXXXXX                                 **
    Versions: 4.6b - 4.6c                                              **
    Notes:                                                             **
        this program shows how we can use hashed tables to improve     **
        the responce time.                                             **
        It shows,                                                      **
           1. how to declare hashed tables                             **
           2. a cache-like technique to improve access to master data  **
           3. how to collect data using hashed tables                  **
           4. how to avoid deletions of unwanted data                  **
    Results: the test we run read about 31000 rows from mkpf, 150000   **
             rows from mseg, 500 rows from makt and 400 from lfa1.     **
             it filled ht_lst with 24500 rows and displayed them in    **
             alv grid format.                                          **
             It needed about 65 seconds to perform this task (with     **
             all the db buffers empty)                                 **
             The same program with standard tables needed 140 seconds  **
             to run with the same recordset and with buffers filled in **
    Objetive: show a list that consists of  all the material movements **
             '101' - '901' for a certain range of dates in mkpf-budat. **
    the columns to be displayed are:                                   **
             mkpf-budat,                                               **
             mkpf-mblnr,                                               **
             mseg-lifnr,                                               **
             lfa1-name1,                                               **
             mkpf-xblnr,                                               **
             mseg-zeile                                                **
             mseg-charg,                                               **
             mseg-matnr,                                               **
             makt-maktx,                                               **
             mseg-erfmg,                                               **
             mseg-erfme.                                               **
    or show a sumary list by matnr - menge                             **
    You'll have to create a pf-status called vista -                   **
    See form set_pf_status for details                                 **
    tables used -
    tables: mkpf,
            mseg,
            lfa1,
            makt.
    global hashed tables used
    data: begin of wa_mkpf, "header
          mblnr like mkpf-mblnr,
          mjahr like mkpf-mjahr,
          budat like mkpf-budat,
          xblnr like mkpf-xblnr,
          end of wa_mkpf.
    data: ht_mkpf like hashed table of wa_mkpf
          with unique key mblnr mjahr
          with header line.
    data: begin of wa_mseg, " line items
          mblnr like mseg-mblnr,
          mjahr like mseg-mjahr,
          zeile like mseg-zeile,
          bwart like mseg-bwart,
          charg like mseg-charg,
          matnr like mseg-matnr,
          lifnr like mseg-lifnr,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          end of wa_mseg.
    data ht_mseg like hashed table of wa_mseg
          with unique key mblnr mjahr zeile
          with header line.
    cache structure for lfa1 records
    data: begin of wa_lfa1,
          lifnr like lfa1-lifnr,
          name1 like lfa1-name1,
          end of wa_lfa1.
    data ht_lfa1 like hashed table of wa_lfa1
          with unique key lifnr
          with header line.
    cache structure for material related data
    data: begin of wa_material,
          matnr like makt-matnr,
          maktx like makt-maktx,
          end of wa_material.
    data: ht_material like hashed table of wa_material
            with unique key matnr
            with header line.
    result table
    data: begin of wa_lst, "
          budat like mkpf-budat,
          mblnr like mseg-mblnr,
          lifnr like mseg-lifnr,
          name1 like lfa1-name1,   
          xblnr like mkpf-xblnr,
          zeile like mseg-zeile,
          charg like mseg-charg,
          matnr like mseg-matnr,
          maktx like makt-maktx,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          mjahr like mseg-mjahr,
          end of wa_lst.
    data: ht_lst like hashed table of wa_lst
            with unique key mblnr mjahr zeile
            with header line.
    data: begin of wa_lst1, " sumary by material
          matnr like mseg-matnr,
          maktx like makt-maktx,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          end of wa_lst1.
    data: ht_lst1 like hashed table of wa_lst1
            with unique key matnr
            with header line.
    structures for alv grid display.
    itabs
    type-pools: slis.
    data: it_lst            like standard table of wa_lst with header line,
          it_fieldcat_lst   type slis_t_fieldcat_alv with header line,
          it_sort_lst       type slis_t_sortinfo_alv,
          it_lst1           like standard table of wa_lst1 with header line,
          it_fieldcat_lst1  type slis_t_fieldcat_alv with header line,
          it_sort_lst1      type slis_t_sortinfo_alv.
    structures
    data: wa_sort         type slis_sortinfo_alv,
          ls_layout       type slis_layout_alv.
    global varialbes
    data: g_lines type i.
    data: g_repid like sy-repid,
          ok_code       like sy-ucomm.
    selection-screen
    "text: Dates:
    select-options: so_budat for mkpf-budat default sy-datum.
    "text: Material numbers.
    select-options: so_matnr for mseg-matnr.
    selection-screen uline.
    selection-screen skip 1.
    "Text: show summary by material.
    parameters: gp_bymat as checkbox default ''.
    start-of-selection.
      perform get_data.
      perform show_data.
    end-of-selection.
          FORM get_data                                                 *
    form get_data.
            select mblnr mjahr budat xblnr
                into table ht_mkpf
               from mkpf
              where budat in so_budat. " make use of std index.
    have we retrieved data from mkpf?
      describe table ht_mkpf lines g_lines.
      if g_lines > 0.
    if true then retrieve all related records from mseg.
    Doing this way we make sure that the access is by primary key
    of mseg.
    The reason is that is faster to filter them in memory
    than to allow the db server to do it.
        select mblnr mjahr zeile bwart charg
                 matnr lifnr erfmg erfme
          into table ht_mseg
          from mseg
            for all entries in ht_mkpf
         where mblnr = ht_mkpf-mblnr
           and mjahr = ht_mkpf-mjahr.
      endif.
    fill t_lst or t_lst1 according to user's choice.
      if gp_bymat = ' '.
        perform fill_ht_lst.
      else.
        perform fill_ht_lst1.
      endif.
    endform.
    form fill_ht_lst.
      refresh ht_lst.
    Example: how to discard unwanted data in an efficient way.
      loop at ht_mseg.
      filter unwanted data
        check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
        check ht_mseg-matnr in so_matnr.
      read header line.
        read table ht_mkpf with table key mblnr = ht_mseg-mblnr
        mjahr = ht_mseg-mjahr.
        clear ht_lst.
    * note : this may be faster if you specify field by field.
        move-corresponding ht_mkpf to ht_lst.
        move-corresponding ht_mseg to ht_lst.
        perform read_lfa1 using ht_mseg-lifnr changing ht_lst-name1.
        perform read_material using ht_mseg-matnr changing ht_lst-maktx.
        insert table ht_lst.
      endloop.
    endform.
    form fill_ht_lst1.
      refresh ht_lst1.
    Example: how to discard unwanted data in an efficient way.
             hot to simulate a collect in a faster way
      loop at ht_mseg.
      filter unwanted data
        check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
        check ht_mseg-matnr in so_matnr.
    * note : this may be faster if you specify field by field.
        read table ht_lst1 with table key matnr = ht_mseg-matnr
        transporting erfmg.
        if sy-subrc <> 0. " if matnr doesn't exist in sumary table
        " insert a new record
          ht_lst1-matnr = ht_mseg-matnr.
          perform read_material using ht_mseg-matnr changing ht_lst1-maktx.
          ht_lst1-erfmg = ht_mseg-erfmg.
          ht_lst1-erfme = ht_mseg-erfme.
          insert table ht_lst1.
        else." a record was found.
        " collect erfmg.  To do so, fill in the unique key and add
        " the numeric fields.
          ht_lst1-matnr = ht_mseg-matnr.
          add ht_mseg-erfmg to ht_lst1-erfmg.
          modify table ht_lst1 transporting erfmg.
        endif.
      endloop.
    endform.
    implementation of cache for lfa1.
    form read_lfa1 using p_lifnr changing p_name1.
            read table ht_lfa1 with table key lifnr = p_lifnr
            transporting name1.
      if sy-subrc <> 0.
        clear ht_lfa1.
        ht_lfa1-lifnr = p_lifnr.
        select single name1
           into ht_lfa1-name1
          from lfa1
        where lifnr = p_lifnr.
        if sy-subrc <> 0. ht_lfa1-name1 = 'n/a in lfa1'. endif.
        insert table ht_lfa1.
      endif.
      p_name1 = ht_lfa1-name1.
    endform.
    implementation of cache for material data
    form read_material using p_matnr changing p_maktx.
      read table ht_material with table key matnr = p_matnr
      transporting maktx.
      if sy-subrc <> 0.
        ht_material-matnr = p_matnr.
        select single maktx into  ht_material-maktx
          from makt
         where spras = sy-langu
           and matnr = p_matnr.
        if sy-subrc <> 0. ht_material-maktx = 'n/a in makt'. endif.
        insert table ht_material.
      endif.
      p_maktx = ht_material-maktx.
    endform.
    form show_data.
      if gp_bymat = ' '.
        perform show_ht_lst.
      else.
        perform show_ht_lst1.
      endif.
    endform.
    form show_ht_lst.
      "needed because the FM can't use a hashed table.
      it_lst[] = ht_lst[].
      perform fill_layout using 'full display'
                           changing ls_layout.
      perform fill_columns_lst.
    perform sort_lst.
      g_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program       = g_repid
                i_callback_pf_status_set = 'SET_PF_STATUS'
                is_layout                = ls_layout
                it_fieldcat              = it_fieldcat_lst[]
               it_sort                  = it_sort_lst
           tables
                t_outtab                 = it_lst
           exceptions
                program_error            = 1
                others                   = 2.
    endform.
    form show_ht_lst1.
      "needed because the FM can't use a hashed table.
      it_lst1[] = ht_lst1[].
      perform fill_layout using 'Sumary by matnr'
                           changing ls_layout.
      perform fill_columns_lst1.
    perform sort_lst.
      g_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program       = g_repid
                i_callback_pf_status_set = 'SET_PF_STATUS'
                is_layout                = ls_layout
                it_fieldcat              = it_fieldcat_lst1[]
               it_sort                  = it_sort_lst
           tables
                t_outtab                 = it_lst1
           exceptions
                program_error            = 1
                others                   = 2.
    endform.
    form fill_layout using p_window_titlebar
                   changing cs_layo type slis_layout_alv.
      clear cs_layo.
      cs_layo-window_titlebar        = p_window_titlebar.
      cs_layo-edit                   = 'X'.
      cs_layo-edit_mode              = space.
    endform.                    " armar_layout_stock
    form set_pf_status using rt_extab type slis_t_extab.
    create a new status
    and then select extras -> adjust template -> listviewer
      set pf-status 'VISTA'.
    endform.        "set_pf_status
    define add_lst.
      clear it_fieldcat_lst.
      it_fieldcat_lst-fieldname     = &1.
      it_fieldcat_lst-outputlen     = &2.
      it_fieldcat_lst-ddictxt       = 'L'.
      it_fieldcat_lst-seltext_l       = &1.
      it_fieldcat_lst-seltext_m       = &1.
      it_fieldcat_lst-seltext_m       = &1.
      if &1 = 'MATNR'.
        it_fieldcat_lst-emphasize = 'C111'.
      endif.
      append it_fieldcat_lst.
    end-of-definition.
    define add_lst1.
      clear it_fieldcat_lst.
      it_fieldcat_lst1-fieldname     = &1.
      it_fieldcat_lst1-outputlen     = &2.
      it_fieldcat_lst1-ddictxt       = 'L'.
      it_fieldcat_lst1-seltext_l       = &1.
      it_fieldcat_lst1-seltext_m       = &1.
      it_fieldcat_lst1-seltext_m       = &1.
      append it_fieldcat_lst1.
    end-of-definition.
    form fill_columns_lst.
    set columns for output.
      refresh it_fieldcat_lst.
      add_lst 'BUDAT' 10.
      add_lst   'MBLNR' 10.
      add_lst  'LIFNR' 10.
      add_lst  'NAME1' 35.
      add_lst  'XBLNR' 15.
      add_lst    'ZEILE' 5.
      add_lst    'CHARG' 10.
      add_lst   'MATNR' 18.
      add_lst   'MAKTX' 30.
      add_lst   'ERFMG' 17.
      add_lst   'ERFME' 5.
      add_lst   'MJAHR' 4.
    endform.
    form fill_columns_lst1.
    set columns for output.
      refresh it_fieldcat_lst1.
      add_lst1 'MATNR' 18.
      add_lst1 'MAKTX' 30.
      add_lst1 'ERFMG' 17.
      add_lst1 'ERFME' 5..
    endform.
    Regards,
    Ameet

  • ALV color

    Hi all,
    Can anyone tell me how to display different colors on different coloumns of an ALV.
    thanks

    hi
    check this code
    An example of using linecolor (ALV).
    Here you have a good example of coloring rows, columns and specific cells in alvs. It comes in an example of how to use hashed tables. 
    For coloured rows and cols check gp_bymat
    for coloured specific rows uncheck gp_bymat.
    HTH.
    Horacio
    ps: code:
    report zuseofhashedtables.
    Program: ZUseOfHashedTables                                        **
    Author: Horacio Zapettini                                          **
    Versions: 4.6b - 4.6c                                              **
    Notes:                                                             **
        this program shows how we can use hashed tables to improve     **
        the responce time.                                             **
        It shows,                                                      **
           1. how to declare hashed tables                             **
           2. a cache-like technique to improve access to master data  **
           3. how to collect data using hashed tables                  **
           4. how to avoid deletions of unwanted data                  **
    Results: the test we run read about 31000 rows from mkpf, 150000   **
             rows from mseg, 500 rows from makt and 400 from lfa1.     **
             it filled ht_lst with 24500 rows and displayed them in    **
             alv grid format.                                          **
             It took about 65 secodns to perform this task (first time **
             we run it when all the db buffers are empty.              **
             The same program with standard tables needed 140 seconds  **
             to run with the same recordset and with buffers filled in **
             A simmilar test over more than a million rows
    Objetive: show a list that consists of  all the material movements **
             '101' - '901' for a certain range of dates in mkpf-budat. **
    the columns to be displayed are:                                   **
             mkpf-budat,                                               **
             mkpf-mblnr,                                               **
             mseg-lifnr,                                               **
             lfa1-name1,                                               **
             mkpf-xblnr,                                               **
             mseg-zeile                                                **
             mseg-charg,                                               **
             mseg-matnr,                                               **
             makt-maktx,                                               **
             mseg-erfmg,                                               **
             mseg-erfme.                                               **
    or show a sumary list by matnr - menge                             **
    You'll have to create a pf-status called vista -                   **
    See form set_pf_status for details                                 **
    tables used -
    tables: mkpf,
            mseg,
            lfa1,
            makt.
    global hashed tables used
    data: begin of wa_mkpf, "header
          mblnr like mkpf-mblnr,
          mjahr like mkpf-mjahr,
          budat like mkpf-budat,
          xblnr like mkpf-xblnr,
          end of wa_mkpf.
    data: ht_mkpf like hashed table of wa_mkpf
          with unique key mblnr mjahr
          with header line.
    data: st_mkpf like standard table of wa_mkpf
          with header line.
    data: begin of wa_mseg, " line items
          mblnr like mseg-mblnr,
          mjahr like mseg-mjahr,
          zeile like mseg-zeile,
          bwart like mseg-bwart,
          charg like mseg-charg,
          matnr like mseg-matnr,
          lifnr like mseg-lifnr,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          end of wa_mseg.
    data ht_mseg like hashed table of wa_mseg
          with unique key mblnr mjahr zeile
          with header line.
    data st_mseg like standard table of wa_mseg
          with header line.
    cache structure for lfa1 records
    data: begin of wa_lfa1,
          lifnr like lfa1-lifnr,
          name1 like lfa1-name1,
          end of wa_lfa1.
    data ht_lfa1 like hashed table of wa_lfa1
          with unique key lifnr
          with header line.
    cache structure for material related data
    data: begin of wa_material,
          matnr like makt-matnr,
          maktx like makt-maktx,
          end of wa_material.
    data: ht_material like hashed table of wa_material
            with unique key matnr
            with header line.
    result table
    data: begin of wa_lst, "
          budat like mkpf-budat,
          mblnr like mseg-mblnr,
          lifnr like mseg-lifnr,
          name1 like lfa1-name1,   
          xblnr like mkpf-xblnr,
          zeile like mseg-zeile,
          charg like mseg-charg,
          matnr like mseg-matnr,
          maktx like makt-maktx,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          mjahr like mseg-mjahr,
          end of wa_lst.
    data: ht_lst like hashed table of wa_lst
            with unique key mblnr mjahr zeile
            with header line.
    data: begin of wa_lst1, " sumary by material
          matnr like mseg-matnr,
          maktx like makt-maktx,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          color_line(4) TYPE c,           " Line color
          color_cell    TYPE lvc_t_scol,  " Cell color
          celltab type LVC_T_STYL,
          end of wa_lst1.
    data: ht_lst1 like hashed table of wa_lst1
            with unique key matnr
            with header line.
    structures for alv grid display.
    itabs
    type-pools: slis.
    data: it_lst            like standard table of wa_lst with header line,
          it_fieldcat_lst   type slis_t_fieldcat_alv with header line,
          it_sort_lst       type slis_t_sortinfo_alv,
          it_lst1           like standard table of wa_lst1 with header line,
          it_fieldcat_lst1  type slis_t_fieldcat_alv with header line,
          it_sort_lst1      type slis_t_sortinfo_alv.
    structures
    data: wa_sort         type slis_sortinfo_alv,
          ls_layout       type slis_layout_alv.
    color management.
    DATA  : wa_color    TYPE lvc_s_scol.
    Internal table for color management.
    DATA : it_color    TYPE TABLE          OF lvc_s_scol.
    itab for input enabling.
    DATA: lt_celltab TYPE lvc_t_styl. "
    global varialbes
    data: g_lines type i.
    data: g_repid like sy-repid,
          ok_code       like sy-ucomm.
    selection-screen
    "text: Dates:
    select-options: so_budat for mkpf-budat default sy-datum.
    "text: Material numbers.
    select-options: so_matnr for mseg-matnr.
    selection-screen uline.
    selection-screen skip 1.
    "Text: show summary by material.
    parameters: gp_bymat as checkbox default ''.
    parameters: gp_hier  as checkbox default 'X'.
    start-of-selection.
      perform get_data.
      perform show_data.
    end-of-selection.
          FORM get_data                                                 *
    form get_data.
            select mblnr mjahr budat xblnr
                into table ht_mkpf
               from mkpf
              where budat in so_budat. " make use of std index.
    have we retrieved data from mkpf?
      describe table ht_mkpf lines g_lines.
      if g_lines > 0.
    if true then retrieve all related records from mseg.
    Doing this way we make sure that the access is by primary key
    of mseg.
    The reason is that is faster to filter them in memory
    than to allow the db server to do it.
        select mblnr mjahr zeile bwart charg
                 matnr lifnr erfmg erfme
          into table ht_mseg
          from mseg
            for all entries in ht_mkpf
         where mblnr = ht_mkpf-mblnr
           and mjahr = ht_mkpf-mjahr.
      endif.
    fill t_lst or t_lst1 according to user's choice.
      if gp_bymat = ' '.
        perform fill_ht_lst.
      else.
        perform fill_ht_lst1.
      endif.
    endform.
    form fill_ht_lst.
      refresh ht_lst.
    Example: how to discard unwanted data in an efficient way.
      loop at ht_mseg.
      filter unwanted data
        check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
        check ht_mseg-matnr in so_matnr.
      read header line.
        read table ht_mkpf with table key mblnr = ht_mseg-mblnr
        mjahr = ht_mseg-mjahr.
        clear ht_lst.
    * note : this may be faster if you specify field by field.
        move-corresponding ht_mkpf to ht_lst.
        move-corresponding ht_mseg to ht_lst.
        perform read_lfa1 using ht_mseg-lifnr changing ht_lst-name1.
        perform read_material using ht_mseg-matnr changing ht_lst-maktx.
        insert table ht_lst.
      endloop.
    endform.
    form fill_ht_lst1.
    data: colorear.
      refresh ht_lst1.
    Example: how to discard unwanted data in an efficient way.
             hot to simulate a collect in a faster way
      loop at ht_mseg.
      filter unwanted data
        check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
        check ht_mseg-matnr in so_matnr.
    * note : this may be faster if you specify field by field.
        read table ht_lst1 with table key matnr = ht_mseg-matnr
        transporting erfmg.
        if sy-subrc <> 0. " if matnr doesn't exist in sumary table
        " insert a new record
          clear ht_lst1.
          ht_lst1-matnr = ht_mseg-matnr.
          perform read_material using ht_mseg-matnr changing ht_lst1-maktx.
          ht_lst1-erfmg = ht_mseg-erfmg.
          ht_lst1-erfme = ht_mseg-erfme.
          if colorear = ''.
            colorear = 'X'.
            refresh it_color.
            ht_lst1-color_cell[] = it_color[].
            MOVE 'C410' TO ht_lst1-color_line.
          else.
            colorear = ' '.
            refresh it_color. clear it_color.
            MOVE 'MATNR' TO wa_color-fname.
            MOVE '6'         TO wa_color-color-col.
            MOVE '1'         TO wa_color-color-int.
            MOVE '1'         TO wa_color-color-inv.
            APPEND wa_color TO it_color.
            MOVE 'MAKTX' TO wa_color-fname.
            MOVE '3'         TO wa_color-color-col.
            MOVE '1'         TO wa_color-color-int.
            MOVE '1'         TO wa_color-color-inv.
            APPEND wa_color TO it_color.
            MOVE 'ERFMG' TO wa_color-fname.
            MOVE '5'         TO wa_color-color-col.
            MOVE '1'         TO wa_color-color-int.
            MOVE '1'         TO wa_color-color-inv.
            APPEND wa_color TO it_color.
            ht_lst1-color_cell[] = it_color[].
            clear ht_lst1-color_line.
          endif.
          insert table ht_lst1.
        else." a record was found.
        " collect erfmg.  To do so, fill in the unique key and add
        " the numeric fields.
          ht_lst1-matnr = ht_mseg-matnr.
          add ht_mseg-erfmg to ht_lst1-erfmg.
          modify table ht_lst1 transporting erfmg.
        endif.
      endloop.
    endform.
    implementation of cache for lfa1.
    form read_lfa1 using p_lifnr changing p_name1.
            read table ht_lfa1 with table key lifnr = p_lifnr
            transporting name1.
      if sy-subrc <> 0.
        clear ht_lfa1.
        ht_lfa1-lifnr = p_lifnr.
        select single name1
           into ht_lfa1-name1
          from lfa1
        where lifnr = p_lifnr.
        if sy-subrc <> 0. ht_lfa1-name1 = 'n/a in lfa1'. endif.
        insert table ht_lfa1.
      endif.
      p_name1 = ht_lfa1-name1.
    endform.
    implementation of cache for material data
    form read_material using p_matnr changing p_maktx.
      read table ht_material with table key matnr = p_matnr
      transporting maktx.
      if sy-subrc <> 0.
        ht_material-matnr = p_matnr.
        select single maktx into  ht_material-maktx
          from makt
         where spras = sy-langu
           and matnr = p_matnr.
        if sy-subrc <> 0. ht_material-maktx = 'n/a in makt'. endif.
        insert table ht_material.
      endif.
      p_maktx = ht_material-maktx.
    endform.
    form show_data.
      if gp_hier = 'X'. "no anda.
       perform show_hierarchicalALV.
      else.
        if gp_bymat = ' '.
          perform show_ht_lst.
        else.
          perform show_ht_lst1.
        endif.
      endif.
    endform.
    form show_hierarchicalALV.
    st_mkpf[] = ht_mkpf[].
    st_mseg[] = ht_mseg[].
    call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    exporting
      I_INTERFACE_CHECK              = ' '
      I_CALLBACK_PROGRAM             =
      I_CALLBACK_PF_STATUS_SET       = ' '
      I_CALLBACK_USER_COMMAND        = ' '
      IS_LAYOUT                      =
      IT_FIELDCAT                    =
      IT_EXCLUDING                   =
      IT_SPECIAL_GROUPS              =
      IT_SORT                        =
      IT_FILTER                      =
      IS_SEL_HIDE                    =
      I_SCREEN_START_COLUMN          = 0
      I_SCREEN_START_LINE            = 0
      I_SCREEN_END_COLUMN            = 0
      I_SCREEN_END_LINE              = 0
      I_DEFAULT                      = 'X'
      I_SAVE                         = ' '
      IS_VARIANT                     =
      IT_EVENTS                      =
      IT_EVENT_EXIT                  =
       i_tabname_header               =
       i_tabname_item                 =
      I_STRUCTURE_NAME_HEADER        =
      I_STRUCTURE_NAME_ITEM          =
       is_keyinfo                     =
      IS_PRINT                       =
      IS_REPREP_ID                   =
      I_BUFFER_ACTIVE                =
      I_BYPASSING_BUFFER             =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER        =
      ES_EXIT_CAUSED_BY_USER         =
      tables
        t_outtab_header                = st_mkpf
        t_outtab_item                  = st_mseg
    EXCEPTIONS
      PROGRAM_ERROR                  = 1
      OTHERS                         = 2
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    endform.
    form show_ht_lst.
      "needed because the FM can't use a hashed table.
      it_lst[] = ht_lst[].
      perform fill_layout using 'full display'
                           changing ls_layout.
      perform fill_columns_lst.
    perform sort_lst.
      g_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program       = g_repid
                i_callback_pf_status_set = 'SET_PF_STATUS'
                is_layout                = ls_layout
                it_fieldcat              = it_fieldcat_lst[]
               it_sort                  = it_sort_lst
           tables
                t_outtab                 = it_lst
           exceptions
                program_error            = 1
                others                   = 2.
    endform.
    form show_ht_lst1.
      "needed because the FM can't use a hashed table.
      it_lst1[] = ht_lst1[].
      perform fill_layout using 'Sumary by matnr'
                           changing ls_layout.
      perform fill_columns_lst1.
    perform sort_lst.
      g_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program       = g_repid
                i_callback_pf_status_set = 'SET_PF_STATUS'
                is_layout                = ls_layout
                it_fieldcat              = it_fieldcat_lst1[]
               it_sort                  = it_sort_lst
           tables
                t_outtab                 = it_lst1
           exceptions
                program_error            = 1
                others                   = 2.
    endform.
    form fill_layout using p_window_titlebar
                   changing cs_layo type slis_layout_alv.
      clear cs_layo.
      cs_layo-window_titlebar        = p_window_titlebar.
      cs_layo-edit                   = 'X'.
      cs_layo-edit_mode              = space.
      MOVE 'COLOR_LINE' TO cs_layo-info_fieldname.
    Field that identify cell color in inetrnal table
      MOVE 'COLOR_CELL' TO cs_layo-coltab_fieldname.
    move 'CELLTAB' TO cs_layo-stylefname.
    endform.                    " armar_layout_stock
    form set_pf_status using rt_extab type slis_t_extab.
    create a new status
    and then select extras -> adjust template -> listviewer
      set pf-status 'VISTA'.
    endform.        "set_pf_status
    define add_lst.
      clear it_fieldcat_lst.
      it_fieldcat_lst-fieldname     = &1.
      it_fieldcat_lst-outputlen     = &2.
      it_fieldcat_lst-ddictxt       = 'L'.
      it_fieldcat_lst-seltext_l       = &1.
      it_fieldcat_lst-seltext_m       = &1.
      it_fieldcat_lst-seltext_m       = &1.
      if &1 = 'MATNR'.
        it_fieldcat_lst-emphasize = 'C111'.
      endif.
      append it_fieldcat_lst.
    end-of-definition.
    define add_lst1.
      clear it_fieldcat_lst.
      it_fieldcat_lst1-fieldname     = &1.
      it_fieldcat_lst1-outputlen     = &2.
      it_fieldcat_lst1-ddictxt       = 'L'.
      it_fieldcat_lst1-seltext_l       = &1.
      it_fieldcat_lst1-seltext_m       = &1.
      it_fieldcat_lst1-seltext_m       = &1.
      append it_fieldcat_lst1.
    end-of-definition.
    form fill_columns_lst.
    set columns for output.
      refresh it_fieldcat_lst.
      add_lst 'BUDAT' 10.
      add_lst   'MBLNR' 10.
      add_lst  'LIFNR' 10.
      add_lst  'NAME1' 35.
      add_lst  'XBLNR' 15.
      add_lst    'ZEILE' 5.
      add_lst    'CHARG' 10.
      add_lst   'MATNR' 18.
      add_lst   'MAKTX' 30.
      add_lst   'ERFMG' 17.
      add_lst   'ERFME' 5.
      add_lst   'MJAHR' 4.
    endform.
    form fill_columns_lst1.
    set columns for output.
      refresh it_fieldcat_lst1.
      add_lst1 'MATNR' 18.
      add_lst1 'MAKTX' 30.
      add_lst1 'ERFMG' 17.
      add_lst1 'ERFME' 5..
    endform.
    Horacio Zapettini
    Program to Calculate FI Opening Balance
    How to find the Opening balance for a given period in FI Module for a Particular GL A/c.
    I was calculated opening balance, code is below maybe it will be helpful.
    *find period.
      CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
        EXPORTING
          i_date         = s_budat-low
          i_periv        = i_tab-periv                          "'K4'
        IMPORTING
          e_buper        = v_donem
          e_gjahr        = v_gjahr
        EXCEPTIONS
          input_false    = 1
          t009_notfound  = 2
          t009b_notfound = 3
          OTHERS         = 4.
    *calc opening balance hesabý
      SELECT * FROM knc1 WHERE kunnr = i_tab-kunnr
                         AND bukrs = i_tab-bukrs " s_bukrs
                         AND gjahr EQ v_gjahr.
        v_dnm = v_donem.
    opening balance first calc > old year ,
        WHILE v_dnm > 1.
          v_dnm = v_dnm - 1.
          CONCATENATE 'knc1-um' v_dnm 's' INTO v_field_name_borc.
          CONCATENATE 'knc1-um' v_dnm 'h' INTO v_field_name_alacak.
          ASSIGN (v_field_name_borc) TO  old
    add days which is from selected date-low month
        IF v_donem > 1.
          v_dnm = v_donem - 1.
        ELSE.
          v_dnm = v_donem.
        ENDIF.
        SELECT SINGLE * FROM t009b WHERE periv = i_tab-periv    "'K4'
                                     AND bdatj = s_budat-low+0(4)
                                     AND poper = v_dnm.
        t009b-butag = t009b-butag + 1.
        IF s_budat-low+6(2) NE t009b-butag.
          v_date_high = s_budat-low - 1.
          IF v_donem = 1.
            v_date_low = s_budat-low.
            v_date_low+4(4)  = '0101'.
          ELSE.
            CONCATENATE t009b-bdatj t009b-bumon t009b-butag INTO
            v_date_low.
          ENDIF.
          SELECT *  FROM bsad WHERE bukrs EQ i_tab-bukrs "IN s_bukrs
                                AND kunnr = i_tab-kunnr
                                AND budat BETWEEN v_date_low AND
                                v_date_high
                                AND umskz = space
                                AND blart IN s_blart.
            IF bsad-shkzg = 'S'.
              i_tab-dmbtr_s = i_tab-dmbtr_s + ( bsad-dmbtr ).
            ELSEIF bsad-shkzg = 'H'.
              i_tab-dmbtr_h = i_tab-dmbtr_h + ( bsad-dmbtr   ).
            ENDIF.
          ENDSELECT.
          SELECT *  FROM bsid WHERE bukrs EQ i_tab-bukrs "IN s_bukrs
                               AND kunnr = i_tab-kunnr
                               AND budat BETWEEN v_date_low AND
                               v_date_high
                               AND umskz = space
                               AND blart IN s_blart.
                                 AND gsber IN gsber.
            IF bsid-shkzg = 'S'.
              i_tab-dmbtr_s = i_tab-dmbtr_s + ( bsid-dmbtr   ).
            ELSEIF bsid-shkzg = 'H'.
              i_tab-dmbtr_h = i_tab-dmbtr_h + ( bsid-dmbtr   ).
            ENDIF.
          ENDSELECT.
        ENDIF.
        "opening balance ( þirket bazlý )z1 degeri
       i_tab-z1 = i_tab-z1 + ( knc1-umsav + i_tab-dmbtr_s - i_tab-dmbtr_h ).
    for israel
        i_tab-dmbtril_s = i_tab-dmbtr_s .
        i_tab-dmbtril_h = i_tab-dmbtr_h .
      ENDSELECT.
    praveen

  • SD:  Tables MKPF - RSEG Relationships.

    Hi !
    What is the foriegn key relationships between tables
    MKPF(header: Material Document) and Rseg(Document Item: Incoming Invoice ).
    I tried the following foriegn key relationships:
    RSEG-LFBNR = MKPF-MBLNR, however the relationships does not always exist-I find occurrence where a material document exist (i can see it by drill down from MIRO Transaction) and field RSEG-LFBNR is empty. Is this case
    is a customization bug !
    I also tried to use the forigen key relations :
    RSEG-EBLEN = MSEG-EBELN
    RSEG-EBELP = MSEG-EBELP
    However it is not one to one foriegn relationship
    (i find occurrence where for one order there are two
    invoices and two Material Document items)
    Is there other one to one foriegn key relationships between those tables ? .
    thanks
    moshe

    get BELNR(material Doc ) from EKBE where BEWTP = 'E' for the PO.
    Regards
    Prabhu

Maybe you are looking for