Function Codes in Dynamic ALV

Hello Friends,
I had created an ALV using CL_SALV_TABLE. My requirement is to hide some of the satndard functions appearing in ALV. I had tried this using the method REMOVE_FUNCTION from CL_SALV_FUNCTIONS. For example to hide Find function, I tried by giving function code as MC_FC_FIND (function code for Find in normal ALV created using CL_GUI_ALV_GRID). But this lead to dump error. I can't find any function codes in CL_SALV_TABLE class.
Can anyone tell me which is the function code that I have to use and in which class I can find this.
Regards,
Abijith

Hi ,
You can get Names in debugging using,
DATA: r_functions TYPE REF TO cl_salv_functions,
      t_func_list TYPE salv_t_ui_func,
      w_fname type string,
      wa_func_list LIKE LINE OF t_func_list.
* Get all functions
  r_functions =   gr_table->get_functions( ).
"gr_table is ref to cl_salv_table
  t_func_list = r_functions->get_functions( ).
  LOOP AT t_func_list INTO wa_func_list.
    w_fname = wa_func_list-r_function->get_name( ).
  ENDLOOP.
Note: You can Hide the particular Function code by
         wa_func_list-r_function->set_visible( ' ' ).
Hope This Helps You.
Regards,
Raghava Channooru

