Manipulate Layout on ALV Grid with dynamic table

Dear all
i'm generating a dynamic table depending of a date selection. That means that I show columns for weeks and the quantity of weeky migh change.
Now the users wants to have a specific layout of the ALV grid with totals. When he saves the layout, only the weeks at this selection will show the next time he runs the programm with a larger selection.
a) Is it possible to modify the layout during runtime by programming?
b) Do you have any other ideas how to solve this problem?
Thank you

You don't know the names of your columns? hmm you do, because before you created dynamic table you had to create field catalog, so the structure and column names of newly (dynamically) created table will be the same like defined in the field catalog.
The last loop also does not look good, in my opinion should be something like:
LOOP AT lt_datatable +(my first table)+ ASSIGNING <ls_data4>.
    AT NEW pernr.
      APPEND initial line to <fs_1> assigning <fs_2>.
      <fs_2>-pernr = <ls_data4>-pernr.
    ENDAT.
    ASSIGN COMPONENT <ls_data4>-wage_type OF STRUCTURE <fs_2> TO <fs_5>.
    <fs_5> = <ls_data4>-amount.
ENDLOOP.
also keep in mind that number of calls of method cl_alv_table_create=>create_dynamic_table is limited to 36 (?) calls within one program session because it uses dynamic subroutine pool behind so you will have short dump if you will execute that 37 times.

