Dynamic ALV GRID screen in a class? Possible?

I have created a class(I have done it locally as to be able to use it for mutiple clients) that I include in programs that I want to implement the alv grid for using the FM approach. Doing this allows me to easily implement the ALV quickly. However, I am wanting to use the OO ALV grid approach since there is more flexibility and control doing it this way. But I do not want to have to create a screen for every program that I want to do this for, I would like to just have a method in my existing class that would call a screen and then be able to control it like normal. I know that screens can not be called from a method so I was thinking of doing something similiar to another post using a FM to call the screen. I realize that this could be complicated because certain methods for the ALV GRID are called in the  PBO/PAI events. Any help or suggestions would be appreciated.
Note: I am on 6.20 and have searched all over the web before posting.
Thanks.

Yes,  i have written a function module which calls a generice ALV grid in a dialog box.  Everything about the ALV grid is encapsulated in a function module.  In this case, all I need to do is send this function module a fieldcatalog and the data,  that's about it.  Doing this may limit the functionality of event handling  or you would just have to handle everything by doing more code for it..   This function module is very simple, not a whole lot to it.   You could do something like this only instead of using a model dialog box, you would throw a regular dynpro.
function z_popup_with_alvgrid.
*"*"Global interface:
*"  IMPORTING
*"     REFERENCE(ENDPOS_COL) TYPE  I DEFAULT 90
*"     REFERENCE(ENDPOS_ROW) TYPE  I DEFAULT 22
*"     REFERENCE(STARTPOS_COL) TYPE  I DEFAULT 10
*"     REFERENCE(STARTPOS_ROW) TYPE  I DEFAULT 2
*"     REFERENCE(TEXTLINE1) TYPE  C OPTIONAL
*"     REFERENCE(TEXTLINE2) TYPE  C OPTIONAL
*"     REFERENCE(TEXTLINE3) TYPE  C OPTIONAL
*"     REFERENCE(TEXTLINE4) TYPE  C OPTIONAL
*"     REFERENCE(TITLE) TYPE  C OPTIONAL
*"     REFERENCE(FIELDCAT) TYPE  LVC_T_FCAT
*"  TABLES
*"      I_ALV
  call screen 0200 starting at startpos_col
                               startpos_row
                     ending at endpos_col
                               endpos_row.
endfunction.
*      Module  STATUS_0200  OUTPUT
module status_0200 output.
  set pf-status '0200'.
  set titlebar  '0200' with title.
  data: alv_container  type ref to cl_gui_custom_container.
  data: alv_grid       type ref to cl_gui_alv_grid.
  data: xfieldcat type lvc_t_fcat.
  xfieldcat = fieldcat.
* Create Controls
  create object:
     alv_container
             exporting
                   container_name    = 'ALV_CONTAINER',
     alv_grid
             exporting
                   i_parent          =  alv_container.
*  Set grid for first display
  call method alv_grid->set_table_for_first_display(
      exporting
           i_structure_name       = 'I_ALV'
      changing
           it_outtab       = i_alv[]
           it_fieldcatalog = xfieldcat[] ).
endmodule.
*     Module  USER_COMMAND_0100  INPUT
module user_command_0200 input.
  case sy-ucomm.
    when 'CONTINUE' or 'CANCEL'.
      set screen 0.
      leave screen.
  endcase.
endmodule.
Regards,
Rich Heilman