Similar Messages

  • How to find function code for Dynamic generated program

    Hi,
    I have created a dynamic program for getting different selection screens depending on inputs . I am finding a flaw that, pressing 'BACK' buttn is leading some other action which was coded by me,  instead of going back.
    SY-UCOMM is also not working as it is dynamic program.
    Help me for getting previous screen.
    Please suggest me the inputs.Thank u
    Regards
    Aditya

    Hi Klaus,
    As per ur instructions, I replaced SY-UCOMM with SSCRFIELDS.
    But no change in my problem.
    The following screen shot is a program which is coded dynamically using fieldsymbols.
    When I press BACK here for the following code selectionscreen, I am getting someother action which was coded by me. But not going back.
    Twist is, SSCRFIELDS-UCOMM or SY-UCOMM is getting captured for 'F8', but not 'BACK'.
    I hope, I have explained my issue clearly. Please let me know, if any deep clarifications needed.
    Regards,
    Aditya

  • Dynamic ALV using REUSE_ALV_HIERSEQ_LIST_DISPLAY

    Hi All,
    My requirement is to display a dynamic output table using REUSE_ALV_HIERSEQ_LIST_DISPLAY.
    I was able to successfully display the dynamic output in grid display using REUSE_ALV_GRID_DISPLAY. But when I try to display the hierarchial list, then only the T_OUTTAB_HEADER data is getting displayed. The T_OUTTAB_ITEM is not getting displayed.
    I am creating the dynamic table using
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG           = I_FIELDCAT_DYN
        IMPORTING
          EP_TABLE                  = I_DYNTABLE
    ALV Display:
      CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
        EXPORTING
          I_INTERFACE_CHECK        = G_INTERFACE_CHECK         
          I_CALLBACK_PROGRAM       = ALV_REPID
          I_CALLBACK_PF_STATUS_SET = 'SET_STATUS'
          I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
          IS_LAYOUT                = ALV_LAYOUT
          IS_PRINT                 = ALV_PRINT
          IT_FIELDCAT              = FC_HIER[]
          I_DEFAULT                = 'X'
          I_SAVE                   = 'A'
          IS_VARIANT               = ALV_VARIANT
          IT_EVENTS                = GT_EVENTS[]   
          I_TABNAME_HEADER         = 'HEADER'
          I_TABNAME_ITEM           = 'LIST'
          IS_KEYINFO               = ALV_KEYINFO
        TABLES
          T_OUTTAB_HEADER     =  HEADER[]
          T_OUTTAB_ITEM           =  <I_FS_DYNOUT>
        EXCEPTIONS
          PROGRAM_ERROR            = 1
          OTHERS                   = 2.
    Any pointers in this regard will be helpful. Also any existing code for dynamic ALV for grid display, will be helpful.
    Thanks & Regards,
    Sonali.

    Hi All,
    Thanks for your inputs.
    All those demo programs are for displaying static output table. I need to display dynamic internal table.
    Also the table name LIST / <I_FS_DYNOUT> does not make a difference.
    Actually there is an existing tcode MB51. In this report first there is a list display, then when u click on detail button, then there is a grid display.
    I had to modify this report to add some more columns.
    So I made a copy and added few more columns to the output table dynamically.
    now when I pass data for list display to REUSE_ALV_HIERSEQ_LIST_DISPLAY, then my list display shows only header data. And when I click on u201Cdetailsu201Dbutton, then the grid display that comes, shows all the data. So the grid display is displaying the dynamic output table contents correctly.
    But the same output table isnt getting displayed in list display.
    Any pointers?
    Thanks & Regards,
    Sonali Gupta.

  • How to find Function codes

    Dear SAP friends,
    Does anybody knows an easy way to find function codes ( those of type ui_func) of standard ALV grid toolbar?
    Searching this forum I learned that you can do se11 and read table RSMPTEXTS for program SAPLSVLV_FULLSCREEN or just se41 for program SAPLSVLV_FULLSCREEN.
    Shouldn't there be some kind of complete Reference about function codes of standard ALV grid?
    Please share if you know.
    Thank you
    Tatyana

    Thank you, Ferry.
    Reading method BUILD_COMPLETE_TOOLBAR of class CL_GUI_ALV_GRID you
    can see an icon code, function code and text  for the buttons of standard ALV grid toolbar.
    Regards,
    Tatyana

  • All Icons and their function codes

    Hi all!
    How can we find all the available icons and their related function codes? I have watched PRINT icon having different function codes in different ALV reports.
    Edited by: Jayasri P. on Jan 7, 2008 12:44 PM

    Hello.
    In order to use them in the GUI status of your ALV do the following:
    go copy the status "STANDARD_FULLSCREEN" of the program "SPLKKBL" to your program and change it.
    If you go to your own status now, under "Application Toolbar", you can define there your own function codes and use them in your code. As far as the icon is concerned, when you will first set the function code, the system will pop-up a screen in which you can define the icon you want to assign to that function code. You just have to do an F4 on the respective field of the pop-up and a new pop-up will show you all the available standard icons of the system that are available for use in your own GUI status. There, the name of each icon (for example, ICON_OKAY, or ICON_CANCEL etc) can be used to display icons in standard ABAP lists. In this case you have to add in your report the following line
    TYPE-POOLS: ICON.
    and then write something like this:
    write:/ icon_okay as icon.
    Reward please if it help.
    Regards,
    George

  • How to find function code for buttons on toolbar in oops alv

    Hi experts,
    I want to remove some buttons from toolbar in oops alv, i know the procedure like get function code and pass the value in a table and pass that table to IT_TOOLBAR_EXCLUDING of
    method set_table_for_first_display but I WANT TO KNOW HOW TO FIND FUNCTION CODE FOR BUTTONS ON TOOLBAR IN OOPS ALV

    Hi Prakash,
    -->First you have to set the pf status in your alv program by,
    {FORM pf_status USING rt_extab TYPE slis_t_extab.
      SET PF-STATUS 'FIRST'.
    ENDFORM.                    "PF_STATUS}
    -->Pass this Subroutine name in the Function module, Reuse_alv_grid_display's parameters i.e,
          i_callback_pf_status_set          = 'PF_STATUS'}
    *-->Then doble click on that pf status,
    From the menu bar, select Extras->Adjust Template->List Viewer,
    This will give you the existing statndard gui status of the program*
    ->Then catch that function codes in the User command Parameter of the Function module Reuse.. i.e,
          i_callback_user_command           = 'COMM'
    And make a subroutine of the name 'COMM'i.e,
    FORM comm USING ucomm LIKE sy-ucomm selfield TYPE slis_selfield.
      DATA: okcode TYPE sy-ucomm.
      okcode = ucomm.
      CASE okcode.
        WHEN 'REF'.
        CALL FUNCTION 'POPUP_TO_INFORM'
          EXPORTING
            titel         = 'MANSI'
            txt1          = 'CREATED BY'
            txt2          = SY-UNAME
          TXT3          = ' '
          TXT4          = ' '
    endcase.
    Hope it helps you
    Regrds
    Mansi

  • ALV-Grid:  Is it possible to catch "LOCAL Function Codes" in any Event ??

    Hi,
    is it possible that i can catch a "Local Function Code" in ALV Grid with an Event??
    For example if you click to an Grid Button on the toolbar than it must call an Event!
    ..........BUTTON: Local APPEND (existing in ALV Toolbar)
    Function Code: '&LOCAL&APPEND'
    My Idea is:
    --- IF i click to the Button "Local APPEND" in the ALV toolbar, than it must after this command give me an Message( "It was Successfull" ).
    But the "Local Function Codes" dont called the Event "User_command" OR "After_user_command" is there any other Event for this "Local Function Codes"???
    Have anyone an idea?
    Thanks in forward.
    Ersin

    Hi,
    See following thread.
    http://scn.sap.com/thread/715996
    Thanks
    Santosh

  • Function code for dropdown on OO ALV Grid to trigger user_command

    Hi Experts,
    I know we can add a dropdown to a column of an OO ALV Grid, set values to the dropdown list and allow the user to select some these values.
    However , what I'm not sure is that if we can *assign a function code to the dropdown * which would then trigger the event user_command ( PAI ) of the ALV class so I can handle the changes to when a particular value is selected from a dropdown list, just like we do in normal dialogs.
    Now I know that I can register the 'Enter' event and handle the data changes in data_changed event, but that is something I want to avoid the user from doing as far as possible to make the report more user friendly.
    Awaiting your valuable inputs and would really appreciate your help.
    Thanks & regards,
    Advait

    Hi Advait,
    No problem. Yes, this functionality requires changing the focus to other cell.
    I think there is other solution. As the dropdown is kind of F4 activity try this way:
    data: it_f4 type lvc_t_f4,
            wa_f4 type lvc_s_f4.
            wa_f4-FIELDNAME = 'CONNID'.
            wa_f4-REGISTER = 'X'.
            wa_f4-GETBEFORE = 'X'.
            wa_f4-CHNGEAFTER = 'X'.
            append wa_f4 to it_f4.
    "register F4 event
      CALL METHOD g_alv_grid_ref->register_f4_for_fields
        EXPORTING
          it_f4  = it_f4.
    "Once you try to pick the value HANDLE_DATA_CHANGED event will be triggered
    "Definition
         methods:
         handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
                                  IMPORTING er_data_changed e_onf4 e_onf4_before e_onf4_after,
    "Implementation
    METHOD handle_data_changed .
        DATA: ls_mod_cells TYPE lvc_s_modi.
        IF e_onf4_before = 'X'.
          MESSAGE 'Data changed before F4' TYPE 'I'.
        ENDIF.
        IF e_onf4 = 'X'.   "if event triggered by F4
          MESSAGE 'Data changed on F4' TYPE 'I'.
        ENDIF.
        IF e_onf4_after = 'X'.
          MESSAGE 'Data changed after F4' TYPE 'I'.
        ENDIF.
       "here you know which cell was modified
        LOOP AT er_data_changed->mt_mod_cells INTO ls_mod_cells.
         "just example test case, here you can implement your code for modified cells
          IF ls_mod_cells-value >=5.
            CALL METHOD er_data_changed->add_protocol_entry
              EXPORTING
                i_msgid     = 'SABAPDOCU'
                i_msgty     = 'E'
                i_msgno     = '888'
                i_msgv1     = 'Only numbers below 5 are possibe'
                i_msgv2     = 'Please correct'
                i_fieldname = ls_mod_cells-fieldname
                i_row_id    = ls_mod_cells-row_id.
            CALL METHOD er_data_changed->modify_cell
              EXPORTING
                i_fieldname = ls_mod_cells-fieldname
                i_row_id    = ls_mod_cells-row_id
                i_value     = space.
          ENDIF.
        ENDLOOP.
      ENDMETHOD.                    "handle_data_changed
    This approach works fine for picking value from input help. Never tried it for dropdown list. You have to try it out.
    Regards
    Marcin

  • Re : function codes that r available in ALV o/pu2019s.

    Hi
        How or where to find the function codes that r available in ALV o/pu2019s. for ex: for EXIT the fcode is %EX, for Spreadsheet its  &XXLu2026.  these things we give in menu painter.
                And what happens to the deleted sales order data, I mean in the database level ( if it s deleted its not in database table ).
    How to solve this.
    Thanks
    Anto

    Hi,
    Go to se80 ->Give standard alv program->Double Click gui status -> You can find the Lists of Fcodes.
    Please Find the Below Link
    [Help|Re: How to find function code for buttons on toolbar in oops alv]
    Hope this will be Helpful
    Thanks
    kalyan

  • Dynamic determination of function text for  function code

    Hi there,
    i have coding that logs all the function codes pressed in a report, that function codes are  defined in the GUI Status or dynamic created in a toolbar.
    In my log i have now all the function codes, but it would be better if i also have the function text of theese function codes. Is there any chance to get the function text for a given function code?
    E.G. user pressed Button "Refresh" , i log the function code "REFR", but i also want to have the text "Refresh". Is that possible?
    Thanks
    Steffen

    Hi steffen,
    try
    CALL FUNCTION 'RS_CUA_INTERNAL_FETCH'
            EXPORTING
              PROGRAM         = PV_NAME
              LANGUAGE        = FS_LANGU
            IMPORTING
              ADM             = FS_ADM
            TABLES
              STA             = T_STA
              FUN             = T_FUN
              MEN             = T_MEN
              MTX             = T_MTX
              ACT             = T_ACT
              BUT             = T_BUT
              PFK             = T_PFK
              SET             = T_SET
              DOC             = T_ATRT
              TIT             = T_TIT
              BIV             = T_BIV
            EXCEPTIONS
              NOT_FOUND       = 1
              UNKNOWN_VERSION = 2
              OTHERS          = 3.
    Regards
    Clemens

  • Function codes ininteractive  ALV

    Hello all,
    In interactive alv we can use function code as &IC1 to indicate double click .
    Here my doubt is where we can find all this function codes. Is there  any table or ?
    Thanks in advance.
    Apps.

    Hi,
    try this .
    In the alv display screen,before clicking any button( if u want to know function code ),
    press /h on the command box and press enter.This gives u message like debugging on.
    Then click on button required,it will goto debugging ,then type sy-ucomm and press F5,u will get function code associated with the button.
    Hope this helps u.

  • Alv status standard function codes

    Hello,
    I have developed an not OO ALV.
    I want to put the sort standard button. Does anybody know the function code i have to put in the status?
    Thanks

    Hi,
    Goto SE41, create a pf-status for your alv report program.
    On the next screen, click menu EXTRAS --> click option ADJUST TEMPLATES and select radiobutton LIST VIEWER --> you will get all standard buttons of alv in the pf-status.
    Delete the unwanted buttons and also you can add new buttons if reqd.
    Activate pf-status --> and apply in alv program.
    Hope this helps you.
    Regards,
    Tarun

  • Adding function code dynamically for radio buttons

    Hi Experts,
             I have two  radio buttons in standard screen which when clicked my custom logic should be executed.
    The issue here is the standard screen radio button does not have a Fcode assigned in the field properties because of this no event is triggered when the radio button is selected.
    Thank You,
    Anupama.

    Hi anu,
         Try the following procedure,
    - Combine all the radio buttons into a group. T
    - Create a common function code for all the radio buttons. F
    - Assign all the radio buttons to the same modification group. F
    - Enclose all entire radio button in a frame. F
    Also check the website it help u as u need,
    [http://help.sap.com/saphelp_nw04/Helpdata/EN/3d/c3b23782a9cc68e10000009b38f8cf/content.htm]
    Hope it helps u....
    Regards,
    Annevit

  • Problem in Data Display in Dynamic ALV Report

    Hi all,
    I am developing a Dynamic ALV report where I want display material batch (zjpack_base-charg) in column and Material (zjpack_base-matnr) & Qty (Zjpack_base-netwr) field row wise.My intention is to show report datewise for a material how many batch developed with there qty.I am sending you the code which i already wrote.Here column is developed batchwise but I am not able to show the qty against each batch.Please see my code and guide me how to display.
    REPORT  zdynamic_test                           .
    *REPORT  ztest_notepad.
    *& Declarations
    *Type-pools
    TYPE-POOLS: slis.
    *TABLES
    TABLES: zjpack_base.
    *Types
    TYPES:
          ty_fcat      TYPE lvc_s_fcat,
          ty_fcatalog  TYPE slis_fieldcat_alv.
    *Work areas
    DATA:
          wa_fcat      TYPE ty_fcat,
          wa_fcatalog  TYPE ty_fcatalog.
    *Internal tables
    DATA:
          it_fcat      TYPE STANDARD TABLE OF ty_fcat,
          it_fcatalog  TYPE STANDARD TABLE OF ty_fcatalog.
    *Type reference
    DATA:
          it_dyn_tab   TYPE REF TO data,
          wa_newline   TYPE REF TO data.
    *INTERNAL TABLE
    DATA: BEGIN OF it_itab OCCURS 0.
            INCLUDE STRUCTURE zjpack_base.
    DATA: END OF it_itab.
    *Filed symbols
    FIELD-SYMBOLS:
          <gt_table>   TYPE STANDARD TABLE,
          <fs_dyntable>,
          <fs_fldval>  TYPE ANY,
          <l_field>    TYPE ANY.
    *Variables
    DATA:
          l_fieldname  TYPE lvc_s_fcat-fieldname,
          l_tabname    TYPE lvc_s_fcat-tabname,
          l_fieldtext  TYPE lvc_s_fcat-seltext,
          l_index      TYPE char2.
    "Selection-screen
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-s11 .
    SELECT-OPTIONS:s_matnr FOR zjpack_base-matnr.
    SELECT-OPTIONS:s_charg FOR zjpack_base-charg.
    SELECT-OPTIONS:s_fdate FOR zjpack_base-fdate .
    SELECTION-SCREEN END OF BLOCK b1.
    PARAMETERS:
             p_colms   TYPE i.
    *& start-of-selection.
    START-OF-SELECTION.
      PERFORM select_data.
      PERFORM build_fieldcat.
      PERFORM create_dynamic_table.
    DO 20 TIMES.
       DO p_colms TIMES.
         l_index = sy-index.
         CONCATENATE 'FIELD' l_index INTO l_fieldname.
         ASSIGN COMPONENT l_fieldname OF STRUCTURE <fs_dyntable> TO <l_field>.
         <l_field> = sy-index.
       ENDDO.
       INSERT <fs_dyntable> INTO TABLE <gt_table>.
    ENDDO.
      LOOP AT it_itab.
        l_index = sy-tabix.
        CONCATENATE 'FIELD' l_index INTO l_fieldname.
        ASSIGN COMPONENT l_fieldname OF STRUCTURE <fs_dyntable> TO <l_field>.
        <l_field> = it_itab-matnr.
        INSERT <fs_dyntable> INTO TABLE <gt_table>.
      ENDLOOP.
      LOOP AT it_fcat INTO wa_fcat.
        PERFORM fieldcatalog1 USING: wa_fcat-fieldname
                                      wa_fcat-tabname
                                      wa_fcat-seltext.
      ENDLOOP.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          i_callback_program = 'ZTEST_NOTEPAD'
          it_fieldcat        = it_fcatalog
        TABLES
          t_outtab           = <gt_table>.
    *&      Form  BUILD_FIELDCAT
    FORM build_fieldcat .
    CLEAR: l_fieldname,
            l_tabname,
            l_fieldtext,
            l_index.
    DO  p_colms TIMES.
       CLEAR l_index.
       l_index = sy-index.
       CONCATENATE 'FIELD' l_index INTO l_fieldname.
       CONCATENATE 'Field' l_index INTO l_fieldtext.
       l_tabname = '<GT_TABLE>'.
       PERFORM fieldcatalog USING: l_fieldname
                                   l_tabname
                                   l_fieldtext.
    ENDDO.
    ENDFORM.                    " BUILD_FIELDCAT
    *&      Form  CREATE_DYNAMIC_TABLE
    FORM create_dynamic_table .
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = it_fcat
        IMPORTING
          ep_table        = it_dyn_tab.
      ASSIGN it_dyn_tab->* TO <gt_table>.
    Create dynamic work area and assign to FS
      CREATE DATA wa_newline LIKE LINE OF <gt_table>.
      ASSIGN wa_newline->* TO <fs_dyntable>.
    ENDFORM.                    " CREATE_DYNAMIC_TABLE
    *&      Form  FIELDCATALOG
    FORM fieldcatalog USING field table f_txt.
      wa_fcat-fieldname = field.
      wa_fcat-tabname   = table.
      wa_fcat-seltext = f_txt.
      APPEND wa_fcat TO it_fcat.
      CLEAR  wa_fcat.
    ENDFORM.                    " FIELDCATALOG
    *&      Form  FIELDCATALOG1
    FORM fieldcatalog1 USING field table f_txt.
      wa_fcatalog-fieldname = field.
      wa_fcatalog-tabname   = table.
      wa_fcatalog-seltext_m = f_txt.
      APPEND wa_fcatalog TO it_fcatalog.
      CLEAR  wa_fcatalog.
    ENDFORM.                    " FIELDCATALOG1
    *&      Form  SELECT_DATA
          text
    -->  p1        text
    <--  p2        text
    FORM select_data .
    DATA: v_srlno TYPE i.
      SELECT matnr charg blqty
      INTO CORRESPONDING FIELDS OF it_itab
      FROM zjpack_base
      WHERE matnr IN s_matnr
      AND   charg IN s_charg
      AND   fdate IN s_fdate.
        COLLECT it_itab.
      ENDSELECT.
    v_srlno.
    LOOP AT it_itab.
       v_srlno = v_srlno + 1.
    ENDLOOP.
      CLEAR: l_fieldname,
              l_tabname,
              l_fieldtext,
              l_index.
    1st Field
    l_index = sy-tabix.
      CONCATENATE 'FIELD' '1' INTO l_fieldname.
      l_fieldtext = 'MATNR'.
      l_tabname = '<GT_TABLE>'.
      PERFORM fieldcatalog USING: l_fieldname
                                  l_tabname
                                  l_fieldtext.
    Other fields
      LOOP AT it_itab.
        CLEAR l_index.
        l_index = sy-tabix + 1.
        CONCATENATE 'FIELD' l_index INTO l_fieldname.
        CONCATENATE 'CHARG-' it_itab-charg INTO l_fieldtext.
        l_tabname = '<GT_TABLE>'.
        PERFORM fieldcatalog USING: l_fieldname
                                    l_tabname
                                    l_fieldtext.
      ENDLOOP.
    Please guide me how my problem will solve.
    Thanks & Regards
    Nirmal

    Hi all, I am developing a Dynamic ALV report where I want display material batch (zjpack_base-charg) in column and Material (zjpack_base-matnr) & Qty (Zjpack_base-netwr) field row wise.My intention is to show report datewise for a material how many batch developed with there qty.I am sending you the code which i already wrote.Here column is developed batchwise but I am not able to show the qty against each batch.Please see my code and guide me how to display.
    *& Report  ZDYNAMIC_TEST                                               *
    REPORT  zdynamic_test                           .
    *REPORT  ztest_notepad.
    *& Declarations
    *Type-pools
    TYPE-POOLS: slis.
    *TABLES
    TABLES: zjpack_base.
    *Types
    TYPES:
          ty_fcat      TYPE lvc_s_fcat,
          ty_fcatalog  TYPE slis_fieldcat_alv.
    *Work areas
    DATA:
          wa_fcat      TYPE ty_fcat,
          wa_fcatalog  TYPE ty_fcatalog.
    *Internal tables
    DATA:
          it_fcat      TYPE STANDARD TABLE OF ty_fcat,
          it_fcatalog  TYPE STANDARD TABLE OF ty_fcatalog.
    *Type reference
    DATA:
          it_dyn_tab   TYPE REF TO data,
          wa_newline   TYPE REF TO data.
    *INTERNAL TABLE
    DATA: BEGIN OF it_itab OCCURS 0.
            INCLUDE STRUCTURE zjpack_base.
    DATA: END OF it_itab.
    *Filed symbols
    FIELD-SYMBOLS:
          <gt_table>   TYPE STANDARD TABLE,
          <fs_dyntable>,
          <fs_fldval>  TYPE ANY,
          <l_field>    TYPE ANY.
    *Variables
    DATA:
          l_fieldname  TYPE lvc_s_fcat-fieldname,
          l_tabname    TYPE lvc_s_fcat-tabname,
          l_fieldtext  TYPE lvc_s_fcat-seltext,
          l_index      TYPE char2.
    "Selection-screen
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-s11 .
    SELECT-OPTIONS:s_matnr FOR zjpack_base-matnr.
    SELECT-OPTIONS:s_charg FOR zjpack_base-charg.
    SELECT-OPTIONS:s_fdate FOR zjpack_base-fdate .
    SELECTION-SCREEN END OF BLOCK b1.
    PARAMETERS:
             p_colms   TYPE i.
    *& start-of-selection.
    START-OF-SELECTION.
      PERFORM select_data.
      PERFORM build_fieldcat.
      PERFORM create_dynamic_table.
    *  DO 20 TIMES.
    *    DO p_colms TIMES.
    *      l_index = sy-index.
    *      CONCATENATE 'FIELD' l_index INTO l_fieldname.
    *      ASSIGN COMPONENT l_fieldname OF STRUCTURE <fs_dyntable> TO <l_field>.
    *      <l_field> = sy-index.
    *    ENDDO.
    *    INSERT <fs_dyntable> INTO TABLE <gt_table>.
    *  ENDDO.
      LOOP AT it_itab.
        l_index = sy-tabix.
        CONCATENATE 'FIELD' l_index INTO l_fieldname.
        ASSIGN COMPONENT l_fieldname OF STRUCTURE <fs_dyntable> TO <l_field>.
        <l_field> = it_itab-matnr.
        INSERT <fs_dyntable> INTO TABLE <gt_table>.
      ENDLOOP.
      LOOP AT it_fcat INTO wa_fcat.
        PERFORM fieldcatalog1 USING: wa_fcat-fieldname
                                      wa_fcat-tabname
                                      wa_fcat-seltext.
      ENDLOOP.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          i_callback_program = 'ZTEST_NOTEPAD'
          it_fieldcat        = it_fcatalog
        TABLES
          t_outtab           = <gt_table>.
    *&      Form  BUILD_FIELDCAT
    FORM build_fieldcat .
    *  CLEAR: l_fieldname,
    *         l_tabname,
    *         l_fieldtext,
    *         l_index.
    *  DO  p_colms TIMES.
    *    CLEAR l_index.
    *    l_index = sy-index.
    *    CONCATENATE 'FIELD' l_index INTO l_fieldname.
    *    CONCATENATE 'Field' l_index INTO l_fieldtext.
    *    l_tabname = '<GT_TABLE>'.
    *    PERFORM fieldcatalog USING: l_fieldname
    *                                l_tabname
    *                                l_fieldtext.
    *  ENDDO.
    ENDFORM.                    " BUILD_FIELDCAT
    *&      Form  CREATE_DYNAMIC_TABLE
    FORM create_dynamic_table .
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = it_fcat
        IMPORTING
          ep_table        = it_dyn_tab.
      ASSIGN it_dyn_tab->* TO <gt_table>.
    * Create dynamic work area and assign to FS
      CREATE DATA wa_newline LIKE LINE OF <gt_table>.
      ASSIGN wa_newline->* TO <fs_dyntable>.
    ENDFORM.                    " CREATE_DYNAMIC_TABLE
    *&      Form  FIELDCATALOG
    FORM fieldcatalog USING field table f_txt.
      wa_fcat-fieldname = field.
      wa_fcat-tabname   = table.
      wa_fcat-seltext = f_txt.
      APPEND wa_fcat TO it_fcat.
      CLEAR  wa_fcat.
    ENDFORM.                    " FIELDCATALOG
    *&      Form  FIELDCATALOG1
    FORM fieldcatalog1 USING field table f_txt.
      wa_fcatalog-fieldname = field.
      wa_fcatalog-tabname   = table.
      wa_fcatalog-seltext_m = f_txt.
      APPEND wa_fcatalog TO it_fcatalog.
      CLEAR  wa_fcatalog.
    ENDFORM.                    " FIELDCATALOG1
    *&      Form  SELECT_DATA
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM select_data .
    *  DATA: v_srlno TYPE i.
      SELECT matnr charg blqty
      INTO CORRESPONDING FIELDS OF it_itab
      FROM zjpack_base
      WHERE matnr IN s_matnr
      AND   charg IN s_charg
      AND   fdate IN s_fdate.
        COLLECT it_itab.
      ENDSELECT.
    *  v_srlno.
    *  LOOP AT it_itab.
    *    v_srlno = v_srlno + 1.
    *  ENDLOOP.
      CLEAR: l_fieldname,
              l_tabname,
              l_fieldtext,
              l_index.
    * 1st Field
    *  l_index = sy-tabix.
      CONCATENATE 'FIELD' '1' INTO l_fieldname.
      l_fieldtext = 'MATNR'.
      l_tabname = '<GT_TABLE>'.
      PERFORM fieldcatalog USING: l_fieldname
                                  l_tabname
                                  l_fieldtext.
    * Other fields
      LOOP AT it_itab.
        CLEAR l_index.
        l_index = sy-tabix + 1.
        CONCATENATE 'FIELD' l_index INTO l_fieldname.
        CONCATENATE 'CHARG-' it_itab-charg INTO l_fieldtext.
        l_tabname = '<GT_TABLE>'.
        PERFORM fieldcatalog USING: l_fieldname
                                    l_tabname
                                    l_fieldtext.
      ENDLOOP.
    ENDFORM.                    " SELECT_DATA

  • Rows as columns and dynamic alv display

    Hi everyone,
    I need to build a intenal table dynamically as well as dispaly few rows as columns in alv output.
    I have seen posts where internal table has been created dynamicaaly as well seen the posts where rows of the table are displayed as columns but, can we achieve both the functionalities at same time.
    I have table as:
    SO     PO     Date    MAT    QTY  
    1        A       X    Y1      10 
                           K1      15
                           M2      11
    2       B       X1     Y2       5
                           M1      12
    3       C       1x     Z1      15
                           K1       6
                           L1      10
    Now the ouput has to be :
    SO     PO   Date     MAT-Y1    MAT-K1    MAT-Y2   MAT-L1     Mat-Z1    MAT-M1   MAT-M2
    1        A     X      10          15                                               11            
    2        B     X1                         5                             12                
    3        C     1X                  6                10          15                                       
    I will not be knowing the number of materials untill runtime(dynamic) and as well the rows has to be displayed as columns. Is it possible to do that.
    Regards
    Edited by: Madhu Posanipalli on Jun 6, 2011 4:51 PM

    Hi,
    Check below code. It will work definitly.
    *& Report  YTEST_PROG_RP
    REPORT  YTEST_PROG_RP.
    type-POOLs slis.
    TYPES: BEGIN OF ty_tab,
        so TYPE i,
        po TYPE c,
        date(2) TYPE c,
        mat(2) TYPE c,
        qty TYPE i,
    END OF ty_tab.
    DATA: itab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,
          jtab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,
          ktab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,
          wa_tab TYPE ty_tab, wa_j TYPE ty_tab, wa_k TYPE ty_tab.
    FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,
                   <fs_dyntable>,
                   <fs_fldval> type any.
    *ALV data declarations
    data: fieldcatalog type LVC_T_FCAT, " with header line, "slis_t_fieldcat_alv with header line,
          fieldcatalog1 TYPE LVC_s_FCAT,
          fieldcatalog2 type  slis_t_fieldcat_alv with header line,
          gd_tab_group type slis_t_sp_group_alv,
          gd_layout    type slis_layout_alv,
          gd_repid     like sy-repid,
          gt_events     type slis_t_event,
          gd_prntparams type slis_print_alv.
    DATA t_newtable TYPE REF TO data.
    DATA t_newline  TYPE REF TO data.
    DATA wa_flname TYPE string.
    *Start-of-selection.
    START-OF-SELECTION.
      perform data_retrieval.
      perform build_fieldcatalog.
      perform dynamic_table.
      perform build_layout.
      perform build_events.
      perform build_print_params.
      perform display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
          Build Fieldcatalog for ALV Report
    form build_fieldcatalog.
      DATA: lv_field1 TYPE string, lv_cnt LIKE sy-tabix VALUE 3, itab_lines TYPE i.
      DATA: fieldname(20) TYPE c.
      DATA: fieldvalue(10) TYPE c.
      DATA: index(3) TYPE c.
      DATA: wa_cat LIKE LINE OF fieldcatalog2,
      wa_colno(2) TYPE n,
      wa_flname(5) TYPE c. .
      fieldcatalog1-fieldname   = 'SO'.
    fieldcatalog1-seltext   = 'SO'.
      fieldcatalog1-col_pos     = 1.
      fieldcatalog1-outputlen   = 2.
    fieldcatalog-emphasize   = 'X'.
    fieldcatalog-key         = 'X'.
    fieldcatalog-do_sum      = 'X'.
    fieldcatalog-no_zero     = 'X'.
      append fieldcatalog1 to fieldcatalog.
      clear  fieldcatalog1.
      fieldcatalog1-fieldname   = 'PO'.
    fieldcatalog1-seltext   = 'PO'.
      fieldcatalog1-col_pos     = 2.
      fieldcatalog1-outputlen   = 2.
      append fieldcatalog1 to fieldcatalog.
      clear  fieldcatalog1.
      fieldcatalog1-fieldname   = 'DATE'.
    fieldcatalog1-seltext   = 'Date'.
      fieldcatalog1-col_pos     = 3.
      fieldcatalog1-outputlen   = 2.
      append fieldcatalog1 to fieldcatalog.
      clear  fieldcatalog1.
      LOOP AT itab INTO wa_tab.
        lv_cnt = lv_cnt + 1.
        CONCATENATE 'MAT-' wa_tab-mat into lv_field1.
        TRANSLATE lv_field1 TO UPPER CASE.
        fieldcatalog1-fieldname   = lv_field1.
       fieldcatalog1-seltext   = lv_field1.
        fieldcatalog1-col_pos     = lv_cnt.
        fieldcatalog1-outputlen   = 6.
        append fieldcatalog1 to fieldcatalog.
        clear fieldcatalog1.
        CLEAR: lv_field1, wa_tab.
      ENDLOOP.
      CLEAR lv_cnt.
    Create dynamic internal table and assign to FS
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = fieldcatalog
        IMPORTING
          ep_table        = t_newtable.
      ASSIGN t_newtable->* TO <t_dyntable>.
      CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
      ASSIGN t_newline->* TO <fs_dyntable>.
    DESCRIBE TABLE fieldcatalog LINES itab_lines.
      loop at fieldcatalog INTO fieldcatalog1.
        CLEAR wa_cat.
        wa_cat-fieldname = fieldcatalog1-fieldname.
        wa_cat-seltext_s = fieldcatalog1-fieldname.
        wa_cat-outputlen = fieldcatalog1-outputlen.
        APPEND wa_cat TO fieldcatalog2.
        CLEAR fieldcatalog1.
      ENDLOOP.
    endform.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
          Build layout for ALV grid report
    form build_layout.
    gd_layout-no_input          = 'X'.
    gd_layout-colwidth_optimize = 'X'.
    gd_layout-totals_text       = 'Totals'(201).
    gd_layout-totals_only        = 'X'.
    gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
                                            "click(press f2)
    gd_layout-zebra             = 'X'.
    gd_layout-group_change_edit = 'X'.
    gd_layout-header_text       = 'helllllo'.
    endform.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
          Display report using ALV grid
    form display_alv_report.
      gd_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
               i_callback_program      = gd_repid
               i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
               i_callback_user_command = 'USER_COMMAND'
               i_grid_title           = outtext
               is_layout               = gd_layout
                it_fieldcat             = fieldcatalog2[]
               it_special_groups       = gd_tabgroup
               it_events               = gt_events
               is_print                = gd_prntparams
               i_save                  = 'X'
               is_variant              = z_template
           tables
                t_outtab                = <t_dyntable>
           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.                    " DISPLAY_ALV_REPORT
    *&      Form  DATA_RETRIEVAL
          Retrieve data form EKPO table and populate itab it_ekko
    form data_retrieval.
      DATA: lv_index LIKE sy-tabix.
      wa_tab-so = 1.
      wa_tab-po = 'A'.
      wa_tab-date = 'X'.
      wa_tab-mat = 'Y1'.
      wa_tab-qty = 10.
      append wa_tab to itab.
      clear wa_tab.
      wa_tab-mat = 'K1'.
      wa_tab-qty = 15.
      append wa_tab to itab.
      CLEAR wa_tab.
      wa_tab-mat = 'M2'.
      wa_tab-qty = 11.
      append wa_tab to itab.
      CLEAR wa_tab.
      wa_tab-so = 2.
      wa_tab-po = 'B'.
      wa_tab-date = 'X1'.
      wa_tab-mat = 'Y2'.
      wa_tab-qty = 5.
      append wa_tab to itab.
      CLEAR wa_tab.
      wa_tab-mat = 'M1'.
      wa_tab-qty = 12.
      append wa_tab to itab.
      CLEAR wa_tab.
      wa_tab-so = 3.
      wa_tab-po = 'C'.
      wa_tab-date = '1x1'.
      wa_tab-mat = 'Z1'.
      wa_tab-qty = 15.
      append wa_tab to itab.
      CLEAR wa_tab.
    wa_tab-mat = 'K1'.
    wa_tab-qty = 6.
    append wa_tab to itab.
    CLEAR wa_tab.
      wa_tab-mat = 'L1'.
      wa_tab-qty = 10.
      append wa_tab to itab.
      CLEAR wa_tab.
      LOOP AT itab INTO wa_tab.
        if wa_tab-so is NOT INITIAL AND wa_tab-po is NOT INITIAL AND wa_tab-date is NOT INITIAL.
          wa_j-so = wa_tab-so.
          wa_j-po = wa_tab-po.
          wa_j-date = wa_tab-date.
          lv_index = wa_tab-so.
        else.
          READ TABLE itab INTO wa_j WITH KEY so = lv_index.
        ENDIF.
        wa_j-mat = wa_tab-mat.
        wa_j-qty = wa_tab-qty.
        APPEND wa_j to jtab.
        CLEAR: wa_tab, wa_j.
      ENDLOOP.
    endform.                    " DATA_RETRIEVAL
    Form  TOP-OF-PAGE                                                 *
    ALV Report Header                                                 *
    Form top-of-page.
    **ALV Header declarations
    *data: t_header type slis_t_listheader,
         wa_header type slis_listheader,
         t_line like wa_header-info,
         ld_lines type i,
         ld_linesc(10) type c.
    Title
    wa_header-typ  = 'H'.
    wa_header-info = 'EKKO Table Report'.
    append wa_header to t_header.
    clear wa_header.
    Date
    wa_header-typ  = 'S'.
    wa_header-key = 'Date: '.
    CONCATENATE  sy-datum+6(2) '.'
                  sy-datum+4(2) '.'
                  sy-datum(4) INTO wa_header-info.   "todays date
    append wa_header to t_header.
    clear: wa_header.
    Total No. of Records Selected
    describe table it_ekko lines ld_lines.
    ld_linesc = ld_lines.
    concatenate 'Total No. of Records Selected: ' ld_linesc
                       into t_line separated by space.
    wa_header-typ  = 'A'.
    wa_header-info = t_line.
    append wa_header to t_header.
    clear: wa_header, t_line.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
          exporting
               it_list_commentary = t_header.
               i_logo             = 'Z_LOGO'.
    endform.                    "top-of-page
          FORM USER_COMMAND                                          *
          --> R_UCOMM                                                *
          --> RS_SELFIELD                                            *
    FORM user_command USING r_ucomm LIKE sy-ucomm
                      rs_selfield TYPE slis_selfield.
    Check function code
    CASE r_ucomm.
       WHEN '&IC1'.
      Check field clicked on within ALVgrid report
       IF rs_selfield-fieldname = 'EBELN'.
        Read data table, using index of row user clicked on
         READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
        Set parameter ID for transaction screen field
         SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
        Sxecute transaction ME23N, and skip initial data entry screen
         CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
       ENDIF.
    ENDCASE.
    ENDFORM.                    "user_command
    *&      Form  BUILD_EVENTS
          Build events table
    form build_events.
    data: ls_event type slis_alv_event.
    call function 'REUSE_ALV_EVENTS_GET'
          exporting
               i_list_type = 0
          importing
               et_events   = gt_events[].
    read table gt_events with key name =  slis_ev_end_of_page
                              into ls_event.
    if sy-subrc = 0.
       move 'END_OF_PAGE' to ls_event-form.
       append ls_event to gt_events.
    endif.
       read table gt_events with key name =  slis_ev_end_of_list
                              into ls_event.
    if sy-subrc = 0.
       move 'END_OF_LIST' to ls_event-form.
       append ls_event to gt_events.
    endif.
    endform.                    " BUILD_EVENTS
    *&      Form  BUILD_PRINT_PARAMS
          Setup print parameters
    form build_print_params.
    gd_prntparams-reserve_lines = '3'.   "Lines reserved for footer
    gd_prntparams-no_coverpage = 'X'.
    endform.                    " BUILD_PRINT_PARAMS
    *&      Form  END_OF_PAGE
    form END_OF_PAGE.
      data: listwidth type i,
            ld_pagepos(10) type c,
            ld_page(10)    type c.
      write: sy-uline(50).
      skip.
      write:/40 'Page:', sy-pagno .
    endform.                    "END_OF_PAGE
    *&      Form  END_OF_LIST
    form END_OF_LIST.
      data: listwidth type i,
            ld_pagepos(10) type c,
            ld_page(10)    type c.
      skip.
      write:/40 'Page:', sy-pagno .
    endform.                    "END_OF_LIST
    *&      Form  dynamic_table
          text
    -->  p1        text
    <--  p2        text
    FORM dynamic_table .
      DATA: lv_s1 TYPE string, lv_s2 TYPE string.
      DATA lv_mat TYPE string.
      DATA: fieldvalue(10) TYPE c.
      ktab[] = jtab[].
      delete ADJACENT DUPLICATES FROM ktab COMPARING so.
      loop at ktab INTO wa_tab.
    Field1
        wa_flname = 'SO'.
        fieldvalue = wa_tab-so.
        CONDENSE    fieldvalue NO-GAPS.
        ASSIGN COMPONENT  wa_flname
            OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
        <fs_fldval> =  fieldvalue.
        CLEAR fieldvalue.
    Field2
        wa_flname = 'PO'.
        fieldvalue = wa_tab-po.
        CONDENSE    fieldvalue NO-GAPS.
        ASSIGN COMPONENT  wa_flname
            OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
        <fs_fldval> =  fieldvalue.
        CLEAR fieldvalue.
    Field3
        wa_flname = 'DATE'.
        fieldvalue = wa_tab-date.
        CONDENSE    fieldvalue NO-GAPS.
        ASSIGN COMPONENT  wa_flname
            OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
        <fs_fldval> =  fieldvalue.
        CLEAR fieldvalue.
        loop at jtab INTO wa_j WHERE so = wa_tab-so.
          CONCATENATE 'MAT-' wa_j-mat INTO lv_mat.
          wa_flname = lv_mat.
          fieldvalue = wa_j-qty.
          CONDENSE    fieldvalue NO-GAPS.
          ASSIGN COMPONENT  wa_flname
              OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
          <fs_fldval> =  fieldvalue.
          CLEAR: wa_j, fieldvalue.
        ENDLOOP.
        APPEND <fs_dyntable> TO <t_dyntable>.
        CLEAR wa_tab.
        FREE <fs_dyntable>.
      ENDLOOP.
    ENDFORM.                    " dynamic_table
    Ram.

Maybe you are looking for