Similar Messages

  • Here's how to do ALV (OO) with dynamic fcat, int table and editable data

    Hi everybody
    Here's a more useful approach to ALV grid with OO using dynamic table, data NOT from DDIC, dynamic FCAT and how to get changed lines from the grid when ENTER key is pressed.
    It's really not too dificult but I think this is more useful than the ever present SFLIGHT methods from the demos.
    This also defines a subclass of cl_gui_alv_grid so you can access the protected attributes / methods of that class.
    You don't need to add the class via SE24 -- done fron this ABAP.
    When you run it click Edit for the first time.
    After editing data press ENTER and the break point should bring you into the relevant method.
    Code developed on NW2004S trial version but also works on rel 6.40 on a "Real" system.
    The code should work without any changes on any system >=6.40.
    All you need to do is to create a blank screen 100 via SE51  with a custom container on it called CCONTAINER1.
    The rest of the code can just be uploaded into your system using the SE38 upload facility.
    When running the program click on the EDIT button to enable the edit functionality of the grid.
    Change your data and when you press ENTER you should get the break-point where you can see the original table and changed rows.
    This program is actually quite general as it covers Dynamic tables, building a dynamic fcat where your table fields are NOT in the DDIC, intercepting the ENTER key via using an event, and accessing the protected attributes of the cl_gui_alv_grid by defining a subclass of this class in the abap.
    I've seen various questions relating to all these functions but none in my view ever answers the questions in a simple manner. I hope this simple program will answer all these and show how using OO ALV is actually quite easy and people shouldn't be scared of using OO.
    Have fun and award points if useful.
    Cheers
    Jimbo.
    <b>PROGRAM zdynfieldcat.
    Simple test of dynamic ITAB with user defined (not ddic) fields
    Build dynamic fcat
    use ALV grid to display and edit.
    *When edit mode set to 1 toolbar gives possibility of adding and
    *deleting rows.
    *Define subclass of cl_gui_alv_grid so we can use protected attributes
    *and methods.
    Add event handler to intercept user entering data and pressing the
    *ENTER key.
    When enter key is pressed get actual value of NEW table (all rows)
    rather than just the changed data.
    *use new RTTI functionality to retrieve internal table structure
    *details.
    Create a blank screen 100  with a custom container called CCONTAINER1.
    James Hawthorne
    include <icon>.
    define  any old internal structure  NOT in DDIC
    types: begin of s_elements,
           anyfield1(20) type c,
           anyfield2(20) type c,
           anyfield3(20) type c,
           anyfield4(20) type c,
           anyfield5(11) type n,
           end of s_elements.
    types:  lt_rows  type lvc_t_roid.
    Note new RTTI functionality allows field detail retrieval
    at runtime for dynamic tables.
    data:   wa_element type s_elements ,
            wa_data type s_elements,
            c_index type sy-index,
            c_dec2 type s_elements-anyfield5,
            wa_it_fldcat type lvc_s_fcat,
            it_fldcat type lvc_t_fcat,
            lr_rtti_struc TYPE REF TO cl_abap_structdescr,    "RTTI
            lt_comp TYPE cl_abap_structdescr=>component_table,"RTTI
            ls_comp LIKE LINE OF lt_comp,                     "RTTI
            zog  like line of lr_rtti_struc->components,      "RTTI
            struct_grid_lset type lvc_s_layo,
            l_valid  type c,
            new_table type ref to data.
    field-symbols: <dyn_table> type standard table,
                   <actual_tab> type standard table,
                   <fs1> type ANY,
                   <FS2> TYPE TABLE.
    data: grid_container1 type ref to cl_gui_custom_container.
    class lcl_grid_event_receiver definition deferred.
    data: g_event_receiver type ref to lcl_grid_event_receiver.
    data: ls_modcell type LVC_S_MODI,
          stab type ref to data,
          sdog type  s_elements.      .
    class lcl_grid_event_receiver definition.
      public section.
        methods:
        handle_data_changed
             for event data_changed of cl_gui_alv_grid
                 importing er_data_changed,
           toolbar for event toolbar of cl_gui_alv_grid
                     importing e_object
                               e_interactive,
          user_command for event user_command of cl_gui_alv_grid
                     importing e_ucomm.
    endclass.
    *implementation of Grid event-handler class
    class lcl_grid_event_receiver implementation.
    method handle_data_changed.
    code whatever required after data entry.
    various possibilites here as you can get back Cell(s) changed
    columns or the entire updated table.
    Data validation is also possible here.
    perform check_data using er_data_changed.
    endmethod.
    Method for handling all creation/modification calls to the toolbar
      method toolbar.
        data : ls_toolbar type stb_button.
    Define Custom Button in the toolbar
        clear ls_toolbar.
        move 0 to ls_toolbar-butn_type.
        move 'EDIT' to ls_toolbar-function.
        move space to ls_toolbar-disabled.
        move 'Edit' to ls_toolbar-text.
        move icon_change_text to ls_toolbar-icon.
        move 'Click2Edit' to ls_toolbar-quickinfo.
        append ls_toolbar to e_object->mt_toolbar.
        clear ls_toolbar.
        move 0 to ls_toolbar-butn_type.
        move 'UPDA' to ls_toolbar-function.
        move space to ls_toolbar-disabled.
        move 'Update' to ls_toolbar-text.
        move icon_system_save to ls_toolbar-icon.
        move 'Click2Update' to ls_toolbar-quickinfo.
        append ls_toolbar to e_object->mt_toolbar.
        clear ls_toolbar.
        move 0 to ls_toolbar-butn_type.
        move 'EXIT' to ls_toolbar-function.
        move space to ls_toolbar-disabled.
        move 'Exit' to ls_toolbar-text.
        move icon_system_end to ls_toolbar-icon.
        move 'Click2Exit' to ls_toolbar-quickinfo.
        append ls_toolbar to e_object->mt_toolbar.
      endmethod.
      method user_command.
        case e_ucomm .
          when 'EDIT'.          "From Tool bar
            perform set_input.
             perform init_grid.
          when 'UPDA'.          "From Tool bar
            perform refresh_disp.
            perform update_table.
          when 'EXIT'.          "From Tool bar
            leave program.
        endcase.
      endmethod.
    endclass.
    class zcltest definition inheriting from  cl_gui_alv_grid.
    define this as a subclass so we can access the protected attributes
    of the superclass cl_gui_alv_grid
    public section.
    methods: constructor, disp_tab.
    endclass.
    need this now to instantiate object
    as we are using subclass rather than the main cl_gui_alv_grid.
    class zcltest implementation.
    METHOD constructor.
    CALL METHOD super->constructor
            exporting i_appl_events = 'X'
               i_parent = grid_container1.
    endmethod.
    method disp_tab.
    FIELD-SYMBOLS: <outtab> TYPE STANDARD TABLE.
    break-point 1.
    mt_outtab is the data table held as a protected attribute
    in class cl_gui_alv_grid.
    ASSIGN me->mt_outtab->* TO <outtab>.  "Original data
    do whatever you want with <outtab>
    contains data BEFORE changes each time.
    Note that NEW (Changed) table has been obtained already by
    call to form check_data USING P_ER_DATA_CHANGED
             TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
    Entered data is in table defined by <fs2>
    In this method you can compare original and changed data.
    Easier than messing around with individual cells.
    do what you want with data in <fs2>  validate / update / merge etc
    endmethod.
    endclass.
    data :
        ok_code like sy-ucomm,
        save_ok like sy-ucomm,
        i4 type int4,
    Container Object [grid_container]
    now created via method constructor
    in the subclass zcltest.
    Control Object [grid]
    grid1 type ref to zcltest,
    Event-Handler Object [grid_handler]
    grid_handler type ref to lcl_grid_event_receiver.
    start-of-selection.
    call screen 100.
    module status_0100 output.
    now display it as grid
    if grid_container1 is initial.
        create object grid_container1
            exporting
              container_name = 'CCONTAINER1'.
        create object grid1.
         break-point 1.
        create object grid_handler.
        set handler:
           grid_handler->user_command for grid1,
           grid_handler->toolbar for grid1,
           grid_handler->handle_data_changed for grid1.
    perform create_dynamic_fcat.
    perform create_dynamic_itab.
    perform populate_dynamic_itab.
    perform init_grid.
    perform register_enter_event.
    set off ready for input initially
    i4 = 0.
      call method grid1->set_ready_for_input
             exporting
               i_ready_for_input = i4.
    endif.
    endmodule.
    module user_command_0100 input.
    *PAI not needed in OO ALV anymore as User Commands are handled as events
    *in method user_command.
    *we can also get control if the Data entered and the ENTER is pressed by
    *raising an event.
    Control then returns to method handle_data_changed.
    endmodule.
    form create_dynamic_fcat.
    get structure of our user table for building field catalog
    Use the RTTI functionality
    lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).
    Build field catalog just use basic data here
    colour specific columns as well
    loop at lr_rtti_struc->components into zog.
    c_index = c_index + 1.
    clear wa_it_fldcat.
      wa_it_fldcat-fieldname = zog-name .
      wa_it_fldcat-datatype =  zog-type_kind.
      wa_it_fldcat-inttype =   zog-type_kind.
      wa_it_fldcat-intlen =    zog-length.
      wa_it_fldcat-decimals =  zog-decimals.
      wa_it_fldcat-lowercase = 'X'.
      if c_index eq 2.
      wa_it_fldcat-emphasize = 'C411'.
         endif.
        if c_index eq 3.
      wa_it_fldcat-emphasize = 'C511'.
       endif.
      append wa_it_fldcat to it_fldcat .
    endloop.
    endform.
    form create_dynamic_itab.
    Create dynamic internal table and assign to field sysmbol.
    Use dynamic field catalog just built.
    call method cl_alv_table_create=>create_dynamic_table
                 exporting
                    it_fieldcatalog = it_fldcat
                 importing
                    ep_table        = new_table.
    assign new_table->* to <dyn_table>.
    endform.
    form populate_dynamic_itab.
    load up a line of the dynamic table
    c_dec2 = c_dec2 + 11.
    wa_element-anyfield1 = 'Tabbies'.
    wa_element-anyfield2 = 'ger.shepards'.
    wa_element-anyfield3  = 'White mice'.
    wa_element-anyfield4 =  'Any old text'.
    wa_element-anyfield5 =  c_dec2.
    append  wa_element to <dyn_table>.
    endform.
    form check_data USING P_ER_DATA_CHANGED
               TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
    Get altered data back
      ASSIGN   p_er_data_changed->mp_mod_rows TO <FS1>.
    stab =       p_er_data_changed->mp_mod_rows.
    ASSIGN STAB->* TO <FS2>.
    LOOP AT <FS2> INTO sdog.
    ALV grid display with altered data is now in <fs2>.
    do any extra processing you want here
    endloop.
    now display new table
    call method grid1->disp_tab.
    endform.
    form exit_program.
      call method grid_container1->free.
      call method cl_gui_cfw=>flush.
      leave program.
    endform.
    form refresh_disp.
      call method grid1->refresh_table_display.
    endform.
    form update_table.
    The dynamic table here is the changed table read from the grid
    after user has changed it
    Data can be saved to DB or whatever.
    loop at <dyn_table> into wa_element.
    do what you want with the data here
    endloop.
    switch off edit mode again for next function
    i4 = 0.
      call method grid1->set_ready_for_input
          exporting
              i_ready_for_input = i4.
    endform.
    form set_input.
    i4 = 1.
      call method grid1->set_ready_for_input
         exporting
           i_ready_for_input = i4.
    endform.
    form switch_input.
    if i4 = 1.
    i4 = 0.
    else.
    i4 = 1.
    endif.
      call method grid1->set_ready_for_input
         exporting
           i_ready_for_input = i4.
    endform.
    form init_grid.
    Enabling the grid to edit mode,
         struct_grid_lset-edit = 'X'. "To enable editing in ALV
         struct_grid_lset-grid_title  = 'Jimbos Test'.
         call method grid1->set_table_for_first_display
           exporting
             is_layout           = struct_grid_lset
           changing
             it_outtab             =  <dyn_table>
             it_fieldcatalog       =  it_fldcat.
    endform.
    form register_enter_event.
    call method grid1->register_edit_event
                   exporting
                      i_event_id = cl_gui_alv_grid=>mc_evt_enter.
    Instantiate the event or it won't work.
    create object g_event_receiver.
    set handler g_event_receiver->handle_data_changed for grid1.
    endform.</b>

    Hi there
    IE7 doesn't give me the add new page option and I get 404 error when trying to access the "How to contribute" section.
    I'll load up Firefox later (this browser usually works when IE7 doesn't always work properly).
    I'll copy the stuff to the wiki when I've got the browser sorted out.
    Cheers
    jimbp

  • Coloring an ALV Cell with DYNAMIC INTERNAL TABLES

    Hello Gurus,
    I need your help regarding coloring of a cell in my ALV Grid report with DYNAMIC tables.
    I have used the call method in calling my ALV. (CALL METHOD gr_alvgrid->set_table_for_first_display).
    Now my problem is, I can not bring out the cellcolor succesfully, I always ended up to dump (GETWA_NOT_ASSIGNED = You attempted to access an unassigned field symbol     
    (data segment 32807).                                  
    What I have done:
    I've created 2 internal tables:
    *1st table
    *After appended all of my columns to  gt_fieldcat
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = gt_fieldcat
        IMPORTING
          ep_table        = gp_both.
      ASSIGN gp_both->* TO <i_xtab1>.
    *2nd table
    Appended these column for CellColor
      CLEAR wa_gtfldcat.
      wa_gtfldcat-fieldname = 'CELLCOLOR'.
      wa_gtfldcat-ref_table = 'CALENDAR_TYPE'.
      wa_gtfldcat-ref_field = 'COLTAB'.
      APPEND wa_gtfldcat TO gt_fieldcat.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = gt_fieldcat
        IMPORTING
          ep_table        = gp_alvgrid.
      ASSIGN gp_alvgrid->* TO <i_xtab2>.
    *Work Areas for tab1 and tab2
    CREATE DATA dref1 LIKE LINE OF <i_xtab1>.
      ASSIGN dref1->* TO <wa_xtab1>.
      CREATE DATA dref2 LIKE LINE OF <i_xtab2>.
      ASSIGN dref2->* TO <wa_xtab2>.
    *Move contents of table1 to table2 and modify cellcolor column
    LOOP AT <i_xtab1> ASSIGNING <wa_xtab1>.
    *-----Cell color assignment
        DESCRIBE TABLE gt_fieldcat.
        DO sy-tfill TIMES.
          READ TABLE gt_fieldcat INTO wa_gtfldcat INDEX sy-index.
          ASSIGN COMPONENT wa_gtfldcat-fieldname
            OF STRUCTURE <wa_xtab1> TO <fs4>.
          IF sy-subrc NE 0. EXIT .ENDIF.
          ASSIGN COMPONENT wa_gtfldcat-fieldname
            OF STRUCTURE <wa_xtab2> TO <fs3>.
          IF sy-subrc NE 0. EXIT .ENDIF.
            <fs3> = <fs4>.
        ENDDO.
        ASSIGN COMPONENT 'CELLCOLOR' OF STRUCTURE <wa_xtab2> TO <fs3>.
        IF sy-subrc = 0.
          PERFORM modify_cell_color USING 'ZZMATNR' <fs3>.
        ENDIF.
        APPEND <wa_xtab1> TO <i_xtab2>.
    ENDLOOP.
    *Call ALV
    gs_layout-ctab_fname = 'COLORCELL'
        CALL METHOD gr_alvgrid->set_table_for_first_display
          EXPORTING
            is_layout                     = gs_layout
          CHANGING
            it_outtab                     = <i_xtab2d>[]
            it_fieldcatalog               = gt_fieldcat
            it_sort                       = lt_sort
          EXCEPTIONS
            invalid_parameter_combination = 1
            program_error                 = 2
            too_many_lines                = 3
            OTHERS                        = 4.
        IF sy-subrc <> 0.
    *--->Exception handling
        ENDIF.
    FORM modify_cell_color  USING p_fieldname   TYPE lvc_fname
                                  pt_cellcolor  TYPE table.
      DATA l_cellcolor TYPE lvc_s_scol.
      CLEAR l_cellcolor.
      l_cellcolor-fname = p_fieldname.
      l_cellcolor-color-col = 6.       " Red.
      l_cellcolor-color-int = 0.
      l_cellcolor-color-inv = 0.
      INSERT l_cellcolor INTO TABLE pt_cellcolor.
    ENDFORM.                    " MODIFY_CELL_COLOR

    Hi,
    The internal tabl which you are using to display the output should have one column in the end.
    The cell in this column will contain an internal table of type 'lvc_s_scol'.
    The contents of this internal table will be the field names of all other columns of your main internal table in the field FNAME and the required color in the field COLOR.
    Please note that the field COLOR will have a hex value for different colors.
    In the stucture is_layout  whihc you pass to the method 'set_table_for_first_display'
    the name of this last column should be given to the field 'ctab_fname'.
    This will help you to give the colors to each cell.
    for example
    I have my data table as follows:-
    ITAB1
    MATNR  MAKTX        COLOR_TAB
    1           ABC            FNAME  COLOR  NOKEYCOL
                                    MATNR 8000
                                    MAKTX 8000
    2          XYZ             MATNR 10000
                                  MAKTX  10000
    So my internal table ITAB1 had 3 columns MATNR MAKTX and COLOR_TAB.
    And COLOR_TAB will contain an internal table with 3 columns FNAME COLOR and NOKEYCOL.
    The value to importing parameter IS_LAYOUT-CTAB_FNAME will be COLOR_TAB.
    This will help you to assign various colors to the cell of the internal table ITAB.
    When you have to change any color, then you will have to just change the entries in cell COLOR_TAB for the particular row and cell.
    Regards,
    Ankur Parab

  • Display ALV GRID Using Dynamic Internal Table

    Hi all,
    I try to display ALV Grid using Dynamic Internal Table, but when i activate my program, i get an error message "DYN_TABLE" is not type-compatible with formal parameter "IT_OUTTAB". ( DYN_TABLE is my Dynamic Itab).
    Anybody can help me how to passing Dynamic Itab into ALV Grid ?? Of ALV Grid only accept static Itab ??
    Thanks,

    Hi Vijay,
    It's doesn't work, and make new error "Formal parameter "IT_OUTTAB[]" does not exist. However, the parameter "IT_OUTTAB" has a similar name."
    Because the method is:
    CALL METHOD <ref. var. to CL_GUI_ALV_GRID>->set_table_for_first_display
    EXPORTING
    I_BUFFER_ACTIVE = <any type (ANY)>
    I_STRUCTURE_NAME = <string of type DD02L-TABNAME>
    IS_VARIANT = <structure of type DISVARIANT>
    I_SAVE = <var. of type CHAR01>
    I_DEFAULT = <var. of type CHAR01>
    IS_LAYOUT = <structure of type LVC_S_LAYO>
    IS_PRINT = <structure of type LVC_S_PRNT>
    IT_SPECIAL_GROUPS = <internal table of type LVC_T_SGRP>
    IT_TOOLBAR_EXCLUDING = <internal table of type UI_FUNCTIONS>
    IT_HYPERLINK = <internal table of type LVC_T_HYPE>
    IT_ALV_GRAPHICS = <internal table of type DTC_T_TC>
    CHANGING
    IT_OUTTAB = <internal table>
    IT_FIELDCATALOG = <internal table of type LVC_T_FCAT>
    IT_SORT = <internal table of type LVC_T_SORT>
    IT_FILTER = <internal table of type LVC_T_FILT>
    Thanks,

  • Binding ALV GRID with Deep Internal Table

    Hello all,
    I am looking for a way to display ALV Grid with the Deep ITAB.
    My ITAB is not too complex.
    It has One Structure which gets whole DB table + One extra field.
    Therefore my Itab looks as follows.
    TYPES: BEGIN OF TY_TRIP,
            ZPM_UPLOAD LIKE ZDBTABLE, "ZDBTABLE is custom database table.
            TDTIME TYPE STRING,
           END OF TY_TRIP.
    DATA: ITAB TYPE TABLE OF TY_TRIP,
          WA_ITAB LIKE LINE OF ITAB.
    Now i am able to populate data into Deep ITAB.
    If i call ALV Grid with ITAB then i get error. So how to call 'REUSE_ALV_GRID_DISPLAY' with this ITAB?
    Thanks in advance.

    Hello,
    My senior asked me to use the below definition.
    TYPES: BEGIN OF TY_TRIP.
            INCLUDE STRUCTURE ZDBTABLE.
    TYPES:  TDTIME TYPE STRING,
           END OF TY_TRIP.
    DATA: ITAB TYPE TABLE OF TY_TRIP,
          WA_ITAB LIKE LINE OF ITAB.
    If anyone else is looking to print in ALV, they can use this type of ITAB definition though it gives you the flexiblity to create ITAB and also making it FLAT and not DEEP.
    But i am still looking for an answer for my first post.
    Thanks.

  • OO ALV grid with a header line is this possible?

    Howdy!
    I have a requirement where I need to produce an ALV grid with the following format:
    <b>Text 1     Text 2  Text 3                  Text 4
                              Text 6
    Col_1 Col_2 Col_3 Col_4 Col_5 Col_6 Col_7 Col_8 Col_9 
    Cell conents -
    Cell conents -
    Cell conents -
    Cell conents -
    Cell conents -
    </b>
    Anyone got any idea on how to get the 'TEXT' fields into the ALV grid? These are dynamic texts that would basically display details of data entered in the selection screen.
    The ALV title line is limited to 70 characters and I can't think of another way of doing this.
    The texts need to appear on the ALV grid becasue the user would like to download them to Excel in addition to the ALV cell contents using the standard ALV functionality.
    Any ideas would be appreciated!
    Message was edited by: Robert

    I'm thinking that this may not work because it is not a full screen grid and the grid container does not care about the container on top of it so, it most likely would not print it.   Implement this example program, you can see how this would work for you if you were using the FM.
    report zrich_0001
           no standard page heading.
    * Global ALV Data Declarations
    type-pools slis.
    data: begin of i_alv occurs 0,
          matnr type mara-matnr,
          end of i_alv.
    * Miscellanous Data Declarations
    data: fieldcat type slis_t_fieldcat_alv,
          events   type slis_t_event,
          list_top_of_page type slis_t_listheader,
          top_of_page  type slis_formname value 'TOP_OF_PAGE'.
    start-of-selection.
      perform initialization.
      perform get_data.
      perform call_alv.
    end-of-selection.
    *  Form  Initialization
    form initialization.
      clear i_alv.       refresh i_alv.
      perform eventtab_build using events[].
    endform.
    *  Form  Get_Data
    form  get_data.
      select matnr into table i_alv
                  from mara up to 100 rows.
    endform.
    *  CALL_ALV
    form call_alv.
      data: variant type  disvariant.
      data: repid type sy-repid.
      repid = sy-repid.
      variant-report = sy-repid.
      variant-username = sy-uname.
      perform build_field_catalog.
      perform comment_build using list_top_of_page[].
    * Call ABAP List Viewer (ALV)
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                it_fieldcat        = fieldcat
                i_callback_program = repid
                is_variant         = variant
                it_events          = events[]
                i_save             = 'U'
           tables
                t_outtab           = i_alv.
    endform.
    * EVENTTAB_BUILD
    form eventtab_build using events type slis_t_event.
    * Registration of events to happen during list display
      data: tmp_event type slis_alv_event.
      call function 'REUSE_ALV_EVENTS_GET'
           exporting
                i_list_type = 0
           importing
                et_events   = events.
      read table events with key name = slis_ev_top_of_page
                               into tmp_event.
      if sy-subrc = 0.
        move top_of_page to tmp_event-form.
        append tmp_event to events.
      endif.
    endform.
    * BUILD_FIELD_CATALOG
    form build_field_catalog.
      clear: fieldcat. refresh: fieldcat.
      data: tmp_fc type slis_fieldcat_alv.
      tmp_fc-reptext_ddic = 'Material'.
      tmp_fc-fieldname    = 'MATNR'.
      tmp_fc-tabname      = 'I_ALV'.
      tmp_fc-outputlen    = 18.
      append tmp_fc to fieldcat.
    endform.
    * COMMENT_BUILD
    form comment_build using list_top_of_page type
                                            slis_t_listheader.
      data: tmp_line type slis_listheader.
      clear tmp_line.
      tmp_line-typ  = 'H'.
      tmp_line-info = 'Here is a line of text'.
      append tmp_line to list_top_of_page.
      clear tmp_line.
      tmp_line-typ  = 'S'.
      tmp_line-key  = 'Key1'.
      tmp_line-info = 'Here is a value'.
      append tmp_line to list_top_of_page.
      clear tmp_line.
      tmp_line-typ  = 'S'.
      tmp_line-key  = 'Key2'.
      tmp_line-info = 'Here is another value'.
      append tmp_line to list_top_of_page.
    endform.
    * TOP_OF_PAGE
    form top_of_page.
      call function 'REUSE_ALV_COMMENTARY_WRITE'
           exporting
                i_logo             = 'ENJOYSAP_LOGO'
                it_list_commentary = list_top_of_page.
    endform.
    Regards,
    Rich Heilman

  • ALV report with dynamic columns, and repeated structure rows

    Hey Guys,
    I've done some ALV programming, but most of the reports were straight forward. This one is a little interesting. So here go the questions...
    Q1: Regarding Columns:
    What is the best way to code a report with columns being dynamic. This is one of the parameters the user is going to enter in his input.
    Q2: Regarding Rows:
    I want to repeat a structure(say it contains f1, f2, f3) multiple time in rows. What is the best way to do it? The labels for these fields have to appear in the first column.
    Below is the visual representation of the questions.
    Jan 06  , Feb 06, Mar 06....(dynamic)
       material 1
    Current Stock
    current required
    $Value of stock
       material 2
    Current Stock
    current required
    $Value of stock
       material 3
    Current Stock
    current required
    $Value of stock
    Thanks for your help.
    Sumit.

    Hi Sumit,
    Just check this sample from one of the SAP site
    ABAP Code Sample for Dynamic Table for ALV with Cell Coloring
    Applies To:
    ABAP / ALV Grid
    Article Summary
    ABAP Code Sample that uses dynamic programming techniques to build a dynamic internal table for display in an ALV Grid with Cell Coloring.
    Code Sample
    REPORT zcdf_dynamic_table.
    * Dynamic ALV Grid with Cell Coloring.
    * Build a field catalog dynamically and provide the ability to color
    * the cells.
    * To test, copy this code to any program name and create screen 100
    * as described in the comments. After the screen is displayed, hit
    * enter to exit the screen.
    * Tested in 4.6C and 6.20
    * Charles Folwell - [email protected] - Feb 2, 2005
    DATA:
    r_dyn_table TYPE REF TO data,
    r_wa_dyn_table TYPE REF TO data,
    r_dock_ctnr TYPE REF TO cl_gui_docking_container,
    r_alv_grid TYPE REF TO cl_gui_alv_grid,
    t_fieldcat1 TYPE lvc_t_fcat, "with cell color
    t_fieldcat2 TYPE lvc_t_fcat, "without cell color
    wa_fieldcat LIKE LINE OF t_fieldcat1,
    wa_cellcolors TYPE LINE OF lvc_t_scol,
    wa_is_layout TYPE lvc_s_layo.
    FIELD-SYMBOLS:
    <t_dyn_table> TYPE STANDARD TABLE,
    <wa_dyn_table> TYPE ANY,
    <t_cellcolors> TYPE lvc_t_scol,
    <w_field> TYPE ANY.
    START-OF-SELECTION.
    * Build field catalog based on your criteria.
    wa_fieldcat-fieldname = 'FIELD1'.
    wa_fieldcat-inttype = 'C'.
    wa_fieldcat-outputlen = '10'.
    wa_fieldcat-coltext = 'My Field 1'.
    wa_fieldcat-seltext = wa_fieldcat-coltext.
    APPEND wa_fieldcat TO t_fieldcat1.
    wa_fieldcat-fieldname = 'FIELD2'.
    wa_fieldcat-inttype = 'C'.
    wa_fieldcat-outputlen = '10'.
    wa_fieldcat-coltext = 'My Field 2'.
    wa_fieldcat-seltext = wa_fieldcat-coltext.
    APPEND wa_fieldcat TO t_fieldcat1.
    * Before adding cell color table, save fieldcatalog to pass
    * to ALV call. The ALV call needs a fieldcatalog without
    * the internal table for cell coloring.
    t_fieldcat2[] = t_fieldcat1[].
    * Add cell color table.
    * CALENDAR_TYPE is a structure in the dictionary with a
    * field called COLTAB of type LVC_T_SCOL. You can use
    * any structure and field that has the type LVC_T_SCOL.
    wa_fieldcat-fieldname = 'T_CELLCOLORS'.
    wa_fieldcat-ref_field = 'COLTAB'.
    wa_fieldcat-ref_table = 'CALENDAR_TYPE'.
    APPEND wa_fieldcat TO t_fieldcat1.
    * Create dynamic table including the internal table
    * for cell coloring.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = t_fieldcat1
    IMPORTING
    ep_table = r_dyn_table
    EXCEPTIONS
    generate_subpool_dir_full = 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.
    * Get access to new table using field symbol.
    ASSIGN r_dyn_table->* TO <t_dyn_table>.
    * Create work area for new table.
    CREATE DATA r_wa_dyn_table LIKE LINE OF <t_dyn_table>.
    * Get access to new work area using field symbol.
    ASSIGN r_wa_dyn_table->* TO <wa_dyn_table>.
    * Get data into table from somewhere. Field names are
    * known at this point because field catalog is already
    * built. Read field names from the field catalog or use
    * COMPONENT <number> in a DO loop to access the fields. A
    * simpler hard coded approach is used here.
    ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'ABC'.
    ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'XYZ'.
    APPEND <wa_dyn_table> TO <t_dyn_table>.
    ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'TUV'.
    ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'DEF'.
    APPEND <wa_dyn_table> TO <t_dyn_table>.
    * Color cells based on your criteria. In this example, a test on
    * FIELD2 is used to decide on color.
    LOOP AT <t_dyn_table> INTO <wa_dyn_table>.
    ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    * Get access to internal table used to color cells.
    ASSIGN COMPONENT 'T_CELLCOLORS'
    OF STRUCTURE <wa_dyn_table> TO <t_cellcolors>.
    CLEAR wa_cellcolors.
    wa_cellcolors-fname = 'FIELD2'.
    IF <w_field> = 'DEF'.
    wa_cellcolors-color-col = '7'.
    ELSE.
    wa_cellcolors-color-col = '5'.
    ENDIF.
    APPEND wa_cellcolors TO <t_cellcolors>.
    MODIFY <t_dyn_table> FROM <wa_dyn_table>.
    ENDLOOP.
    * Display screen. Define screen 100 as empty, with next screen
    * set to 0 and flow logic of:
    * PROCESS BEFORE OUTPUT.
    * MODULE initialization.
    * PROCESS AFTER INPUT.
    CALL SCREEN 100.
    * MODULE initialization OUTPUT
    MODULE initialization OUTPUT.
    * Set up for ALV display.
    IF r_dock_ctnr IS INITIAL.
    CREATE OBJECT r_dock_ctnr
    EXPORTING
    side = cl_gui_docking_container=>dock_at_left
    ratio = '90'.
    CREATE OBJECT r_alv_grid
    EXPORTING i_parent = r_dock_ctnr.
    * Set ALV controls for cell coloring table.
    wa_is_layout-ctab_fname = 'T_CELLCOLORS'.
    * Display.
    CALL METHOD r_alv_grid->set_table_for_first_display
    EXPORTING
    is_layout = wa_is_layout
    CHANGING
    it_outtab = <t_dyn_table>
    it_fieldcatalog = t_fieldcat2.
    ELSE. "grid already prepared
    * Refresh display.
    CALL METHOD r_alv_grid->refresh_table_display
    EXPORTING
    i_soft_refresh = ' '
    EXCEPTIONS
    finished = 1
    OTHERS = 2.
    ENDIF.
    ENDMODULE. " initialization OUTPUT
    Regards
    vijay

  • Group feature at ALV grid with editable columns

    Am I right ?
    Group function by using a sorted layout is disabled while having one (or more) editable columns, isn't it ?
    ... or is there a possibility to use gouped rows ?
    Greetings
    Markus

    Also...
    *& Report ZDEMO_ALVGRID_EDIT *
    *& Example of a simple ALV Grid Report *
    *& The basic ALV grid, Enhanced to display specific fields as *
    *& editable depending on field value *
    REPORT ZDEMO_ALVGRID_EDIT .
    TABLES: ekko.
    TYPE-POOLS: slis. "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_ekko,
    ebeln TYPE ekpo-ebeln,
    ebelp TYPE ekpo-ebelp,
    statu TYPE ekpo-statu,
    aedat TYPE ekpo-aedat,
    matnr TYPE ekpo-matnr,
    menge TYPE ekpo-menge,
    meins TYPE ekpo-meins,
    netpr TYPE ekpo-netpr,
    peinh TYPE ekpo-peinh,
    field_style TYPE lvc_t_styl, "FOR DISABLE
    END OF t_ekko.
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
    wa_ekko TYPE t_ekko.
    *ALV data declarations
    DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE.
    DATA: it_fieldcat TYPE lvc_t_fcat, "slis_t_fieldcat_alv WITH HEADER LINE,
    wa_fieldcat TYPE lvc_s_fcat,
    gd_tab_group TYPE slis_t_sp_group_alv,
    gd_layout TYPE lvc_s_layo, "slis_layout_alv,
    gd_repid LIKE sy-repid.
    *Start-of-selection.
    START-OF-SELECTION.
    PERFORM data_retrieval.
    PERFORM set_specific_field_attributes.
    PERFORM build_fieldcatalog.
    PERFORM build_layout.
    PERFORM display_alv_report.
    *& Form BUILD_FIELDCATALOG
    Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
    wa_fieldcat-fieldname = 'EBELN'.
    wa_fieldcat-scrtext_m = 'Purchase Order'.
    wa_fieldcat-col_pos = 0.
    wa_fieldcat-outputlen = 10.
    wa_fieldcat-emphasize = 'X'.
    wa_fieldcat-key = 'X'.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.
    wa_fieldcat-fieldname = 'EBELP'.
    wa_fieldcat-scrtext_m = 'PO Item'.
    wa_fieldcat-col_pos = 1.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.
    wa_fieldcat-fieldname = 'STATU'.
    wa_fieldcat-scrtext_m = 'Status'.
    wa_fieldcat-col_pos = 2.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.
    wa_fieldcat-fieldname = 'AEDAT'.
    wa_fieldcat-scrtext_m = 'Item change date'.
    wa_fieldcat-col_pos = 3.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.
    wa_fieldcat-fieldname = 'MATNR'.
    wa_fieldcat-scrtext_m = 'Material Number'.
    wa_fieldcat-col_pos = 4.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.
    wa_fieldcat-fieldname = 'MENGE'.
    wa_fieldcat-scrtext_m = 'PO quantity'.
    wa_fieldcat-col_pos = 5.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.
    wa_fieldcat-fieldname = 'MEINS'.
    wa_fieldcat-scrtext_m = 'Order Unit'.
    wa_fieldcat-col_pos = 6.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.
    wa_fieldcat-fieldname = 'NETPR'.
    wa_fieldcat-scrtext_m = 'Net Price'.
    wa_fieldcat-edit = 'X'. "sets whole column to be editable
    wa_fieldcat-col_pos = 7.
    wa_fieldcat-outputlen = 15.
    wa_fieldcat-datatype = 'CURR'.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.
    wa_fieldcat-fieldname = 'PEINH'.
    wa_fieldcat-scrtext_m = 'Price Unit'.
    wa_fieldcat-col_pos = 8.
    APPEND wa_fieldcat TO it_fieldcat.
    CLEAR wa_fieldcat.
    ENDFORM. " BUILD_FIELDCATALOG
    *& Form BUILD_LAYOUT
    Build layout for ALV grid report
    FORM build_layout.
    Set layout field for field attributes(i.e. input/output)
    gd_layout-stylefname = 'FIELD_STYLE'.
    gd_layout-zebra = 'X'.
    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'
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
    i_callback_program = gd_repid
    i_callback_user_command = 'USER_COMMAND'
    is_layout_lvc = gd_layout
    it_fieldcat_lvc = it_fieldcat
    i_save = 'X'
    TABLES
    t_outtab = it_ekko
    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.
    SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
    UP TO 10 ROWS
    FROM ekpo
    INTO CORRESPONDING FIELDS OF TABLE it_ekko.
    ENDFORM. " DATA_RETRIEVAL
    *& Form set_specific_field_attributes
    populate FIELD_STYLE table with specific field attributes
    form set_specific_field_attributes .
    DATA ls_stylerow TYPE lvc_s_styl .
    DATA lt_styletab TYPE lvc_t_styl .
    Populate style variable (FIELD_STYLE) with style properties
    The NETPR field/column has been set to editable in the fieldcatalog...
    The following code sets it to be disabled(display only) if 'NETPR'
    is gt than 10.
    LOOP AT it_ekko INTO wa_ekko.
    IF wa_ekko-netpr GT 10.
    ls_stylerow-fieldname = 'NETPR' .
    ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
    "set field to disabled
    APPEND ls_stylerow TO wa_ekko-field_style.
    MODIFY it_ekko FROM wa_ekko.
    ENDIF.
    ENDLOOP.
    endform. " set_specific_field_attributes
    REWARD POINTS IF usefful !!

  • Display amount in ALV Grid with different Decimal Places based on Currency

    HI Experts,
    Working with ALV Report i have one Amount field NETWR which is having Length 15 and Decimal Places 2.
    we have two different types of currency's AED and KWD and AED having 2 decimal Places and KWD having 3 decimal places.
    im using FM: REUSE_ALV_GRID_DISPLAY for Display. value storing in Table was like this
    AED---22.56
    KWD---225.65
    i need to display values like AED : 22.56

    HI Experts,
    Working with ALV Report i have one Amount field NETWR which is having Length 15 and Decimal Places 2. we have two different types of currency's AED and KWD and AED having 2 decimal Places and KWD having 3 decimal places.
    im using FM: REUSE_ALV_GRID_DISPLAY for Display. value storing in Table was like this
    AED---22.56
    KWD---225.65 (converting this value to 22.565 using BAPI_CURRENCY_GETDECIMALS according to currency in my Report)
    i need to display values like AED : 22.56
                                             KWD---22.565 but here field is NETWR with 2 decimal.
    Need to Display amount in ALV Grid with different Decimal Places based on Currency
    Regards,
    Dileep Kumar Reddy

  • ALV Grid with Popup Window

    Hey @all,
    I want to make a ALV Grid with a Popup Window. The idea is that there is a field for notes and when you click on this field a popup window should be opened where you can insert more text or if text already exists only the first column of the text is shown in field until you click on the field.
    Is there any possibility to do it this way? Do I have to make a second Grid for this Popup Window? Do anybody have an example how to solve this problem?
    Thank you in advance for your answers!
    Greetings,
    Alexander

    *& Report  Z_VISHVAS_ALV1
    report  z_vishvas_alv1.
    type-pools: slis.
    data: begin of i_outtab occurs 0.
            include structure sflight.
    data:   w_chk type c.                  "For multiple selection
    data: end of i_outtab.
          I_OUTTAB TYPE SFLIGHT OCCURS 0,
    data: i_private type slis_data_caller_exit,
          i_selfield type slis_selfield,
          w_exit(1) type c.
    parameters: p_title type sy-title.
    start-of-selection.
      select * from sflight into table i_outtab.
      call function 'REUSE_ALV_POPUP_TO_SELECT'
           exporting
                i_title                 = p_title
                i_selection             = 'X'
                i_zebra                 = 'X'
              I_SCREEN_START_COLUMN   = 0
              I_SCREEN_START_LINE     = 0
              I_SCREEN_END_COLUMN     = 0
              I_SCREEN_END_LINE       = 0
                i_checkbox_fieldname    = 'W_CHK'
              I_LINEMARK_FIELDNAME    =
              I_SCROLL_TO_SEL_LINE    = 'X'
                i_tabname               = 'I_OUTTAB'
                i_structure_name        = 'SFLIGHT'
              IT_FIELDCAT             =
              IT_EXCLUDING            =
              I_CALLBACK_PROGRAM      =
              I_CALLBACK_USER_COMMAND =
               IS_PRIVATE             = I_PRIVATE
         importing
                es_selfield             = i_selfield
                e_exit                  = w_exit
           tables
                t_outtab                = i_outtab
           exceptions
                program_error           = 1
                others                  = 2.
      if sy-subrc <> 0.
       MESSAGE i000(0k) WITH sy-subrc.
      endif.
    *****the internal table is modified with a cross sign for marking the
    ***rows selected
      loop at i_outtab where w_chk = 'X'.
        write: /  i_outtab-carrid, i_outtab-price.
      endloop.

  • ALV grid with editable fields

    Dear Colleagues,
    I develop an ALV grid with OO standard methods. Before the first display of the table I define the editable fields. It works fine.
    I have a problem : if the table is empty and I press the standard icons "Append a line" or "Insert a line", the new line don't have the defined editable characteristics.for fields. Is there a standard method which I have forgotten ?
    Thanks a lot and kind regards
    Peter

    vs_toolbar_excluding = cl_gui_alv_grid=>mc_fc_loc_delete_row.
        APPEND vs_toolbar_excluding TO i_toolbar_excluding.
        vs_toolbar_excluding = cl_gui_alv_grid=>mc_fc_loc_append_row.
        APPEND vs_toolbar_excluding TO i_toolbar_excluding.
        vs_toolbar_excluding = cl_gui_alv_grid=>mc_fc_loc_copy_row.
        APPEND vs_toolbar_excluding TO i_toolbar_excluding.
        vs_toolbar_excluding = cl_gui_alv_grid=>mc_fc_loc_insert_row.
        APPEND vs_toolbar_excluding TO i_toolbar_excluding.
        vs_toolbar_excluding = cl_gui_alv_grid=>mc_fc_loc_copy.
        APPEND vs_toolbar_excluding TO i_toolbar_excluding.
        vs_toolbar_excluding = cl_gui_alv_grid=>mc_fc_loc_cut.
        APPEND vs_toolbar_excluding TO i_toolbar_excluding.
        vs_toolbar_excluding = cl_gui_alv_grid=>mc_fc_loc_paste.
        APPEND vs_toolbar_excluding TO i_toolbar_excluding.
        vs_toolbar_excluding = cl_gui_alv_grid=>mc_fc_loc_undo.
        APPEND vs_toolbar_excluding TO i_toolbar_excluding.
        vs_toolbar_excluding = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
        APPEND vs_toolbar_excluding TO i_toolbar_excluding.
    * Displaying the output in ALV Grid
        vs_layout_grid-no_rowmark = 'X'.
        vs_layout_grid-zebra      = 'X'.
        vs_layout_grid-cwidth_opt = 'X'.
        vs_layout_grid-edit       = 'X'.
        vs_layout_grid-ctab_fname = 'CT'.
        vs_layout_grid-stylefname = 'CELLTAB'.
        CALL METHOD v_grid->set_table_for_first_display
          EXPORTING
            i_save                        = 'X'
            is_layout                     = vs_layout_grid
            it_toolbar_excluding          = i_toolbar_excluding[]
          CHANGING
            it_outtab                     = itab[]
            it_fieldcatalog               = it_fieldcat[]
          EXCEPTIONS
            invalid_parameter_combination = 1
            program_error                 = 2
            too_many_lines                = 3
            OTHERS                        = 4.
        IF sy-subrc NE 0.
          MESSAGE 'ALV Grid display unsuccessful' TYPE 'I'.
          STOP.
        ENDIF.                             " IF sy-subrc NE 0
      ELSE.                                " IF w_custom_container...
    * Refresh the container if it already exists
        CALL METHOD v_grid->refresh_table_display
          EXCEPTIONS
            finished = 1
            OTHERS   = 2.
        IF sy-subrc NE 0.
          MESSAGE 'Refreshing the container is not successful' TYPE 'I'.
          STOP.
        ENDIF.                            

  • ALV grid with 2 labels on the output

    Hi,
    I am trying ALV  Grid with two labels using Function modules.
    in the output, it should appear like...
    Header1 | Header2 | Header3 | Header4 |
    T21
    T22
    T31
    T32
    First line is for Header lable and second line is for item lable under corresponding Header labels.
    Pls. can any suggest me a solution for this..
    Thanks
    PRa

    Using the Gird Functions it is not possible, you can get the with the help of ALV list function.
    If you use this aproach you will loose some Functionalities, Your Report Output will Distorted.
    cehck this image..
    http://img100.imageshack.us/img100/3846/output6ef.th.gif
    REPORT ZTEST_ALV message-id zz .
    TYPE-POOLS: SLIS.
    DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
    IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
    L_LAYOUT type slis_layout_alv,
    x_events type slis_alv_event,
    it_events type SLIS_T_EVENT.
    DATA: BEGIN OF ITAB OCCURS 0,
    VBELN LIKE VBAK-VBELN,
    POSNR LIKE VBAP-POSNR,
    MALE type i,
    female type i,
    END OF ITAB.
    SELECT VBELN
    POSNR
    FROM VBAP
    UP TO 20 ROWS
    INTO TABLE ITAB.
    X_FIELDCAT-FIELDNAME = 'VBELN'.
    X_FIELDCAT-SELTEXT_L = 'VBELN'.
    X_FIELDCAT-TABNAME = 'ITAB'.
    X_FIELDCAT-COL_POS = 1.
    APPEND X_FIELDCAT TO IT_FIELDCAT.
    CLEAR X_FIELDCAT.
    X_FIELDCAT-FIELDNAME = 'POSNR'.
    X_FIELDCAT-SELTEXT_L = 'POSNR'.
    X_FIELDCAT-TABNAME = 'ITAB'.
    X_FIELDCAT-COL_POS = 2.
    APPEND X_FIELDCAT TO IT_FIELDCAT.
    CLEAR X_FIELDCAT.
    X_FIELDCAT-FIELDNAME = 'MALE'.
    X_FIELDCAT-SELTEXT_L = 'MALE'.
    X_FIELDCAT-TABNAME = 'ITAB'.
    X_FIELDCAT-COL_POS = 3.
    APPEND X_FIELDCAT TO IT_FIELDCAT.
    CLEAR X_FIELDCAT.
    X_FIELDCAT-FIELDNAME = 'FEMALE'.
    X_FIELDCAT-SELTEXT_L = 'FEMALE'.
    X_FIELDCAT-TABNAME = 'ITAB'.
    X_FIELDCAT-COL_POS = 3.
    APPEND X_FIELDCAT TO IT_FIELDCAT.
    CLEAR X_FIELDCAT.
    x_events-NAME = SLIS_EV_TOP_OF_PAGE.
    x_events-FORM = 'TOP_OF_PAGE'.
    APPEND x_events TO iT_EVENTS.
    CLEAR x_events .
    L_LAYOUT-NO_COLHEAD = 'X'.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = SY-REPID
    IS_LAYOUT = L_LAYOUT
    IT_FIELDCAT = IT_FIELDCAT
    it_events = it_events
    TABLES
    T_OUTTAB = ITAB
    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.
    FORM TOP_OF_PAGE.
    *-To display the headers for main list
    FORMAT COLOR COL_HEADING.
    WRITE: / SY-ULINE(103).
    WRITE: / SY-VLINE,
    (8) ' ' ,
    SY-VLINE,
    (8) ' ' ,
    SY-VLINE,
    (19) '***'(015) centered,
    sy-vline.
    WRITE: / SY-VLINE,
    (8) 'VBELN'(013) ,
    SY-VLINE,
    (8) 'POSNR'(014) ,
    SY-VLINE,
    (8) 'MALE'(016) ,
    sy-vline,
    (8) 'FMALE'(017) ,
    sy-vline.
    FORMAT COLOR OFF.
    ENDFORM.

  • Save Layout in ALV Grid

    Hi,
    I have to save layout in ALV grid which should persist every time when i start the transaction.I am able to get save, change and manage option in the grid and also able to set the default layout but this default layout doesnot work.
    please see the code :
      l_repvar  = sy-repid.
      ls_variant = l_repvar.
      l_varient = 'A'.
      ls_variant-variant = l_varient.
      draft_layout-sel_mode = 'D'.
      draft_layout-stylefname = 'CELLPROP'.
      draft_layout-no_f4 = 'X'.
    DISPLAY THE DATA ON THE GRID
      CALL METHOD draft_grid->set_table_for_first_display
        EXPORTING
          i_structure_name     = 'PSHLP_DRAFT_ST'
          is_layout            = draft_layout
          it_toolbar_excluding = g_it_exclude
          is_variant           = ls_variant
          i_save               = 'A'
          i_default            = 'X'
        CHANGING
          it_fieldcatalog      = draft_fieldcat
          it_outtab            = l_draft[].
    i have tried by chaging i_save to 'X' and 'U' but no difference.
    Useful answers will be rewarded.
    Thanks and Regards,
    Harsh

    hi,
    try with this code,
    DATA: wa_disvariant LIKE disvariant.
        wa_disvariant-report = g_repid.
        wa_disvariant-username = sy-uname.
    and pass these values in your function module,
             i_save                      = 'X'
             is_variant                  = wa_disvariant
    thanks and regards,
    muralidhar.

  • Default collapsed view in ALV grid with subtotoal lines

    Hallo experts,
    I am displaying a ALV grid with subtotals. Now my requirement to display the Grid with only subtotal lines. Means the grid should be displayed in collapsed mode by default.
    Can any you help me finding this option.
    Thanks.
    Matt.

    Hallo experts,
    I am displaying a ALV grid with subtotals. Now my requirement to display the Grid with only subtotal lines. Means the grid should be displayed in collapsed mode by default.
    Can any you help me finding this option.
    Thanks.
    Matt.
    Hi Matt,
    Whe you call the FM REUSE_ALV_GRID_DISPLAY, you have to fill the table it_sort.
    In this table, you have to fill the field FIELDNAME with the field that you can show with susbstotals and fill the field EXPA with 'X'.
    W_SORT-SPOS = 1.
    W_SORT-FIELDNAME = 'CODIGO'.
    W_SORT-SUBTOT = 'X'.
    W_SORT-EXPA = 'X'.
    APPEND W_SORT TO IT_SORT.
    In the fieldcatalog there must be any with the field DO_SUM = 'X'
    You can maka this directly in the list by creating a variant with susbtotals, colapse them and save as a default variant for all users.
    Regards,
    Pepe
    Regards,
    Pepe

  • ALV GRID with own EXCEL-Template

    Hallo,
    I have Problem with using ALV-Grid with a own created
    template.
    At First I copy the SAP_OM.XLS template to CUS_OM.XLS.
    Then I update it by deleting all sheets, but not RAWDATA.
    When I use this template in ALV-GRID, it would be the right one, but it his no Data.
    The security settings in Excel are correct.
    Can anyone help me to show the data like the normal
    ALV-GRID??
    thanks Dieter

    Hi
    Check this link...
    How to send data  to different tabs of an excel sheet?

Maybe you are looking for

  • Max number of logical table sources

    Hi, I have one logical table based (a fact table) on 8 logical table sources. This is done to simulate some partitioning as my customer does not have an partition set up on data base level. Anyway my challenge is that a request fired in answers does

  • My 5 won't turn on

    My phone won't turn on or charge.  I was reading my email about 30 mins. Before

  • How to reference another java file?

    nvm Edited by: kingryanj on Nov 24, 2008 7:06 AM

  • Comparison between E70 and N91

    I've been waiting for the E70 for a while now, and it looks like it's going to be available very soon now and I'll be asking my manager if I can upgrade my 6680 to one. The reason I wanted one was for the VOIP connectivity and WLAN... Are there any f

  • CDONTS: Send Email with Summary of Items

    Thanks for looking at this. I want to do is send an email message to the site administrator whenever a customer registers product serial numbers. The email would have the customers name, address, etc at the top and then a table of product serial numb