Representing a table as a grid

I am a novice java programmer and need some assistance. I am trying to take a table composed of test, dates, and test results. I want to take this table and restructure it and display it as a grid with tests as row headers and dates as column headers and results in the grid. The test results are of different types as well. I am also trying to have a mapping from (row, column) pairs to the object stored at that location in the table. I would appreciate any ideas.
Thanks a lot in advance
JA

Well, I haven't worked with JTable but I don't think it would be too hard to get the column labels from the ResultSet and set them as column headers in the table. Then you just loop through the ResultSet and populate the rows of the JTable, right?

Similar Messages

  • Modifying database table in ALV Grid

    Hi all.
    I need to be able to modify the database table in ALV Grid. Here's the code. The database table, that is displayed is 'zng_so_head', it's internal table is 'res_tab'. In the program i tried to create a button 'CHANGE' on the ALV-toolbar, but when executing the program there's no such button (why?). What code, screens, screen elements, etc. should be added to this program to provide a possibility of changing data of the database table 'zng_so_head' (i mean changing existing data, adding new lines and saving changes)?
    CODE:
    & Report  ZNG_ALV_TC_EDIT_SIMP&
    REPORT  ZNG_ALV_TC_EDIT_SIMP.
    *-- GLOBAL DATA DECLARATIONS FOR ALV
    DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
    DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
    DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.
    DATA gt_fieldcat TYPE lvc_t_fcat.
    DATA gs_layout TYPE lvc_s_layo.
    TABLES: zng_so_head, zng_cust, zng_vendors.
    *-- STRUCTURE OF INTERNAL TABLE
    TYPES: BEGIN OF in_tab,
            so_num TYPE zng_so_head-so_num,          "type numc
            vend_num TYPE zng_so_head-vend_num,      "type numc
            cust_num TYPE zng_so_head-cust_num,      "type numc
            so_date TYPE zng_so_head-so_date,        "type dats
           END OF in_tab.
    *-- INTERNAL TABLE HOLDING LIST DATA
    DATA res_tab TYPE TABLE OF in_tab WITH HEADER LINE.
    *-- FILLING IN INTERNAL TABLE
    SELECT hso_num hvend_num hcust_num hso_date
    INTO TABLE res_tab FROM zng_so_head AS h.
    *&      Form  prepare_field_catalog
    FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
      DATA ls_fcat TYPE lvc_s_fcat.
      ls_fcat-fieldname = 'SO_NUM'.
      ls_fcat-inttype = 'N'.
      ls_fcat-ref_table = 'zng_so_head'.
      ls_fcat-outputlen = '12'.
      ls_fcat-coltext = 'SO_NUM'.
      ls_fcat-seltext = 'SO_NUM'.
      APPEND ls_fcat TO pt_fieldcat.
      CLEAR ls_fcat.
      ls_fcat-fieldname = 'VEND_NUM'.
      ls_fcat-inttype = 'N'.
      ls_fcat-ref_table = 'zng_so_head'.
      ls_fcat-outputlen = '12'.
      ls_fcat-coltext = 'VEND_NUM'.
      ls_fcat-seltext = 'VEND_NUM'.
      APPEND ls_fcat TO pt_fieldcat.
      CLEAR ls_fcat.
      ls_fcat-fieldname = 'CUST_NUM'.
      ls_fcat-inttype = 'N'.
      ls_fcat-ref_table = 'zng_so_head'.
      ls_fcat-outputlen = '12'.
      ls_fcat-coltext = 'CUST_NUM'.
      ls_fcat-seltext = 'CUST_NUM'.
      APPEND ls_fcat TO pt_fieldcat.
      CLEAR ls_fcat.
      ls_fcat-fieldname = 'SO_DATE'.
      ls_fcat-inttype = 'D'.
      ls_fcat-ref_table = 'zng_so_head'.
      ls_fcat-outputlen = '12'.
      ls_fcat-coltext = 'SO_DATE'.
      ls_fcat-seltext = 'SO_DATE'.
      APPEND ls_fcat TO pt_fieldcat.
    ENDFORM.                    "prepare_field_catalog
    *&      Form  display_alv
    FORM display_alv.
      IF gr_alvgrid IS INITIAL.
        CREATE OBJECT gr_ccontainer
        EXPORTING container_name = gc_custom_control_name.
        CREATE OBJECT gr_alvgrid
        EXPORTING i_parent = gr_ccontainer.
        PERFORM prepare_field_catalog CHANGING gt_fieldcat.
        CALL METHOD gr_alvgrid->set_table_for_first_display
          EXPORTING
            is_layout       = gs_layout
          CHANGING
            it_outtab       = res_tab[]
            it_fieldcatalog = gt_fieldcat.
      ELSE.
        CALL METHOD gr_alvgrid->refresh_table_display.
      ENDIF.
    ENDFORM.                    "display_alv
          CLASS lcl_event_handler DEFINITION
    CLASS lcl_event_handler DEFINITION.
      PUBLIC SECTION.
        METHODS:
        handle_toolbar
          FOR EVENT toolbar OF cl_gui_alv_grid
            IMPORTING e_object
                      e_interactive.
    ENDCLASS.             "lcl_event_handler DEFINITION
          CLASS lcl_event_handler IMPLEMENTATION
    CLASS lcl_event_handler IMPLEMENTATION.
      METHOD handle_toolbar.
        DATA: ls_toolbar TYPE stb_button.
        MOVE 3 TO ls_toolbar-butn_type.
        APPEND ls_toolbar TO e_object->mt_toolbar.
        CLEAR ls_toolbar.
        MOVE 'CHANGE' TO ls_toolbar-function.
        MOVE icon_change TO ls_toolbar-icon.
        MOVE 'change' TO ls_toolbar-quickinfo.
        MOVE 'change' TO ls_toolbar-text.
        APPEND ls_toolbar TO e_object->mt_toolbar.
      ENDMETHOD.                    "handle_toolbar
    ENDCLASS.                    "lcl_event_handler IMPLEMENTATION
    DATA object_ref TYPE REF TO lcl_event_handler.
    START-OF-SELECTION.
      CALL SCREEN 100.
    MODULE STATUS_0100 OUTPUT
    MODULE display_alv OUTPUT.
      SET PF-STATUS 'SCREEN_100'.
      PERFORM display_alv.
      CREATE OBJECT object_ref.
      SET HANDLER object_ref->handle_toolbar FOR gr_alvgrid.
    ENDMODULE.                    "display_alv OUTPUT
    MODULE USER_COMMAND_0100 INPUT
    MODULE user_command_0100 INPUT.
      IF sy-ucomm = 'BACK' OR
         sy-ucomm = 'EXIT' OR
         sy-ucomm = 'CANCEL'.
        LEAVE PROGRAM.
      ELSE.
        CALL METHOD object_ref->handle_toolbar.
      ENDIF.
    ENDMODULE.                    "status_0100 INPUT
    END OF CODE
    Thanks all.

    Hi,
    For the button on the toolbar,here is the code:
    CLASS lcl_eh IMPLEMENTATION.
    *METHOD:      HANDLE_TOOLBAR
    *DESCRIPTION: This method provides the necessary detail required to
                 create an extra button in the toolbar.
      METHOD handle_toolbar.
        CLEAR ls_toolbar.
        MOVE 'CHANGE' TO ls_toolbar-function.
        MOVE 0 TO ls_toolbar-butn_type.
        MOVE CHANGETO ls_toolbar-text.
        MOVE 'ICON_DETAIL' TO ls_toolbar-icon.
        MOVE 'CHANGE' TO ls_toolbar-quickinfo.
        APPEND ls_toolbar TO e_object->mt_toolbar.
      ENDMETHOD.                    "handle_toolbar
    Also,if you are using the CHANGE button to record changes in the DB,then in the local class that you have defined,you should use the following method and then write the logic:
    *METHOD:      HANDLE_USER_COMMAND
      METHOD handle_user_command.
        CASE e_ucomm.
          WHEN 'CHANGE'.
    CHECK_CHANGED_DATA
    REFRESH_TABLE_DISPLAY
    Now call the methods that i have given in my previous post.This function code will be checked at the event you click the button 'CHANGE'.I think you have done this in an ELSE condition in the PAI of the screen.Not too sure if it works in the PAI.
    Regards,
    Beejal
    **Reward if this helps

  • How to print to tables in ALV grid

    hi all
    I have 2 internal tables with some values
    i want to display the 2 internal tables in the grid one after another with some title
    can anyone tell me how to do it
    Thank you.

    i think in grid you can not do like this (By using function module). But you can do it in OO approach for that just check the se38 with alvgrid* and search. you can findout lot of example there. And one more option is there by using alv block but it is a list display.
    Just check this sample program of alv block
    TYPE-POOLS : SLIS.
    TABLES : EKKO,EKPO.
    DATA : BEGIN OF IEKKO OCCURS 0,
           EBELN LIKE EKKO-EBELN,
           AEDAT LIKE EKKO-AEDAT,
           END OF IEKKO.
    DATA : BEGIN OF IEKPO OCCURS 0,
           EBELN LIKE EKPO-EBELN,
           EBELP LIKE EKPO-EBELP,
           MATNR LIKE EKPO-MATNR,
           MENGE LIKE EKPO-MENGE,
           MEINS LIKE EKPO-MEINS,
           END OF IEKPO.
    DATA : IFIELDCATEKKO TYPE SLIS_T_FIELDCAT_ALV,
           IFIELDCATEKPO TYPE SLIS_T_FIELDCAT_ALV,
           WFIELDCAT     TYPE SLIS_FIELDCAT_ALV,
           ILAYOUT       TYPE SLIS_LAYOUT_ALV,
           IEVENTHEAD    TYPE SLIS_T_EVENT,
           IEVENTITEM    TYPE SLIS_T_EVENT,
           WEVENT        TYPE SLIS_ALV_EVENT,
           ISORT         TYPE SLIS_T_SORTINFO_ALV,
           WSORT         TYPE SLIS_SORTINFO_ALV.
    PARAMETERS : P_NUM(3) TYPE N DEFAULT 10.
    PERFORM GET_DATA_EKKO.
    PERFORM GET_DATA_EKPO.
    PERFORM BUILD_FCAT_HEAD.
    PERFORM BUILD_FCAT_ITEM.
    PERFORM BUILD_LAYOUT.
    PERFORM BUILD_EVENT_TAB.
    PERFORM DISPLAY_BLOCK.
    *&      Form  GET_DATA_EKKO
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM GET_DATA_EKKO .
    SELECT EBELN AEDAT INTO TABLE IEKKO FROM EKKO UP TO P_NUM ROWS WHERE EBELN LIKE '45000057%'.
    ENDFORM.                    " GET_DATA_EKKO
    *&      Form  GET_DATA_EKPO
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM GET_DATA_EKPO .
    IF NOT IEKKO[] IS INITIAL.
      SELECT EBELN EBELP MATNR MENGE MEINS INTO TABLE IEKPO FROM EKPO FOR ALL ENTRIES IN IEKKO
                                                      WHERE EBELN = IEKKO-EBELN.
    ENDIF.
    ENDFORM.                    " GET_DATA_EKPO
    *&      Form  DISPLAY_BLOCK
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM DISPLAY_BLOCK .
    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
      EXPORTING
        I_CALLBACK_PROGRAM             = SY-REPID
    *   I_CALLBACK_PF_STATUS_SET       = ' '
    *   I_CALLBACK_USER_COMMAND        = ' '
    *   IT_EXCLUDING                   =
              CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
                EXPORTING
                  IS_LAYOUT                        = ILAYOUT
                  IT_FIELDCAT                      = IFIELDCATEKKO
                  I_TABNAME                        = 'IEKKO'
                  IT_EVENTS                        = IEVENTHEAD[]
    *             IT_SORT                          =
    *             I_TEXT                           = ' '
                TABLES
                  T_OUTTAB                         = IEKKO
               EXCEPTIONS
                 PROGRAM_ERROR                    = 1
                 MAXIMUM_OF_APPENDS_REACHED       = 2
                 OTHERS                           = 3
              IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
              ENDIF.
    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
      EXPORTING
        IS_LAYOUT                        = ILAYOUT
        IT_FIELDCAT                      = IFIELDCATEKPO
        I_TABNAME                        = 'IEKPO'
        IT_EVENTS                        = IEVENTITEM
    *   IT_SORT                          =
    *   I_TEXT                           = ' '
      TABLES
        T_OUTTAB                         = IEKPO
    * EXCEPTIONS
    *   PROGRAM_ERROR                    = 1
    *   MAXIMUM_OF_APPENDS_REACHED       = 2
    *   OTHERS                           = 3
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
    * EXPORTING
    *   I_INTERFACE_CHECK             = ' '
    *   IS_PRINT                      =
    *   I_SCREEN_START_COLUMN         = 0
    *   I_SCREEN_START_LINE           = 0
    *   I_SCREEN_END_COLUMN           = 0
    *   I_SCREEN_END_LINE             = 0
    * IMPORTING
    *   E_EXIT_CAUSED_BY_CALLER       =
    *   ES_EXIT_CAUSED_BY_USER        =
    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_BLOCK
    *&      Form  BUILD_FCAT_HEAD
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM BUILD_FCAT_HEAD .
    WFIELDCAT-FIELDNAME = 'EBELN'.
    WFIELDCAT-TABNAME   = 'IEKKO'.
    WFIELDCAT-SELTEXT_L = 'Pur. Doc no'.
    WFIELDCAT-OUTPUTLEN = 15.
    APPEND WFIELDCAT TO IFIELDCATEKKO.
    CLEAR WFIELDCAT.
    WFIELDCAT-FIELDNAME = 'AEDAT'.
    WFIELDCAT-TABNAME   = 'IEKKO'.
    WFIELDCAT-SELTEXT_L = 'Pur. doc date'.
    WFIELDCAT-OUTPUTLEN = 15.
    APPEND WFIELDCAT TO IFIELDCATEKKO.
    CLEAR WFIELDCAT.
    ENDFORM.                    " BUILD_FCAT_HEAD
    *&      Form  BUILD_FCAT_ITEM
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM BUILD_FCAT_ITEM .
    WFIELDCAT-FIELDNAME = 'EBELN'.
    WFIELDCAT-TABNAME   = 'IEKPO'.
    WFIELDCAT-SELTEXT_L = 'Pur. Doc no'.
    WFIELDCAT-OUTPUTLEN = 15.
    APPEND WFIELDCAT TO IFIELDCATEKPO.
    CLEAR WFIELDCAT.
    WFIELDCAT-FIELDNAME = 'EBELP'.
    WFIELDCAT-TABNAME   = 'IEKPO'.
    WFIELDCAT-SELTEXT_L = 'Pur. Doc item'.
    *wfieldcat-do_sum = 'X'.
    WFIELDCAT-OUTPUTLEN = 15.
    APPEND WFIELDCAT TO IFIELDCATEKPO.
    CLEAR WFIELDCAT.
    WFIELDCAT-FIELDNAME = 'MATNR'.
    WFIELDCAT-TABNAME   = 'IEKPO'.
    WFIELDCAT-SELTEXT_L = 'Material no'.
    WFIELDCAT-OUTPUTLEN = 18.
    APPEND WFIELDCAT TO IFIELDCATEKPO.
    CLEAR WFIELDCAT.
    WFIELDCAT-FIELDNAME = 'MENGE'.
    WFIELDCAT-TABNAME   = 'IEKPO'.
    WFIELDCAT-SELTEXT_L = 'P.O. Qty'.
    wfieldcat-do_sum = 'X'.
    *WFIELDCAT-DATATYPE = 'QUAN'.
    WFIELDCAT-OUTPUTLEN = 15.
    APPEND WFIELDCAT TO IFIELDCATEKPO.
    CLEAR WFIELDCAT.
    WFIELDCAT-FIELDNAME = 'MEINS'.
    WFIELDCAT-TABNAME   = 'IEKPO'.
    WFIELDCAT-SELTEXT_L = 'UOM'.
    WFIELDCAT-OUTPUTLEN = 3.
    APPEND WFIELDCAT TO IFIELDCATEKPO.
    CLEAR WFIELDCAT.
    ENDFORM.                    " BUILD_FCAT_ITEM
    *&      Form  BUILD_LAYOUT
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM BUILD_LAYOUT .
    ILAYOUT-COLWIDTH_OPTIMIZE = 'X'.
    ENDFORM.                    " BUILD_LAYOUT
    *&      Form  BUILD_EVENT_TAB
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM BUILD_EVENT_TAB .
    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
       I_LIST_TYPE           = 0
    IMPORTING
       ET_EVENTS             = IEVENTHEAD
    * EXCEPTIONS
    *   LIST_TYPE_WRONG       = 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.
    IEVENTITEM = IEVENTHEAD.
    READ TABLE IEVENTHEAD INTO WEVENT WITH KEY NAME = 'TOP_OF_PAGE'.
    IF SY-SUBRC = 0.
    WEVENT-FORM = 'TOPOFPAGEHEAD'.
    MODIFY IEVENTHEAD FROM WEVENT INDEX SY-TABIX.
    ENDIF.
    READ TABLE IEVENTHEAD INTO WEVENT WITH KEY NAME = 'USER_COMMAND'.
    IF SY-SUBRC = 0.
    WEVENT-FORM = 'USERCOMMAND'.
    MODIFY IEVENTHEAD FROM WEVENT INDEX SY-TABIX.
    ENDIF.
    READ TABLE IEVENTITEM INTO WEVENT WITH KEY NAME = 'TOP_OF_PAGE'.
    IF SY-SUBRC = 0.
    WEVENT-FORM = 'TOPOFPAGEITEM'.
    MODIFY IEVENTITEM FROM WEVENT INDEX SY-TABIX.
    ENDIF.
    ENDFORM.                    " BUILD_EVENT_TAB
    FORM USERCOMMAND USING PUCOMM LIKE SY-UCOMM SELFIELD TYPE SLIS_SELFIELD.
    CASE PUCOMM.
    WHEN '&IC1'.
    WHEN 'OTHERS'.
    ENDCASE.
    ENDFORM.
    FORM TOPOFPAGEHEAD.
    DATA : ILIST TYPE SLIS_T_LISTHEADER,
           WLIST TYPE SLIS_LISTHEADER.
    WLIST-INFO = 'Header data with P.O. no and creating date'.
    WLIST-TYP  = 'H'.
    APPEND WLIST TO ILIST.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        IT_LIST_COMMENTARY       = ILIST
    *   I_LOGO                   =
    *   I_END_OF_LIST_GRID       =
    ENDFORM.
    FORM TOPOFPAGEITEM.
    DATA : ILIST TYPE SLIS_T_LISTHEADER,
           WLIST TYPE SLIS_LISTHEADER.
    WLIST-INFO = 'Item data with P.O.item material no and qty'.
    WLIST-TYP  = 'H'.
    APPEND WLIST TO ILIST.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        IT_LIST_COMMENTARY       = ILIST
    *   I_LOGO                   =
    *   I_END_OF_LIST_GRID       =
    ENDFORM.
    regards
    shiba dutta

  • Tables in Fluid Grid Layouts

    I having trouble with tables in fluid grid layouts.  They work good in a desktop environment but in tablet and phone views, the table gets cut off past the dimensions of the display giving only part of the table.  Any advice on how to make it work like it should?

    Thanks a lot everyone.  Some good links there.  What I need to do, is be able to display tabular data as seen on my current website at www.richardsinkler.net (click on the "tunings" button).  One thing I have noticed, is the page I created using a template I made using fluid grid layout, doesn't give me the div ID in my css file 3 times (in phone, tablet and desktop sections) like other pages I created from the same template.  I had to not display a div on the phone where I had a pic that would bleed out of the right side of the display.  I was able to set the dislplay attribute to "none" and everything was fine.  I guess I could hand code the same functionality into the css file for what I need, to stop the display of the tables on smaller screens.  Or, could I have 2 divs on my desktop page with my tables in one, and a text version of the tables in the other?  Then I could hide the text div on the larger display and use the tables, and hide the tables on the smaller displays and use the text div.  Sound feasable? 
    Also, what is the difference between "width" and "max-width"?  I will look it up, but find that real people, and not technical writers (although they are real people also), can explain it better for the average person like me.

  • A data structure to represent a table in ram ?

    So I've implemented a shoppingCart using a table in the database and it's fine.
    BUT, I'm thinking the table approach isn't that efficient - for example clicking Add to Cart does two things:
    1) insert the row into the shoppingCart table
    2) display the whole shopping cart for that session
    I'm thinking, wouldn't it be nice if I could just store the shoppingCart in a data structure ? I'm sure Coldfusion supports such a strucuture with addRow , removeRow commands - I just can't think of it.
    Do you think this is an efficient approach ?

    a data structure to represent a table in ram ?
    Yes. In fact, you could literally use a structure to represent the shopping-cart in memory. It would begin like this:
    <cfset session.shoppingCart = structnew()>
    I'm sure Coldfusion supports such a strucuture with addRow , removeRow commands - I just can't think of it.
    You would then be thinking of structInsert() and structDelete.
    Do you think this is an efficient approach ?
    Yes. However, I have a different suggestion. What you're doing is a learning exercise. That can only be a good thing.
    If you're serious about setting up shop, which I assume you are, then you should invest in shopping-cart software. They cost little, relative to the benefit you could derive from them. Mary Jo's CFWebstore seems good value for money.

  • Remove table border and grid lines

    all,
    i have and adf faces table on my page and I would like to get rid of the table border and grid lines. i tried using the inline style properties of the table and columns in the table (border-style:none;), and the GridVisible = false property of the columns, but the lines still appear.
    any suggestions?
    paul

    Hi,
    We can design frames in so many ways so check all those one by one
    Check the output options tab in all your window, table & text nodes.there check whether Box & Shading is check or not if it is check remove it.
    sometimes for vertical lines we create seperate windows with low width like 0.01 cm & in its output options check 'box and shading' frame & this window postions are as you required & you can adjust the line in the preview option of box & shading in the output options.
    & in the table node table tab check the select pattren here patterns are again two types with frame & without frame.
    Let me know your exact requirment & your trails if its not working.
    Thanks,
    Phani.
    Edited by: phani kumar on Aug 26, 2008 1:56 PM

  • Show dynamic table in ALV grid

    Hi !
    how do I show a dynamic table in ALV GRID ?
    I used the following commands:
    call method cl_alv_table_create=>create_dynamic_table
      exporting
        it_fieldcatalog = it_fieldcat[]
      importing
        ep_table        = gt_new_table.
      assign gt_new_table->* to <l_table>.
      create data gs_new_line like line of <l_table>.
      assign gs_new_line->* to <l_line>.
    I added records into the table
    Now I got a dynamic table.
    How do I show it in ALV GRID ?
    thanks
      Adi

    Hi,
    Check these links
    Re: Dynamic table
    http://sap.ittoolbox.com/code/d.asp?a=s&d=3038
    http://www.sap4.com/codigo-138.html
    http://www.sapassist.com/code/d.asp?a=s&d=3365
    There is an example in the report BCALV_TABLE_CREATE
    report BCALV_TABLE_CREATE.
    data: ok_code like sy-ucomm,
         g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1',
         grid1  type ref to cl_gui_alv_grid,
         g_custom_container type ref to cl_gui_custom_container.
    data: gt_fieldcat type lvc_t_fcat.
    data: gp_table type ref to data.
    field-symbols: <gt_table> type table.
    parameters: n type i.
    if n > 100.
    message a000(0k) with 'N <= 100'.
    endif.
    perform fieldcat_build.
    call method cl_alv_table_create=>create_dynamic_table
                            exporting it_fieldcatalog = gt_fieldcat
                            importing ep_table = gp_table.
    assign gp_table->* to <gt_table>.
    perform fill_table.
    call screen 100.

  • Showing R/3 Table as a Grid in Web Dynpro

    Hello,
    I am on SAP Netweaver 7.0 SP10. I am developing a Visual Composer screen to show list of products. I have list of products in a Table from backend. But in VC , I dont want to show it as table. Instead of displaying the products in a Table, I want to show products in a 3x4 Grid, something like we see in Amazon or any other web shop.
    Does anybody have ideas on how to achieve this. I appreciate your help.
    Regards,
    Sunita.

    Hi Sunita,
    I think the only way to do this in VC is to use a table, but I think this doesn't fit your requirements. Yesterday I was in St. Leon-Rot and heard something about the new capabilities of Java Webdynpro. I think you should try it with Webdynpro. The pictures are also a problem in VC. An Alternative is BSP there you have the flexibility of HTML for your tables.
    Best Regards,
    Marcel

  • How can I represent a table with JSF ?

    Hi,
    I want to replace my (html) table with a JSF representation..
    I found the tag <h:dataTable>, and this defines <h:column> but there is no <h:row> !!
    There is an attribute rows to represent the number of rows to display, but how can I add these rows ?
    Thank you

    <h:panelGrid columns="2">
    </h:panelGrid>will produce table with 2 columns and if provided, the next 2 columns will appear in the next row and so forth...

  • How to represent Nested table as variable/Object in OCI

    Hi All,
    I'm new to OCI.
    I've following nested table in my database.
    Nested table:
    create type type1 as object (name varchar2(20));
    create type type2 as table of type1;
    create table table1 (col1 varchar2(20), col2 type2) nested table col2 store as table2;
    Can anyone help me to present col2 as C structure/typedef so as to use it with OCIDefineObject?

    You can have a look at Chapter 11 of the OCI Programmer's Guide. Look at the section Collections in it. You can represent the nested table as OCITable *. Further, you can generate structure representation of your object type by using OTT. Please let us know if this answers your question. In case you are not able to proceed please let us know.
    Thanks,
    Sumit

  • Two Internal Tables for ALV Grid

    Hi Gurus,
    I have a little problem here. I have a report to display cost of production. The rows is about 50 displaying amount in dollars (currency fields). I have this in ALV Grid. But my problem is that the last 4 lines of the report are not currency fields like the others, they are quantity fields.
    How can i go about to display this last 4 lines in this ALV Grid. They are from different internal tables off course because of the data type.
    In short. I just want to display these 2 internal tables in an ALV Grid.
    Thanks in Advance.

    Hi,
    u can use ALV Block list to display 2 ALV.
    Reffer to the below code.
    DATA: v_layout TYPE slis_layout_alv.
      DATA: ls_print TYPE slis_print_alv.
      PERFORM build_fieldcatalog.
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
        EXPORTING
          i_callback_program             = sy-repid
    *     I_CALLBACK_PF_STATUS_SET       = ' '
    *     I_CALLBACK_USER_COMMAND        = ' '
    *     IT_EXCLUDING                   =
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
        EXPORTING
          is_layout                        = v_layout
          it_fieldcat                      = it_fcat_nlei
          i_tabname                        = 'IT_NLEI_ALV'
          it_events                        = it_event_nlei
    *     IT_SORT                          =
    *     I_TEXT                           = ' '
        TABLES
          t_outtab                         = it_nlei_alv
        EXCEPTIONS
          program_error                    = 1
          maximum_of_appends_reached       = 2
          OTHERS                           = 3.
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
        EXPORTING
          is_layout                        = v_layout
          it_fieldcat                      = it_fcat_vbrp
          i_tabname                        = 'IT_VBRP_ALV'
          it_events                        = it_event_vbrp
    *     IT_SORT                          =
    *     I_TEXT                           = ' '
        TABLES
          t_outtab                         = it_vbrp_alv
       EXCEPTIONS
         program_error                    = 1
         maximum_of_appends_reached       = 2
         OTHERS                           = 3.
      ls_print-no_print_selinfos  = 'X'.   " Display no selection infos
      ls_print-no_print_listinfos = 'X'.   " Display no listinfos
      ls_print-reserve_lines      = 2.     " Lines reserved for end of page
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
        EXPORTING
    *     I_INTERFACE_CHECK             = ' '
          is_print                      = ls_print
    *     I_SCREEN_START_COLUMN         = 0
    *     I_SCREEN_START_LINE           = 0
    *     I_SCREEN_END_COLUMN           = 0
    *     I_SCREEN_END_LINE             = 0
    *   IMPORTING
    *     E_EXIT_CAUSED_BY_CALLER       =
    *     ES_EXIT_CAUSED_BY_USER        =
       EXCEPTIONS
         program_error                 = 1
         OTHERS                        = 2

  • Nested table in ALV grid

    Hi all
    i have the following types:
    <begin of type1,
    fieldA type i ,
    fieldB type i,
    <end of type1,
    <begin of type2,
    fieldC type i
    fieldA type i,
    <end of type2,
    <begin of type3,
    fieldA type i,
    fieldB type i,
    fieldC type i,
    <end of type3,
    <begin of type4,
    fieldA type i
    fields1 type type1 occurs 4,
    fields2 type type2 occurs 5,
    fields3 type type3 occurs 7,
    fieldD type i,
    <end of type4.
    I would like to set a internal table of type4 in an ALV grid. How do you do this? because i thought it could
    like to hear from you! And off course << Moderator message - Please do not offer points >>
    kind regards
    Anton
    Edited by: Rob Burbank on Nov 9, 2010 2:03 PM

    I have found another solution. I make one internal table with all the fields in it. It is not what i like, but it works...
    thanks all for your replies!
    kind regards
    Anton Pierhagen

  • Table control vs grid control

    What is the difference between table control and ALV grid control?

    Hi,
    1.Table control example
    Follow the steps to update the database table records.
    1.TOP INCLUDE code
    TABLES: EKKO.
    DATA: OK_CODE TYPE SY-UCOMM.
    CONTROLS: TC100 TYPE TABLEVIEW USING SCREEN 100.
    DATA: IT_EKKO LIKE EKKO OCCURS 0 WITH HEADER LINE.
    DATA: CUR TYPE I.
    DATA: I_EKKO2 LIKE EKKO OCCURS 0 WITH HEADER LINE.
    DATA: V_FNAM TYPE I,V_FVAL(10) TYPE N.
    2.Create screen with number(e.g 123) and click on layout tab
    Give the table control name as TC100.
    SELECT THE FIELDS FROM INTERNAL TABLE (IT_EKKO). DRAG THE TEXT FIELDS INTO THE TABLE CONTROL FOR FIELD HEADINGS.
    Create 4 pushbuttons(insert,fetch,delete and exit)
    CLICK ON “Element list” TAB AND ENTER THE “OK_CODE”.
    CLICK ON FLOWLOGIC TAB.
    3.Flowlogic code
    PROCESS BEFORE OUTPUT.
    MODULE STATUS_0100.
    LOOP AT IT_EKKO CURSOR CUR WITH CONTROL TC100.
    ENDLOOP.
    PROCESS AFTER INPUT.
    LOOP AT IT_EKKO.
    MODULE MODIFY_ITAB.
    ENDLOOP.
    MODULE USER_COMMAND_0100.
    4.Double click on MODIFY_ITAB and write as
    module MODIFY_ITAB input.
    APPEND IT_EKKO TO I_EKKO2.
    endmodule. " MODIFY_ITAB INPUT
    5.Activate PAI and double click on it and write the code as
    module USER_COMMAND_0100 input.
    CASE OK_CODE.
    WHEN 'INS'.
    LOOP AT I_EKKO2.
    MODIFY EKKO FROM I_EKKO2.
    ENDLOOP.
    SELECT * FROM EKKO INTO TABLE IT_EKKO.
    IF SY-SUBRC = 0.
    MESSAGE S003(ZCSMSG).
    ENDIF.
    WHEN 'FETCH'.
    SELECT * FROM EKKO INTO TABLE IT_EKKO UP TO 2000 ROWS.
    TC100-LINES = SY-DBCNT.
    WHEN 'EXIT'.
    LEAVE PROGRAM.
    ENDCASE.
    endmodule. " USER_COMMAND_0100 INPUT
    6.Create Transaction code and execute it.
    2.Grid control example
    TABLES VBAK.
    TYPE-POOLS SLIS.
    Data Declaration
    TYPES: BEGIN OF T_VBAK,
          VBELN TYPE VBAK-VBELN,
          ERDAT TYPE VBAK-ERDAT,
          ERNAM TYPE VBAK-ERNAM,
          AUDAT TYPE VBAK-AUDAT,
          VBTYP TYPE VBAK-VBTYP,
          NETWR TYPE VBAK-NETWR,
          VKORG TYPE VBAK-VKORG,
          VKGRP TYPE VBAK-VKGRP,
          LINE_COLOR(4) TYPE C,
          END OF T_VBAK.
    DATA: IT_VBAK TYPE STANDARD TABLE OF T_VBAK INITIAL SIZE 0,
          WA_VBAK TYPE T_VBAK.
    ALV Data Declaration
    DATA: FLDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
          GD_LAYOUT TYPE SLIS_LAYOUT_ALV,
          GD_REPID TYPE SY-REPID.
    START-OF-SELECTION.
    PERFORM DATA_RETRIEVAL.
    PERFORM BLD_FLDCAT.
    PERFORM BLD_LAYOUT.
    PERFORM DISPLAY_ALV_REPORT.
    Build Field Catalog for ALV Report
    FORM BLD_FLDCAT.
    FLDCAT-FIELDNAME = 'VBELN'.
    FLDCAT-SELTEXT_M = 'Sales Document'.
    FLDCAT-COL_POS = 0.
    *FLDCAT-EMPHASIZE = 'C411'.
    FLDCAT-OUTPUTLEN = 20.
    FLDCAT-KEY = 'X'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'ERDAT'.
    FLDCAT-SELTEXT_L = 'Record Date created'.
    FLDCAT-COL_POS = 1.
    FLDCAT-KEY = 'X'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'ERNAM'.
    FLDCAT-SELTEXT_L = 'Cteated Object Person Name'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'AUDAT'.
    FLDCAT-SELTEXT_M = 'Document Date'.
    FLDCAT-COL_POS = 3.
    FLDCAT-EMPHASIZE = 'C110'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'VBTYP'.
    FLDCAT-SELTEXT_L = 'SD Document category'.
    FLDCAT-COL_POS = 4.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'NETWR'.
    FLDCAT-SELTEXT_L = 'Net Value of the SO in Document Currency'.
    FLDCAT-COL_POS = 5.
    FLDCAT-OUTPUTLEN = 60.
    FLDCAT-DO_SUM = 'X'.
    FLDCAT-DATATYPE = 'CURR'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'VKORG'.
    FLDCAT-SELTEXT_L = 'Sales Organization'.
    FLDCAT-COL_POS = 6.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'VKGRP'.
    FLDCAT-SELTEXT_M = 'Sales Group'.
    FLDCAT-COL_POS = 7.
    FLDCAT-EMPHASIZE = 'C801'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    ENDFORM.
    Build Layout for ALV Grid Report
    FORM BLD_LAYOUT.
    GD_LAYOUT-NO_INPUT = 'X'.
    GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
    GD_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.
    GD_LAYOUT-WINDOW_TITLEBAR = 'GRID DISPLAY'.
    GD_LAYOUT-CONFIRMATION_PROMPT = 'X'.  “ This asks the confirmation    
                                       before leaving the screen.
    ENDFORM.
    Display report using ALV grid
    FORM DISPLAY_ALV_REPORT.
    GD_REPID = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM                = GD_REPID
       IS_LAYOUT                         = GD_LAYOUT
       I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
       I_GRID_TITLE                      = 'SALES DOCUMENT HEADER'
       IT_FIELDCAT                       = FLDCAT[]
       I_SAVE                            = 'X'
      TABLES
        T_OUTTAB                          = IT_VBAK
    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.
    Retrieve data from VBAK table and populate itab IT_VBAK
    FORM DATA_RETRIEVAL.
    DATA LD_COLOR(1) TYPE C.
    SELECT VBELN ERDAT ERNAM AUDAT VBTYP NETWR VKORG
    UP TO 20 ROWS
    FROM VBAK
    INTO TABLE IT_VBAK.
    LOOP AT IT_VBAK INTO WA_VBAK.
    LD_COLOR = LD_COLOR + 1.
    IF LD_COLOR = 8.
      LD_COLOR = 1.
    ENDIF.
    CONCATENATE 'C' LD_COLOR '10' INTO WA_VBAK-LINE_COLOR.
    MODIFY IT_VBAK FROM WA_VBAK.
    ENDLOOP.
    ENDFORM.
    FORM TOP_OF_PAGE.
    DATA: T_HEADER TYPE SLIS_T_LISTHEADER,
          W_HEADER TYPE SLIS_LISTHEADER.
    W_HEADER-TYP = 'H'.
    W_HEADER-INFO = 'WELCOME HEADER LIST'.
    APPEND W_HEADER TO T_HEADER.
    W_HEADER-TYP = 'S'.
    W_HEADER-KEY = 'REPORT:'.
    W_HEADER-INFO = SY-REPID.
    APPEND W_HEADER TO T_HEADER.
    W_HEADER-TYP = 'S'.
    W_HEADER-KEY = 'DATE:'.
    CONCATENATE SY-DATUM6(2) ' / ' SY-DATUM4(2) ' / ' SY-DATUM(4) INTO W_HEADER-INFO.
    APPEND W_HEADER TO T_HEADER.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        IT_LIST_COMMENTARY       = T_HEADER.     
    ENDFORM.
    Refer the following link
    http://www.****************
    Reward,if useful.
    Thanks,
    Chandu

  • Updating database table using ALV Grid class CL_ALV_CHANGED_DATA_PROTOCOL

    Hi,
    I am trying to use class CL_ALV_CHANGED_DATA_PROTOCOL to update a database table from an ALV grid.
    I have used program BCALV_EDIT_04 as an example.
    I am able to successfully processed inserted or deleted lines using the attributes
    MT_DELETED_ROWS
    MT_INSERTED_ROWS
    but I also want to process modified lines.
    I was just wondering whether anyone out there has some example code for this.
    I can see that there are the following attributes available
    MT_MOD_CELLS
    MP_MOD_ROWS.
    I would ideally like to use MP_MOD_ROWS rather than  MT_MOD_CELLS but it is not clear to me what type MP_MOD_ROWS is.
    If anyone has any example code for this sort of thing, please let me know.
    Thanks,
    Ruby

    hi Ruby,
    Yes we can use that *data reference variable *.
    It is a variable( something comparable to a pointer ) that points to a int table( table with changed contents )
    which ll be created at run-time based on the data type ot the internal table that we pass to the parameter it_outtab of method set_table_for_first_display ...
    assign er_data_changed->mp_mod_rows->* to a field-symbol and use it...
    Check the below code for example -> method refresh_changed_data
    screen flow logic.
    PROCESS BEFORE OUTPUT.
      MODULE pbo.
    PROCESS AFTER INPUT.
      MODULE pai.
    main program.
    *       CLASS lcl_event_responder DEFINITION                           *
    CLASS lcl_event_responder DEFINITION.
      PUBLIC SECTION.
        DATA  : ls_changed_cell TYPE  lvc_s_modi,
                lv_language     TYPE  spras..
        METHODS refresh_changed_data  FOR EVENT data_changed
                                      OF cl_gui_alv_grid
                                      IMPORTING er_data_changed
                                                e_ucomm.
    ENDCLASS.                    "event_responder DEFINITION
    TYPES tt_makt TYPE STANDARD TABLE OF makt.
    DATA: go_handler         TYPE REF TO lcl_event_responder,
          go_grid            TYPE REF TO cl_gui_alv_grid,
          gt_fieldcat        TYPE lvc_t_fcat,
          gv_language        TYPE spras VALUE 'E',
          gt_outtab          TYPE tt_makt,
          gs_tableline       TYPE LINE OF tt_makt.
    FIELD-SYMBOLS : <changed_rows> TYPE tt_makt.
    CALL SCREEN 100.
    *       MODULE PBO OUTPUT                                             *
    MODULE pbo OUTPUT.
      SET PF-STATUS 'BASIC'.
      PERFORM create_and_init_alv CHANGING gt_outtab[]
                                           gt_fieldcat.
    ENDMODULE.                    "pbo OUTPUT
    *       MODULE PAI INPUT                                              *
    MODULE pai INPUT.
      LEAVE PROGRAM.
    ENDMODULE.                    "pai INPUT
    FORM create_and_init_alv CHANGING pt_outtab LIKE gt_outtab[]
                                      pt_fieldcat TYPE lvc_t_fcat.
      CHECK go_grid IS NOT BOUND.
      CREATE OBJECT go_grid
        EXPORTING
          i_parent = cl_gui_container=>default_screen.
      PERFORM build_display_table.
      PERFORM build_fieldcat CHANGING pt_fieldcat.
      go_grid->set_table_for_first_display( CHANGING  it_fieldcatalog      = pt_fieldcat
                                                      it_outtab            = pt_outtab ).
      go_grid->set_ready_for_input( 1 ).
    * raises the 'data_changed' event when we select another cell/any action after changing the data
      go_grid->register_edit_event( EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_enter ).
      CREATE OBJECT go_handler.
      SET HANDLER go_handler->refresh_changed_data FOR go_grid.
    ENDFORM.                               "CREATE_AND_INIT_ALV
    FORM build_display_table.
      FREE gt_outtab.
      SELECT * FROM makt UP TO 20 ROWS INTO TABLE gt_outtab WHERE spras EQ gv_language.
    ENDFORM.                               "build_display_table
    FORM build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
      DATA ls_fcat TYPE lvc_s_fcat.
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name = 'MAKT'
        CHANGING
          ct_fieldcat      = pt_fieldcat.
      LOOP AT pt_fieldcat INTO ls_fcat.
        ls_fcat-edit       = abap_true.
        MODIFY pt_fieldcat FROM ls_fcat.
      ENDLOOP.
    ENDFORM.                               "build_fieldcat
    *       CLASS event_responder IMPLEMENTATION                          *
    CLASS lcl_event_responder IMPLEMENTATION.
      METHOD refresh_changed_data.
        ASSIGN er_data_changed->mp_mod_rows->* TO <changed_rows>.
        LOOP AT <changed_rows> INTO gs_tableline.
          BREAK-POINT.
        ENDLOOP.
      ENDMETHOD.                    "click
    ENDCLASS.                    "event_responder IMPLEMENTATION
    Cheers,
    Jose.

  • Modifying database table through ALV-Grid

    Hi all.
    I need to modify a database table (ZNG_SO_HEAD) by entering data in ALV-Grid, which displays its internal table (exact  copy of ZNG_SO_HEAD), and clicking the button ('CHANGE') on the ALV-toolbar. The ALV is already editable, the button already exists. Here is the code. After changing data in ALV and clicking 'CHANGE' on the toolbar the database table ZNG_SO_HEAD remains unchangeable, but i need to change data in it somehow.
    Thanks all.
    REPORT  zng_alv_tc_edit_simp.
    *-- GLOBAL DATA DECLARATIONS FOR ALV
    DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
    DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
    DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.
    DATA gt_fieldcat TYPE lvc_t_fcat.
    DATA gs_layout TYPE lvc_s_layo.
    TABLES: zng_so_head, zng_cust, zng_vendors.
    *-- STRUCTURE OF INTERNAL TABLE
    TYPES: BEGIN OF in_tab,
            mandt TYPE zng_so_head-mandt,
            so_num TYPE zng_so_head-so_num,          "type numc
            vend_num TYPE zng_so_head-vend_num,      "type numc
            cust_num TYPE zng_so_head-cust_num,      "type numc
            so_date TYPE zng_so_head-so_date,        "type dats
           END OF in_tab.
    *-- INTERNAL TABLE HOLDING LIST DATA
    DATA res_tab TYPE TABLE OF in_tab WITH HEADER LINE.
    *DATA wa_res_tab LIKE LINE OF res_tab.
    *-- FILLING IN INTERNAL TABLE
    SELECT h~mandt h~so_num h~vend_num h~cust_num h~so_date
    INTO TABLE res_tab FROM zng_so_head AS h.
    *       CLASS lcl_event_handler DEFINITION
    CLASS lcl_event_handler DEFINITION.
      PUBLIC SECTION.
        METHODS:
    *   to add new functional buttons to the alv toolbar
        handle_toolbar
          FOR EVENT toolbar OF cl_gui_alv_grid
            IMPORTING e_object
                      e_interactive,
    *   to implement user commands
        handle_user_command
          FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING e_ucomm.
    ENDCLASS.             "lcl_event_handler DEFINITION
    *       CLASS lcl_event_handler IMPLEMENTATION
    CLASS lcl_event_handler IMPLEMENTATION.
      METHOD handle_toolbar.
        DATA: ls_toolbar TYPE stb_button.
        MOVE 3 TO ls_toolbar-butn_type.
        CLEAR ls_toolbar.
        MOVE 'CHANGE' TO ls_toolbar-function.
        MOVE icon_change TO ls_toolbar-icon.
        MOVE 'change' TO ls_toolbar-quickinfo.
        MOVE 'change' TO ls_toolbar-text.
        APPEND ls_toolbar TO e_object->mt_toolbar.
      ENDMETHOD.                    "handle_toolbar>
      METHOD handle_user_command.
        DATA:l_valid TYPE c.
        CASE e_ucomm.
          WHEN 'CHANGE'.
            CALL METHOD gr_alvgrid->check_changed_data
              IMPORTING
                e_valid = l_valid.
            IF l_valid = 'X'.
              MODIFY zng_so_head FROM res_tab.
            ENDIF.
        ENDCASE.
      ENDMETHOD. "handle_user_command
    ENDCLASS.                    "lcl_event_handler IMPLEMENTATION
    DATA object_ref TYPE REF TO lcl_event_handler.
    FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
    >>>>>>done correctly>>>>>>>>>
    FORM display_alv.
    >>>>>>done correctly>>>>>>>>>
    START-OF-SELECTION.
      CALL SCREEN 100.
    *  MODULE STATUS_0100 OUTPUT
    MODULE display_alv OUTPUT.
      SET PF-STATUS 'SCREEN_100'.
      PERFORM display_alv.
      CREATE OBJECT object_ref.
      SET HANDLER object_ref->handle_toolbar FOR gr_alvgrid.
      SET HANDLER object_ref->handle_user_command FOR gr_alvgrid.
    ENDMODULE.                    "display_alv OUTPUT
    *  MODULE USER_COMMAND_0100 INPUT
    MODULE user_command_0100 INPUT.
    IF sy-ucomm = 'BACK' OR
         sy-ucomm = 'EXIT' OR
         sy-ucomm = 'CANCEL'.
        LEAVE PROGRAM.
      ELSE.
        CALL METHOD object_ref->handle_toolbar.
        CALL METHOD object_ref->handle_user_command.
      ENDIF.
    ENDMODULE.

    Hello Nikolai,
    I have written a sample code taking care of all the requirements(button in the toolbar and changes saved in database).I have used SPFLI table and the internal table i_spfli.This code works and the change is also made in the database table.
    REPORT  SAMPLE.
    *-- GLOBAL DATA DECLARATIONS FOR ALV
    DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
    DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
    DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.
    DATA gt_fieldcat TYPE lvc_t_fcat.
    DATA gs_layout TYPE lvc_s_layo.
    Data:i_spfli type table of spfli.
          CLASS lcl_event_handler DEFINITION
    CLASS lcl_event_handler DEFINITION.
      PUBLIC SECTION.
        DATA:l_valid TYPE c.
         DATA: ls_toolbar TYPE stb_button.
        METHODS:
      to add new functional buttons to the alv toolbar
        handle_toolbar
          FOR EVENT toolbar OF cl_gui_alv_grid
            IMPORTING e_object
                      e_interactive,
      to implement user commands
        handle_user_command
          FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING e_ucomm.
    ENDCLASS.             "lcl_event_handler DEFINITION
          CLASS lcl_event_handler IMPLEMENTATION
    CLASS lcl_event_handler IMPLEMENTATION.
      METHOD handle_toolbar.
      CLEAR ls_toolbar.
        MOVE 0 TO ls_toolbar-butn_type.
        MOVE 'CHANGE' TO ls_toolbar-function.
        MOVE 'ICON_CHANGE' TO ls_toolbar-icon.
        MOVE 'change' TO ls_toolbar-quickinfo.
        MOVE 'change' TO ls_toolbar-text.
        APPEND ls_toolbar TO e_object->mt_toolbar.
      ENDMETHOD.                    "handle_toolbar>
      METHOD handle_user_command.
        CASE e_ucomm.
          WHEN 'CHANGE'.
            CALL METHOD gr_alvgrid->check_changed_data
              IMPORTING
                e_valid = l_valid.
            IF l_valid = 'X'.
              MODIFY spfli FROM table i_spfli.
            ENDIF.
        ENDCASE.
      ENDMETHOD. "handle_user_command
    ENDCLASS.                    "lcl_event_handler IMPLEMENTATION
    START-OF-SELECTION.
    DATA object_ref TYPE REF TO lcl_event_handler.
    select * from spfli into table i_spfli.
    Call screen 100.
    MODULE STATUS_0100 OUTPUT
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS 'SCREEN_100'.
      PERFORM display_alv.
    ENDMODULE.                    "display_alv OUTPUT
    MODULE USER_COMMAND_0100 INPUT
    MODULE user_command_0100 INPUT.
    IF sy-ucomm = 'BACK' OR
         sy-ucomm = 'EXIT' OR
         sy-ucomm = 'CANCEL'.
        LEAVE PROGRAM.
      ENDIF.
    ENDMODULE.
    *& Form display_alv
    FORM display_alv.
    *IF gr_alvgrid IS INITIAL.
    CREATE OBJECT gr_ccontainer
    EXPORTING container_name = gc_custom_control_name.
    CREATE OBJECT gr_alvgrid
    EXPORTING i_parent = gr_ccontainer.
    PERFORM prepare_field_catalog CHANGING gt_fieldcat.
    CREATE OBJECT object_ref.
      SET HANDLER object_ref->handle_toolbar FOR gr_alvgrid.
      SET HANDLER object_ref->handle_user_command FOR gr_alvgrid.
    CALL METHOD gr_alvgrid->set_table_for_first_display
    EXPORTING
    is_layout = gs_layout
    CHANGING
    it_outtab = i_spfli[]
    it_fieldcatalog = gt_fieldcat.
    ENDFORM. "display_alv
    *& Form prepare_field_catalog
    FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
    DATA ls_fcat TYPE lvc_s_fcat.
    ls_fcat-fieldname = 'CARRID'.
    ls_fcat-ref_table = 'SPFLI'.
    ls_fcat-edit = 'X'.
    APPEND ls_fcat TO pt_fieldcat.
    CLEAR ls_fcat.
    ls_fcat-fieldname = 'CONNID'.
    ls_fcat-ref_table = 'SPFLI'.
    ls_fcat-edit = 'X'.
    APPEND ls_fcat TO pt_fieldcat.
    CLEAR ls_fcat.
    ls_fcat-fieldname = 'DEPTIME'.
    ls_fcat-ref_table = 'SPFLI'.
    ls_fcat-edit = 'X'.
    APPEND ls_fcat TO pt_fieldcat.
    CLEAR ls_fcat.
    ls_fcat-fieldname = 'ARRTIME'.
    ls_fcat-ref_table = 'SPFLI'.
    ls_fcat-edit = 'X'.
    APPEND ls_fcat TO pt_fieldcat.
    CLEAR ls_fcat.
    endform.
    Hope this helps.
    Regards,
    Beejal

Maybe you are looking for