Similar Messages

  • Create deep structure to disable some cells in Dynamic ALV GRID

    Hi,
    I want to disable some cells in a Dynamic ALV Grid before calling "SET_tABLE_Display" Method.
    I check the BCALV_EDIT_02, where some cells are grayed out by assign the  CL_GUI_ALV_GRID-MC_STYLE_DISABLED  to the field name.
    But I want the same using Field symbol.
    I'm creating Dynamic table and dynamic structure based on the Dynamic field catalog.
    Example: <FT_TAB> TYPE STANDARD TABLE,
                    <FS_TAB> TYPE ANY,            
    DATA: INT_TAB  is my dynamic table values.
    For the INT_TAB internal table, I created dynamic Structure and dynamic field symbol table.
    LOOP AT INT_TAB.
    ASSIGN COMPONENT 'MATNR'  OF STRUCTURE <FS_TAB> TO <F_VALUE>
    <F_VALUE> = INT_TAB-MATNR.
    APPEND <FS_TAB> TO <FT_TAB>
    "Here is the problem occurs, I want to grayed out the MATNR value based on some condition.
    ENDLOOP.
    I would like to set the 'MATNR' value to be grayed out by passing the CL_GUI_ALV_GRID-MC_STYLE_DISABLED.
    and update into <FT_TAB>(       <FT_TAB> structure will have 2 structures)
    Finally the fieldsymbol should have two structure ( <F_TAB> = DYNAMIC STRUCTURE + LVC_S_STYLE )
    Display alv grid by passing <FT_TAB> to set_table_display method.
    Thanks in advance,
    Kumar.

    Hi,
    I am  not sure whether I really understand your request. Let me try to help.
    > Example: <FT_TAB> TYPE STANDARD TABLE,
    >                 <FS_TAB> TYPE ANY,            
    >
    > DATA: INT_TAB  is my dynamic table values.
    >
    >
    > LOOP AT INT_TAB.
    >  ASSIGN COMPONENT 'MATNR'  OF STRUCTURE <FS_TAB> TO <F_VALUE>
    > <F_VALUE> = INT_TAB-MATNR.
    >  APPEND <FS_TAB> TO <FT_TAB>
    Here <FT_TAB> must already be assigned to some internal table with a given (dynamic) structure. Did this happen before this piece of code?
    What I would do is to create a dynamic table (see documentation to CREATE DATA) with MATNR and the STYLE field (LVC_T_STYL). See the documentation for CREATE DATA - creation of internal tables. When collection the field descriptions for that internal table I would also build the field catalogue for the ALV.
    Then assign <FT_TAB> to that newly created internal table, <FS_TAB> to a newly created structure (same as a table line).
    Move the MATNR to component 1 (or component 'MATNR') of the table and fill the style table according to your needs. Then insert the <FS_TAB> into <FT_TAB>.
    Finally call the ALV SET_TABLE... method with your dynamic table and your field catalogue.
    Regards,
    Gerd Rother

  • Dynamic ALV Grid is not displaying !!

    Hi all,
      I am trying to create dynamic alv grids and upto five levels(five grids) out put is displaying fine without any problem. But when I try to display the 6th grid, the program is going into infinite loop and getting timed out. Even I tried to increse the height of the grid even though it is not displaying.
    Please correct me if any thing is wrong in below code.
    *1st Level grid
    IF <table1> IS ASSIGNED AND <table1> IS NOT INITIAL.
       CREATE OBJECT ob_split1
           EXPORTING
             parent      = ob_custom
             orientation = cl_gui_easy_splitter_container=>orientation_vertical.
        PERFORM set_split_height USING ob_split1  '20'.
        CREATE OBJECT ob_grid1
          EXPORTING
            i_parent = ob_split1->top_left_container.
    ELSE.
        CREATE OBJECT ob_split1
           EXPORTING
             parent      = ob_custom
             orientation = cl_gui_easy_splitter_container=>orientation_vertical.
        PERFORM set_split_height USING ob_split1  '0'.
    ENDIF.
    *2nd Level grid
    IF <table2> IS ASSIGNED AND <table2> IS NOT INITIAL.
       CREATE OBJECT ob_split2
           EXPORTING
             parent      = ob_split1->bottom_right_container
             orientation = cl_gui_easy_splitter_container=>orientation_vertical.
          PERFORM set_split_height USING ob_split2   '20'.
        CREATE OBJECT ob_grid2
          EXPORTING
            i_parent = ob_split2->top_left_container.
      ELSE.
         CREATE OBJECT ob_split2
            EXPORTING
              parent      = ob_split1->bottom_right_container
              orientation = cl_gui_easy_splitter_container=>orientation_vertical.
         PERFORM set_split_height USING ob_split2    '0'.
      ENDIF.
    (Created 3rd,4th,5th same like above).
    *6th Level grid
    IF <table6> IS ASSIGNED AND <table6> IS NOT INITIAL.
    CREATE OBJECT ob_split6
           EXPORTING
             parent      = ob_split5->bottom_right_container
             orientation = cl_gui_easy_splitter_container=>orientation_vertical.
         PERFORM set_split_height USING ob_split6  '20'.
         CREATE OBJECT ob_grid6
           EXPORTING
             i_parent = ob_split6->top_left_container.
      ELSE.
         CREATE OBJECT ob_split6
           EXPORTING
             parent      = ob_split5->bottom_right_container
             orientation = cl_gui_easy_splitter_container=>orientation_vertical.
         PERFORM set_split_height USING ob_split6  '0'.
      ENDIF.
    Appreciated your reply. Please let me know for additional info.
    Thanks,
    Ranjith.
    Edited by: Thomas Zloch on Dec 8, 2010 5:44 PM - please use code tags

    Hi romanch,
    defining the field catalog you must reference all currency fields to the respective currency key field (type CUKY).
    <alv_fieldcat>-cfieldname         = 'HWAER'.
    This is sample for alv output of a currency field. The alv structure has a field HWAER which carries the currency key, e.g. USD or so.
    Obviously you do not provide a cutrrency key for your values. If they are initial (zero), ALV will not display them as 0,00 but leave the field empty if the reference too currency key is not established.
    If you define a DDIC structure for the ALV output this refernce is enforced. You can pass the DDIC structure name to the ALV and don not have to create the field catalog manually.
    Regards,
    Clemens

  • Two dynamic ALV grid

    Hi experts,
      I am having a dynamic ALV grid. How to create a new grid(second grid) in the same page with different values?
    Thanks&Regards,
    vino

    Add 2 view containers, create 2 different usages of AVL component and embed the view of these 2 alv components in 2 view containers..
    Hope this helps
    manas dua

  • Radio button in dynamic ALV grid

    Hi guys!
    I want to implement a dynamical ALV grid with a radiobutton in the first column.
    when clicking a button, or processing the program i want to get the information of the selected row and perform other things....
    Can someone help me with a code example for this, or just tell me where i can find the necessary information`?
    regards
    thomas

    Hi,
    I dont understand why you need Radio button, If you use REUSE_ALV_GRID_DISPLAY the output grid will by default allow you to select only one row.
    see the program - BCALV_FULLSCREEN_DEMO for more information

  • ALV grid screen dynamic resizing.

    Hello Experts,
    I have written a functionality to display a report program using the CL_GUI_ALV_GRID class.
    I need to add a functionality so that the scrollbars and the custom container area resize themselves dynamically if I am changing the window size of the window in which my ALV grid is displayed.
    Any pointers in this direction will be very helpful.
    Thank you.
    Gaurav.

    You could try this thread...if it helps...
    Resizing ALV Grid When Changing Screen Resolution
    Thanks,
    Ketan

  • Make ALV GRID screen resizable

    Hi All,
    I have created an object V_MAPBOX using reference to class CL_GUI_DIALOGBOX_CONTAINER.
    CREATE OBJECT v_mapbox
          EXPORTING
            width = 300
            height = 130
            style = cl_gui_control=>ws_sysmenu
            repid = 'ZMAP'
            dynnr = '1000'
            top = v_top2
            left = v_left2
            caption = 'Mapping Information'
          EXCEPTIONS
            cntl_error = 1
            cntl_system_error = 2
            create_error = 3
            lifetime_error = 4
            lifetime_dynpro_dynpro_link = 5
            event_already_registered = 6
            error_regist_event = 7
            OTHERS = 8.
    Then created an object V_MAPALV with reference to class CL_GUI_ALV_GRID exporting V_MAPBOX.
    Finally I am calling the method SET_TABLE_FOR_FIRST_DISPLAY of CL_GUI_ALV_GRID to display the screen on my custom container of screen 1000.
        CALL METHOD v_mapalv->set_table_for_first_display
          EXPORTING
            i_save                        = 'A'
            is_layout                     = wa_layout
          CHANGING
            it_outtab                     = i_map
            it_fieldcatalog              = i_fieldcat_map
          EXCEPTIONS
            invalid_parameter_combination = 1
            program_error                 = 2
            too_many_lines                = 3
            OTHERS                        = 4.
        IF sy-subrc <> 0.
        ENDIF.
    The screen is getting displayed as expected. But I require to make this ALV screen to be resizable while it is displayed.
    Have tried calling     CALL METHOD v_mapbox->resize, before calling the V_MAPALV methods but it does not work.
    Need to know how can I make this resizable.

    Hi,
    ABAP objects are used to implement the controls in programs.
    An SAP Container can contain other controls (for example, SAP ALV Grid Control, Tree Control, SAP Picture Control, SAP Splitter Control, and so on). It administers these controls logically in one collection and provides a physical area for the display.
    Every control exists in a container. Since containers are themselves controls, they can be nested within one another. The container becomes the parent of its control. SAP containers are divided into five groups:
    SAP custom container: Displays within an area defined in Screen Painter on screens or sub screens.
    Class: CL_GUI_CUSTOM_CONTAINER
    SAP dialog box container: Displays in a modeless dialog box or as a full screen. Class:
    CL_GUI_DIALOGBOX_CONTAINER
    SAP docking container: Displays as docked, resizable sub-window with the option of displaying it as a modeless dialog box. Class: CL_GUI_DOCKING_CONTAINER
    SAP splitter container: Displays and groups several controls in one area - that is, splits the area into cells Class: CL_GUI_SPLITTER_CONTAINER
    SAP easy splitter container: Displays controls in two cells, which the user can resize using a split bar. Class: CL_GUI_EASY_SPLITTER_CONTAINER.
    In the control, you can adjust the column width by dragging, or use the 'Optimum width' function to adjust the column width to the data currently displayed. You can also change the column sequence by selecting a column and dragging it to a new position.
    Thanks,
    Pradeep.

  • Stretch alv grid screen

    Hi,
    I've a screen with alv grid in a custom control.
    I'd like to make it stretch (+-) with the mouse, is it possible?
    Thanks in advance,
    Maria João Rocha

    Maria,
    I am assuming that the GRID is not occupying the entire space on your screen and you want to pull and fit into the screen.
    FOr this what you need to do is.
    1. On the Screen you have placed a CUSTOM CONTROL, right?
      Stretch to the extent possible - if you don't have anything else on the screen, make the control occupy the entire screen.
    2. Double click, shows the properties. There will be HORIZONTAL AND VERTICAL properties at the end of the screen. Check both the boxes and give 1 and 1 in the field next to them.
    This automatcially makes sure that the container will occupy the entire space available on the screen.
    Regards,
    Ravi
    Note : Please mark the helpful answers.

  • How to make a field manadatory within ALV Grid using methods and classes

    Hi,
    I am using ALV Grid using set_table_for_first_display
    inside my dialog programming. I have a field called project number inside my grid which has to be made as mandatory field.
    I have defined a method called catch_data_changed inside my class lcl_event_receiver. This method captures the changes made to one of the fields inside my ALV grid and displays all the default values of the other fields from the grid.
    Now, i have to make project number which is one of my fields inside my ALV grid as mandatory. At the field catalog level i did not find any such option for making a field as required field.
    Is there any other way, i can accomplish this within the ALV grid?

    from my understanding from ur question, i understood that u want the editable field inside alvgrid to be mandatory.
    i dont know anthing in fieldcat, but u can try the following logic.
    FORM DATA_CHANGED  USING P_ER_DATA_CHANGED TYPE REF TO
    CL_ALV_CHANGED_DATA_PROTOCOL .
      DATA: L_VALUE TYPE LVC_VALUE,
        ls_mod_cell type lvc_s_modi.
      READ TABLE P_ER_DATA_CHANGED->MT_MOD_CELLS INTO LS_MOD_CELL.
    if sy-subrc = 0.
        CALL METHOD P_ER_DATA_CHANGED->GET_CELL_VALUE
          EXPORTING
            I_ROW_ID    = LS_MOD_CELL-row_id
            I_FIELDNAME = LS_MOD_CELL-fieldname
          IMPORTING
            E_VALUE     = L_VALUE.
    IF LS_MOD_CELL-FIELDNAME <> 'fieldname what u want'
    MESSAGE 'ENTER VALUE INTO (fieldname u want) ' TYPE 'I'.
    ENDIF.
    ELSE.
    MESSAGE 'ENTER VALUE INTO (fieldname u want) ' TYPE 'I'.
    ENDIF.

  • How to validate the columns in dynamic alv grid

    Hi Friends,
    I want to validatethe value of all the columens (min 1 and max 40) which i create dynamically in alv grid.
    value must be between 0 and 1 only.
    Please help ,, need urgently.

    method handle_data_changed.
         data: ls_good type lvc_s_modi,
               li_diff type i,
               value type p DECIMALS 3,
               old_value type p DECIMALS 3,
               lw_outtab1 type gt_tab.
    clear value.
           loop at er_data_changed->mt_good_cells into ls_good.
           value = ls_good-value.
           old_value = ls_good-value.
            if value lt 0 or value gt 1.
               MESSAGE 'Value is out of range' TYPE 'I'.
              Read table gt_outtab1 into lw_outtab1 index ls_good-row_id .
               perform show_alv.
               clear ls_good.
            ENDIF.
          ENDCASE.
           ENDLOOP.
    I again created the table.. actually data is not changed in the internal table but still it shows the changed value in the alv grid. even in build the table again and call the refersh alv grid method..

  • ALV Grid  screen limit for a long field

    Hi, i am having a problem making an ALV Grid of IDOC contents, i want to show de SDATA field of de EDIDD structure, but it is a 1000 char field, and when the ALV comes out i can only see part of the field.
    I think the problem is the scrollbar, because it seems it not allows to scroll unless a field is starting or ending at the right or left of the screen.
    It is a way to solve this problem?
    thanks
    best regards
    Mariano Billinghurst.

    a®s, thank you I have already tougth that solution but my client wants to see all in the alv to compare the lines.
    I anyonelse have an idea it is wellcome!
    thanks.
    mariano.

  • Dynamic ALV Grid Footer

    Hi experts,
    I have a ALV Grid display, for example I selected 2 rows out of 5 from the display ALV, then I have a footer which contains: number of line items selected : v_no_lines. The v_no_lines is the number of rows selected from the display ALV which is 2. The total number of line items selected should be displayed on the bottom section of the ALV Grid.

    DATA:wf_data TYPE REF TO data,
         wf_str TYPE REF TO data.
    DATA: wf_alv TYPE REF TO cl_salv_table.
    FIELD-SYMBOLS:<fs_tab> TYPE STANDARD TABLE,
                  <fs_line> TYPE ANY,
                  <fs_f> TYPE ANY,
                  <fs_t> TYPE ANY..
    CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
      EXPORTING
        class              = 'ENG-DATA-METALS'
        classtext          = ' '
        classtype          = 'Z03'
        features           = 'X'
        language           = sy-langu
        object             = '338127-1'
        objecttable        = 'MARA' "tcla-obtab
        key_date           = sy-datum
        initial_charact    = ' '
        change_service_clf = ' '
        inherited_char     = ' '
        change_number      = ' '
      TABLES
        t_class            = i_sclass[]
        t_objectdata       = i_object[]
      EXCEPTIONS
        no_classification  = 1
        no_classtypes      = 2
        invalid_class_type = 3
        OTHERS             = 4.
    CHECK sy-subrc = 0.
    lines = LINES( i_object ).

  • Calling ALV grid in class method

    Is it possible to call a ALV grid display in a class~method.
    I thought, I would call a screen and make a ALV grid display using the control frame work,it is no possible to call screen inside a method.
    Then i tried to avoid calling the screen..
    data: dockingleft type ref to cl_gui_docking_container,
            alv_left    type ref to cl_gui_alv_grid,
            repid type syrepid.
      repid = sy-repid.
      check dockingleft is initial.
      create object dockingleft
                  exporting repid     = repid
                            dynnr     = sy-dynnr
                            side      = dockingleft->dock_at_left
                            extension = 1700.
      create object alv_left
                    exporting i_parent = dockingleft .
      call method alv_left->set_table_for_first_display
          exporting
               i_structure_name       = 'SMESG'
          changing
               it_outtab       = TSMESG[]
      EXCEPTIONS
          INVALID_PARAMETER_COMBINATION = 1
          PROGRAM_ERROR                 = 2
          TOO_MANY_LINES                = 3
          others                        = 4.
    This doesn't seem to invoke the ALV grid. Any suggestions ?

    Hi,
    You need to call you custom screen with custom container like the following
      create object g_docking_container_1
        exporting
          repid     = g_repid
          dynnr     = '100'      "Place the custom container in 100
          extension = 1700
          side      = cl_gui_docking_container=>dock_at_left.
    then
      call method alv_left->set_table_for_first_display

  • Custom total/subtotal formula in an ALV Grid and printing.

    I have an ALV grid using OOPs method (Class cl_gui_alv_grid). The table that I am displaying is a dynamic table.
    call method o_grid->set_table_for_first_display
        exporting
          is_variant      = gx_variant
          i_save          = 'A'
          is_layout       = gs_layout
        changing
          it_fieldcatalog = it_fldcat
          it_outtab       = <gt_tabletotal>.
    On one of the columns in the ALV grid, instead of the regular summation, I had to do weighted averages (not avg).
    I built a logic to manipulate this total field for that column using field symbols.
    CALL METHOD o_grid->get_subtotals
        IMPORTING ep_collect00 = total
                  ep_collect01 = subto.
    ASSIGN total->* TO <ftotal>.
    ASSIGN subto->* TO <fsubto>.
    CALL METHOD o_grid->refresh_table_display
       EXPORTING I_SOFT_REFRESH = '1' .
    I manipulated <ftotal>-mycustomformulafield field there using some logic.
    In my field catalog i have the above field with wa_it_fldcat-do_sum = 'X ' .
    Now, II am able to see my custom formula on the screen. But when I print the grid using the print button or when I export to an excel sheet(I use export to local file and then select excel there) , my custom formula that i calculated above is reset to 0.000 .
    (Also when I email the grid, my custom formula is wiped). How can I avoid this ? Any useful suggestion is well appreciated.

    Hi, Shareen,
    We have the same problema here.
    Could you solve it?
    Thanks in advance

  • How to use ALV Grid?

    Hi,
    I am totally new to ALV Grids. Could you give a full example of creating a ALV Grid with 2 columns, thinking there is a internal table itab with itab-col1 & itab-col2. Please start from initialising variables and onwards.
    Thanks,
    Kishan

    Hi,
    Simple example of how to implement an ALV grid
    Note that this example uses table ZSFLIGHT. The table is equivalent to the table SFLIGHT.
    Steps:
    1.        Create an executable program (Report)
    2.        Create a screen (100) and place a custom container named ALV_CONTAINER on the screen
    3.        Create a Pushbutton. Give it the text Exit and the functioncode EXIT
    REPORT sapmz_hf_alv_grid .
    TABLES: zsflight.
    G L O B A L   I N T E R N  A L   T A B L E S
    DATA: gi_sflight TYPE STANDARD TABLE OF sflight.
    G L O B A L   D A T A
    DATA: ok_code LIKE sy-ucomm,
    g_wa_sflight LIKE sflight.
    Declare reference variables to the ALV grid and the container
    DATA:
    go_grid             TYPE REF TO cl_gui_alv_grid,
    go_custom_container TYPE REF TO cl_gui_custom_container.
    S T A R T - O F - S E L E C T I O N.
    START-OF-SELECTION.
    SET SCREEN '100'.
    *&      Module  USER_COMMAND_0100  INPUT
    MODULE user_command_0100 INPUT.
    CASE ok_code.
    WHEN 'EXIT'.
    LEAVE TO SCREEN 0.
    ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Module  STATUS_0100  OUTPUT
    MODULE status_0100 OUTPUT.
    Create objects
    IF go_custom_container IS INITIAL.
    CREATE OBJECT go_custom_container
    EXPORTING container_name = 'ALV_CONTAINER'.
    CREATE OBJECT go_grid
    EXPORTING
      i_parent = go_custom_container.
    PERFORM load_data_into_grid.
    ENDIF.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Form  load_data_into_grid
    FORM load_data_into_grid.
    Read data from table SFLIGHT
    SELECT *
    FROM zsflight
    INTO TABLE gi_sflight.
    Load data into the grid and display them
    CALL METHOD go_grid->set_table_for_first_display
    EXPORTING i_structure_name = 'SFLIGHT'
    CHANGING  it_outtab        = gi_sflight.
    ENDFORM.                    " load_data_into_grid
    Allow the user to save and reuse the layout
    A button can be shown on the grid toolbar, allowing the user to save and reuse a layout. The button looks like this: 
    See also example in SAP standard program BCALV_GRID_09.
    To do this use the parameters IS_VARIANT and I_SAVE of the set_table_for_first_display method. Note that the IS_VARIANT
    parameter must have the structure DISVARIANT.
    The I_SAVE "Options for saving layouts" parameter can have the following values:
    ·        U Only user specific layouts can be saved
    ·        X Only global layouts can be saved
    ·        A Both user specific and global layouts can be saved
    ·        Space Layouts can not be saved
    Add the following code to the example:
    FORM load_data_into_grid.
    DATA:
      For parameter IS_VARIANT
    l_layout TYPE disvariant.
    Code..........    
    Load data into the grid and display them
    l_layout-report = sy-repid.
    CALL METHOD go_grid->set_table_for_first_display
    EXPORTING i_structure_name = 'SFLIGHT'
         is_variant       = l_layout
         i_save           = 'A'
    CHANGING  it_outtab        = gi_
    Integrate user defined functions in the grid toolbar
    Possibilities:
    ·        Replace existing functions in the toolbar or context men with user defined functions
    ·        Add new functions to the toolbar or context menu
    Note that the whole toolbar can be removed using the IT_TOOLBAR_EXCLUDING parameter of the set_table_for_first_display
    method.
    See also example in SAP standard program BCALV_GRID_05
    1) To get access to the icons insert the following statement in the top of the program:
    TYPE-POOLS: icon.
    2) To allow the declaration of o_event_receiver before the lcl_event_receiver class is defined, declare it as deferred in the start of
    the program
    To allow the declaration of o_event_receiver before the lcl_event_receiver class is defined, declare it as deferred in the
    start of the program
    CLASS lcl_event_receiver DEFINITION DEFERRED.
    3) Declare reference to the event handler class
    DATA:
    o_event_receiver TYPE REF TO lcl_event_receiver.
    4) Class for event receiver. This class adds the new button to the toolbar and handles the event when the button is pushed
    CLASS lcl_event_receiver DEFINITION.
    PUBLIC SECTION.
    METHODS:
    handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
    IMPORTING
    e_object e_interactive,
    handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
    IMPORTING e_ucomm.
    ENDCLASS.
          CLASS lcl_event_receiver IMPLEMENTATION
    CLASS lcl_event_receiver IMPLEMENTATION.
    METHOD handle_toolbar.
    Event handler method for event toolbar.
    CONSTANTS:
    Constants for button type
    c_button_normal           TYPE i VALUE 0,
    c_menu_and_default_button TYPE i VALUE 1,
    c_menu                    TYPE i VALUE 2,
    c_separator               TYPE i VALUE 3,
    c_radio_button            TYPE i VALUE 4,
    c_checkbox                TYPE i VALUE 5,
    c_menu_entry              TYPE i VALUE 6.
    DATA:
    ls_toolbar  TYPE stb_button.
      Append seperator to the normal toolbar
    CLEAR ls_toolbar.
    MOVE c_separator TO ls_toolbar-butn_type..
    APPEND ls_toolbar TO e_object->mt_toolbar.
      Append a new button that to the toolbar. Use E_OBJECT of
      event toolbar. E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.
      This class has one attribute MT_TOOLBAR which is of table type
      TTB_BUTTON. The structure is STB_BUTTON
    CLEAR ls_toolbar.
    MOVE 'CHANGE'        TO ls_toolbar-function.
    MOVE  icon_change    TO ls_toolbar-icon.
    MOVE 'Change flight' TO ls_toolbar-quickinfo.
    MOVE 'Change'        TO ls_toolbar-text.
    MOVE ' '             TO ls_toolbar-disabled.
    APPEND ls_toolbar    TO e_object->mt_toolbar.
    ENDMETHOD.
    METHOD handle_user_command.
      Handle own functions defined in the toolbar
    CASE e_ucomm.
    WHEN 'CHANGE'.
    LEAVE TO SCREEN 0.
    ENDCASE.
    ENDMETHOD.
    ENDCLASS.
    5) In the PBO module, crate object for event handler and set handler
    CREATE OBJECT o_event_receiver.
    SET HANDLER o_event_receiver->handle_user_command FOR go_grid.
    SET HANDLER o_event_receiver->handle_toolbar FOR go_grid.
    6) In the PBO module after the CALL METHOD go_grid->set_table_for_first_display, raise event
    toolbar to show the modified toolbar
    CALL METHOD go_grid->set_toolbar_interactive.
    Set focus to the grid
    After CALL METHOD go_grid->set_table_for_first_display insert the following statement:
    CALL METHOD cl_gui_control=>set_focus EXPORTING control = go_grid.
    Set the title of the grid
    Fill the grid_title field of structure lvc_s_layo.
    Note that the structure lvc_s_layo can be used for to customize the grid appearance in many ways.
    DATA:
    ALV control: Layout structure
    gs_layout TYPE lvc_s_layo.
    Set grid title
    gs_layout-grid_title = 'Flights'.
    CALL METHOD go_grid->set_table_for_first_display
       EXPORTING i_structure_name = 'SFLIGHT'
                               is_layout               = gs_layout
       CHANGING   it_outtab               = gi_sflight.
    Customize the appearence of the grid
    The structure lvc_s_layo contains fields for setting graphical properties, displaying exceptions, calculating totals and enabling specific
    interaction options.
    Fill the apporpiate fields of structure lvc_s_layo and insert it as a parameter in the CALL METHOD
    go_grid->set_table_for_first_display. See the example under Set the title of the grid.
    If you want to change apperance after list output, use the methods get_frontend_layout and set_frontend_layout.
    Examples of fields in structure lvc_s_layo:
    GRID_TITLE Setting the title of the grid
    SEL_MODE. Selection mode, determines how rows can be selected. Can have the following values:
    ·        A Multiple columns, multiple rows with selection buttons.
    ·        B Simple selection, listbox, Single row/column
    ·        C Multiple rows without buttons
    ·        D Multiple rows with buttons and select all ICON
    Setting and getting selected rows (Columns) and read line contents
    You can read which rows of the grid that has been selected, and dynamic select rows of the grid using methods get_selected_rows
    and set_selected_rows. There are similar methods for columns.
    Note that the grid table always has the rows in the same sequence as displayed in the grid, thus you can use the index of the selected
    row(s) to read the information in the rows from the table. In the examples below the grid table is named gi_sflight.
    Data declaration:
    DATA:
    Internal table for indexes of selected rows
    gi_index_rows TYPE lvc_t_row,
    Information about 1 row
    g_selected_row LIKE lvc_s_row.
    Example 1: Reading index of selected row(s) and using it to read the grid table
    CALL METHOD go_grid->get_selected_rows
    IMPORTING
    et_index_rows = gi_index_rows.
    DESCRIBE TABLE gi_index_rows LINES l_lines.
    IF l_lines = 0.
    CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
    EXPORTING
         textline1 = 'You must choose a valid line'.
    EXIT.
    ENDIF.
    LOOP AT gi_index_rows INTO g_selected_row.
    READ TABLE gi_sflight INDEX g_selected_row-index INTO g_wa_sflight.
    ENDIF.
    ENDLOOP.
    Example 2: Set selected row(s).
    DESCRIBE TABLE gi_index_rows LINES l_lines.
    IF l_lines > 0.
    CALL METHOD go_grid->set_selected_rows
    exporting
    it_index_rows = gi_index_rows.
    ENDIF.
    Make an Exception field ( = Traffic lights)
    There can be defined a column in the grid for display of traffic lights. This field is of type Char 1, and can contain the following values:
    ·        1 Red
    ·        2 Yellow
    ·        3 Green
    The name of the traffic light field is supplied inh the gs_layout-excp_fname used by method set_table_for_first_display.
    Example
    TYPES: BEGIN OF st_sflight.
    INCLUDE STRUCTURE zsflight.
    TYPES:  traffic_light TYPE c.
    TYPES: END OF st_sflight.
    TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
    DATA: gi_sflight TYPE tt_sflight.
      Set the exception field of the table
    LOOP AT gi_sflight INTO g_wa_sflight.
    IF g_wa_sflight-paymentsum < 100000.
    g_wa_sflight-traffic_light = '1'.
    ELSEIF g_wa_sflight-paymentsum => 100000 AND
        g_wa_sflight-paymentsum < 1000000.
    g_wa_sflight-traffic_light = '2'.
    ELSE.
    g_wa_sflight-traffic_light = '3'.
    ENDIF.
    MODIFY gi_sflight FROM g_wa_sflight.
    ENDLOOP.
      Name of the exception field (Traffic light field)
    gs_layout-excp_fname = 'TRAFFIC_LIGHT'.
      Grid setup for first display
    CALL METHOD go_grid->set_table_for_first_display
    EXPORTING i_structure_name = 'SFLIGHT'
                         is_layout               = gs_layout
    CHANGING  it_outtab                 = gi_sflight.
    Color a line
    The steps for coloring a line i the grid is much the same as making a traffic light.
    To color a line the structure of the  table must include a  Char 4 field  for color properties
    TYPES: BEGIN OF st_sflight.
    INCLUDE STRUCTURE zsflight.
          Field for line color
    types:  line_color(4) type c.
    TYPES: END OF st_sflight.
    TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
    DATA: gi_sflight TYPE tt_sflight.
    Loop trough the table to set the color properties of each line. The color properties field is
    Char 4 and the characters is set as follows:
    Char 1 = C = This is a color property
    Char 2 = 6 = Color code (1 - 7)
    Char 3 = Intensified on/of = 1 = on
    Char 4 = Inverse display = 0 = of
    LOOP AT gi_sflight INTO g_wa_sflight.
    IF g_wa_sflight-paymentsum < 100000.
    g_wa_sflight-line_color    = 'C610'.
    ENDIF.
    MODIFY gi_sflight FROM g_wa_sflight.
    ENDLOOP.
    Name of the color field
    gs_layout-info_fname = 'LINE_COLOR'.
    Grid setup for first display
    CALL METHOD go_grid->set_table_for_first_display
    EXPORTING i_structure_name = 'SFLIGHT'
                        is_layout                = gs_layout
    CHANGING  it_outtab                 = gi_sflight.
    Refresh grid display
    Use the grid method REFRESH_TABLE_DISPLAY
    Example:
    CALL METHOD go_grid->refresh_table_display.
    Complete code for the ALV grid example
    This example shows and ALV grid with flights. After selecting a line a change button can be pushed to display a change screen. After
    the changes have been saved, the ALV grid screen is displayed again, and the grid is updated with the changes.
    The example shows:
    ·        How to setup the ALV grid
    ·        How to ste focus to the grid
    ·        How to set the title of the grid
    ·        How to allow a user to save and reuse a grid layout (Variant)
    ·        How to customize the ALV grid toolbar
    ·        Refresh the grid
    ·        Set and get row selection and read line contents
    ·        Make and exception field (Traffic light)
    ·        Coloring a line
    Steps:
    ·        Create screen 100 with the ALV grid. Remember to include an exit button
    ·        Add a change button to the ALV grid toolbar
    ·        Create screen 200 the Change screen
    The screens: 
    The code:
    REPORT sapmz_hf_alv_grid .
    Type pool for icons - used in the toolbar
    TYPE-POOLS: icon.
    TABLES: zsflight.
    To allow the declaration of o_event_receiver before the
    lcl_event_receiver class is defined, decale it as deferred in the
    start of the program
    CLASS lcl_event_receiver DEFINITION DEFERRED.
    G L O B A L   I N T E R N  A L   T A B L E S
    *DATA: gi_sflight TYPE STANDARD TABLE OF sflight.
    To include a traffic light and/or color a line the structure of the
    table must include fields for the traffic light and/or the color
    TYPES: BEGIN OF st_sflight.
      INCLUDE STRUCTURE zsflight.
          Field for traffic light
    TYPES:  traffic_light TYPE c.
          Field for line color
    types:  line_color(4) type c.
    TYPES: END OF st_sflight.
    TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
    DATA: gi_sflight TYPE tt_sflight.
    G L O B A L   D A T A
    DATA: ok_code         LIKE sy-ucomm,
        Work area for internal table
    g_wa_sflight    TYPE st_sflight,
        ALV control: Layout structure
    gs_layout       TYPE lvc_s_layo.
    Declare reference variables to the ALV grid and the container
    DATA:
    go_grid             TYPE REF TO cl_gui_alv_grid,
    go_custom_container TYPE REF TO cl_gui_custom_container,
    o_event_receiver    TYPE REF TO lcl_event_receiver.
    DATA:
    Work area for screen 200
    g_screen200 LIKE zsflight.
    Data for storing information about selected rows in the grid
    DATA:
    Internal table
    gi_index_rows TYPE lvc_t_row,
    Information about 1 row
    g_selected_row LIKE lvc_s_row.
    C L A S S E S
    CLASS lcl_event_receiver DEFINITION.
    PUBLIC SECTION.
    METHODS:
    handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
    IMPORTING
       e_object e_interactive,
    handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
    IMPORTING e_ucomm.
    ENDCLASS.
          CLASS lcl_event_receiver IMPLEMENTATION
    CLASS lcl_event_receiver IMPLEMENTATION.
    METHOD handle_toolbar.
    Event handler method for event toolbar.
    CONSTANTS:
    Constants for button type
    c_button_normal           TYPE i VALUE 0,
    c_menu_and_default_button TYPE i VALUE 1,
    c_menu                    TYPE i VALUE 2,
    c_separator               TYPE i VALUE 3,
    c_radio_button            TYPE i VALUE 4,
    c_checkbox                TYPE i VALUE 5,
    c_menu_entry              TYPE i VALUE 6.
    DATA:
      ls_toolbar  TYPE stb_button.
      Append seperator to the normal toolbar
    CLEAR ls_toolbar.
    MOVE c_separator TO ls_toolbar-butn_type..
    APPEND ls_toolbar TO e_object->mt_toolbar.
      Append a new button that to the toolbar. Use E_OBJECT of
      event toolbar. E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.
      This class has one attribute MT_TOOLBAR which is of table type
      TTB_BUTTON. The structure is STB_BUTTON
    CLEAR ls_toolbar.
    MOVE 'CHANGE'        TO ls_toolbar-function.
    MOVE  icon_change    TO ls_toolbar-icon.
    MOVE 'Change flight' TO ls_toolbar-quickinfo.
    MOVE 'Change'        TO ls_toolbar-text.
    MOVE ' '             TO ls_toolbar-disabled.
    APPEND ls_toolbar    TO e_object->mt_toolbar.
    ENDMETHOD.
    METHOD handle_user_command.
      Handle own functions defined in the toolbar
    CASE e_ucomm.
    WHEN 'CHANGE'.
      PERFORM change_flight.
           LEAVE TO SCREEN 0.
    ENDCASE.
    ENDMETHOD.
    ENDCLASS.
    S T A R T - O F - S E L E C T I O N.
    START-OF-SELECTION.
    SET SCREEN '100'.
    *&      Module  USER_COMMAND_0100  INPUT
    MODULE user_command_0100 INPUT.
    CASE ok_code.
    WHEN 'EXIT'.
    LEAVE TO SCREEN 0.
    ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Module  STATUS_0100  OUTPUT
    MODULE status_0100 OUTPUT.
    DATA:
      For parameter IS_VARIANT that is sued to set up options for storing
      the grid layout as a variant in method set_table_for_first_display
    l_layout TYPE disvariant,
      Utillity field
    l_lines TYPE i.
    After returning from screen 200 the line that was selected before
    going to screen 200, should be selected again. The table gi_index_rows
    was the output table from the GET_SELECTED_ROWS method in form
    CHANGE_FLIGHT
    DESCRIBE TABLE gi_index_rows LINES l_lines.
    IF l_lines > 0.
    CALL METHOD go_grid->set_selected_rows
      EXPORTING
        it_index_rows = gi_index_rows.
    CALL METHOD cl_gui_cfw=>flush.
    REFRESH gi_index_rows.
    ENDIF.
    Read data and create objects
    IF go_custom_container IS INITIAL.
      Read data from datbase table
    PERFORM get_data.
      Create objects for container and ALV grid
    CREATE OBJECT go_custom_container
    EXPORTING container_name = 'ALV_CONTAINER'.
    CREATE OBJECT go_grid
    EXPORTING
      i_parent = go_custom_container.
      Create object for event_receiver class
      and set handlers
    CREATE OBJECT o_event_receiver.
    SET HANDLER o_event_receiver->handle_user_command FOR go_grid.
    SET HANDLER o_event_receiver->handle_toolbar FOR go_grid.
      Layout (Variant) for ALV grid
    l_layout-report = sy-repid. "Layout fo report
    Setup the grid layout using a variable of structure lvc_s_layo
      Set grid title
    gs_layout-grid_title = 'Flights'.
      Selection mode - Single row without buttons
      (This is the default  mode
    gs_layout-sel_mode = 'B'.
      Name of the exception field (Traffic light field) and the color
      field + set the exception and color field of the table
    gs_layout-excp_fname = 'TRAFFIC_LIGHT'.
    gs_layout-info_fname = 'LINE_COLOR'.
    LOOP AT gi_sflight INTO g_wa_sflight.
    IF g_wa_sflight-paymentsum < 100000.
          Value of traffic light field
      g_wa_sflight-traffic_light = '1'.
          Value of color field:
          C = Color, 6=Color 1=Intesified on, 0: Inverse display off
      g_wa_sflight-line_color    = 'C610'.
    ELSEIF g_wa_sflight-paymentsum => 100000 AND
           g_wa_sflight-paymentsum < 1000000.
      g_wa_sflight-traffic_light = '2'.
    ELSE.
      g_wa_sflight-traffic_light = '3'.
    ENDIF.
    MODIFY gi_sflight FROM g_wa_sflight.
    ENDLOOP.
      Grid setup for first display
    CALL METHOD go_grid->set_table_for_first_display
    EXPORTING i_structure_name = 'SFLIGHT'
              is_variant       = l_layout
              i_save           = 'A'
              is_layout        = gs_layout
    CHANGING  it_outtab        = gi_sflight.
    *-- End of grid setup -
      Raise event toolbar to show the modified toolbar
    CALL METHOD go_grid->set_toolbar_interactive.
      Set focus to the grid. This is not necessary in this
      example as there is only one control on the screen
    CALL METHOD cl_gui_control=>set_focus EXPORTING control = go_grid.
    ENDIF.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0200  INPUT
    MODULE user_command_0200 INPUT.
    CASE ok_code.
    WHEN 'EXIT200'.
    LEAVE TO SCREEN 100.
    WHEN'SAVE'.
    PERFORM save_changes.
    ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0200  INPUT
    *&      Form  get_data
    FORM get_data.
    Read data from table SFLIGHT
    SELECT *
    FROM zsflight
    INTO TABLE gi_sflight.
    ENDFORM.                    " load_data_into_grid
    *&      Form  change_flight
    Reads the contents of the selected row in the grid, ans transfers
    the data to screen 200, where it can be changed and saved.
    FORM change_flight.
    DATA:l_lines TYPE i.
    REFRESH gi_index_rows.
    CLEAR   g_selected_row.
    Read index of selected rows
    CALL METHOD go_grid->get_selected_rows
    IMPORTING
    et_index_rows = gi_index_rows.
    Check if any row are selected at all. If not
    table  gi_index_rows will be empty
    DESCRIBE TABLE gi_index_rows LINES l_lines.
    IF l_lines = 0.
    CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
       EXPORTING
            textline1 = 'You must choose a line'.
    EXIT.
    ENDIF.
    Read indexes of selected rows. In this example only one
    row can be selected as we are using gs_layout-sel_mode = 'B',
    so it is only ncessary to read the first entry in
    table gi_index_rows
    LOOP AT gi_index_rows INTO g_selected_row.
    IF sy-tabix = 1.
    READ TABLE gi_sflight INDEX g_selected_row-index INTO g_wa_sflight.
    ENDIF.
    ENDLOOP.
    Transfer data from the selected row to screenm 200 and show
    screen 200
    CLEAR g_screen200.
    MOVE-CORRESPONDING g_wa_sflight TO g_screen200.
    LEAVE TO SCREEN '200'.
    ENDFORM.                    " change_flight
    *&      Form  save_changes
    Changes made in screen 200 are written to the datbase table
    zsflight, and to the grid table gi_sflight, and the grid is
    updated with method refresh_table_display to display the changes
    FORM save_changes.
    DATA: l_traffic_light TYPE c.
    Update traffic light field
    Update database table
    MODIFY zsflight FROM g_screen200.
    Update grid table , traffic light field and color field.
    Note that it is necessary to use structure g_wa_sflight
    for the update, as the screen structure does not have a
    traffic light field
    MOVE-CORRESPONDING g_screen200 TO g_wa_sflight.
    IF g_wa_sflight-paymentsum < 100000.
    g_wa_sflight-traffic_light = '1'.
      C = Color, 6=Color 1=Intesified on, 0: Inverse display off
    g_wa_sflight-line_color    = 'C610'.
    ELSEIF g_wa_sflight-paymentsum => 100000 AND
       g_wa_sflight-paymentsum < 1000000.
    g_wa_sflight-traffic_light = '2'.
    clear g_wa_sflight-line_color.
    ELSE.
    g_wa_sflight-traffic_light = '3'.
    clear g_wa_sflight-line_color.
    ENDIF.
    MODIFY gi_sflight INDEX g_selected_row-index FROM g_wa_sflight.
    Refresh grid
    CALL METHOD go_grid->refresh_table_display.
    CALL METHOD cl_gui_cfw=>flush.
    LEAVE TO SCREEN '100'.
    ENDFORM.                    " save_changes
    rgds,
    latheesh

Maybe you are looking for

  • Text/Caption in Web Dyn Pro? (Newline possible?)

    Is it possible to add a new line for text in caption in web dyn pro? In Java, I tried storing the string as "Result.\nPass" but it seems when being displayed, the new line is not shown but it is only shown in one whole line. Any advise?

  • Pci-e 3.0 not showing..Only PCI-e 2.0...I7 3770k and GTX 660 TI-Z77a-G43

    I am hoping this is an easy one for all of you....I just built another Msi Board...Board in the title.... I enabled Pci-e 3 in Bios-before I even installed the operating system.....so after all the updates...all the drivers....100% ready for retail..

  • AppleCare for macbook..is it still valid if I move to another country?

    What happens to the validity of an AppleCare plan bought in one country if you then move to another? I was under the impression that for laptops the warranty is global, but in the terms and conditions of mine it says that it is only valid in the coun

  • Billing / customer service issues

    VERIZON ISSUES I have been fighting to get a credit since mid-sept. This is edge-up phone return billed because it was never take out of verizons system even though I have tracked and they have received it. literately over a dozen time was reassured

  • Some links not working on PC?

    I have designed this site for a friend and i'm at a stage of real frustration as some of the links on the flash site work fine on Mac but not on PC. To relay her fears, I have asked a PC friend of mine to test the links on his PC and he came back say