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

Similar Messages

  • 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

  • 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.

  • 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.

  • Change the data in fieldcat and update the database table in alv oops

    Hi,
    my requirement is i have displayed a fieldcat in change mode and when i change the data and click on save it has to be updated the database table..
    this has to be done using alv oops...

    Hi,
    This code will reflect all the changes into the internal table that is being displayed.
    * to reflect the data changed into internal table
          DATA : ref_grid TYPE REF TO cl_gui_alv_grid. "new
          IF ref_grid IS INITIAL.
            CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
              IMPORTING
                e_grid = ref_grid.
          ENDIF.
          IF NOT ref_grid IS INITIAL.
            CALL METHOD ref_grid->check_changed_data.
          ENDIF.
    Now after this code is executed the internal table is modified as per the changes done in alv output.
    Now you can use this internal table to update the database table.
    Hope this helps you.
    Regards,
    Tarun

  • 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

  • Modifying single cell in ALV Grid via OO

    Hi All,
    Got a problem I hope someone can assist me with.  I have a custom program generating an editable ALV grid.  The users want to update a single cell in a row with value from a custom drop down.  I've got the dropdown working, but I can't work out how to get the value back into the field.  My attempts result in a 'GETWA_NOT_ASSIGNED' short dump.
    I'm using the CL_GUI_ALV_GRID->get_selected_cells_id method to get the reference for the field to be modified, but I don't know where to go from here. 
    Any thoughts would be greatly appreciated.  Btw, my knowledge of OO is passable, but not great, so any explanations of what the code is doing in a proposed solution would be greatly appreciated.
    points will be rewarded.
    Cheers,
    Stephen

    Hello Stephen
    Since your dropdown list restrict the already allowed values there should be no special need to validate the selected values.
    Simply "grab" the data from the editable ALV into your internal itab in the ABAP report.
    I have copied sample report BCALV_EDIT_07 into ZUS_SDN_BCALV_EDIT_07 and modified the report to show how to retrieve the dropdown values (which is simple). Please note that I added the GUI-function 'SAVE' to the GUI-status MAIN100.
    *       MODULE PAI INPUT                                              *
    MODULE pai INPUT.
      save_ok = ok_code.
      CLEAR ok_code.
      "$TMP
      g_grid->check_changed_data( ). " retrieve changes from editable grid
      CASE save_ok.
        WHEN 'EXIT'.
          PERFORM exit_program.
        "$TMP
        WHEN 'SAVE'.
          PERFORM save_data.
        WHEN OTHERS.
    *     do nothing
      ENDCASE.
    ENDMODULE.                    "pai INPUT
    *&      Form  SAVE_DATA
    *       text
    FORM save_data.  "$TMP
    * define local data
      data: ls_fcat   type lvc_s_fcat,
            lt_fcat   type lvc_t_fcat.
      lt_fcat = gt_fieldcat.
      ls_fcat-edit = ' '.
      modify lt_fcat from ls_fcat
          TRANSPORTING edit
        where ( edit = 'X' ).  " display ALV should be not editable
      " Simulate saving of data
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
    *     I_INTERFACE_CHECK                 = ' '
    *     I_BYPASSING_BUFFER                =
    *     I_BUFFER_ACTIVE                   =
    *     I_CALLBACK_PROGRAM                = ' '
    *     I_CALLBACK_PF_STATUS_SET          = ' '
    *     I_CALLBACK_USER_COMMAND           = ' '
    *     I_CALLBACK_TOP_OF_PAGE            = ' '
    *     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
    *     I_CALLBACK_HTML_END_OF_LIST       = ' '
    *     I_STRUCTURE_NAME                  =
    *     I_BACKGROUND_ID                   = ' '
          I_GRID_TITLE                      = 'Display modified list data'
    *     I_GRID_SETTINGS                   =
    *     IS_LAYOUT_LVC                     =
          IT_FIELDCAT_LVC                   = lt_fcat
    *     IT_EXCLUDING                      =
    *     IT_SPECIAL_GROUPS_LVC             =
    *     IT_SORT_LVC                       =
    *     IT_FILTER_LVC                     =
    *     IT_HYPERLINK                      =
    *     IS_SEL_HIDE                       =
    *     I_DEFAULT                         = 'X'
    *     I_SAVE                            = ' '
    *     IS_VARIANT                        =
    *     IT_EVENTS                         =
    *     IT_EVENT_EXIT                     =
    *     IS_PRINT_LVC                      =
    *     IS_REPREP_ID_LVC                  =
          I_SCREEN_START_COLUMN             = 5
          I_SCREEN_START_LINE               = 5
          I_SCREEN_END_COLUMN               = 120
          I_SCREEN_END_LINE                 = 20
    *     I_HTML_HEIGHT_TOP                 =
    *     I_HTML_HEIGHT_END                 =
    *     IT_EXCEPT_QINFO_LVC               =
    *     IR_SALV_FULLSCREEN_ADAPTER        =
        TABLES
          t_outtab                          = gt_outtab
        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.                    "SAVE_DATA
    And here is the entire coding: In order to find the modified parts of the coding simply search for $TMP.
    PROGRAM zus_sdn_bcalv_edit_07.
    * Purpose:
    * ~~~~~~~~
    * This example shows how to define dropdown listboxes for
    * particular cells of your output table.
    * To check program behavior
    * ~~~~~~~~~~~~~~~~~~~~~~~~~
    * Conceive that customers are only allowed to smoke in the
    * first class. For this reason, if the customer is a smoker
    * only the first class (F) can be chosen in column 'CLASS',
    * otherwise all classes.
    * Essential steps (search for '§')
    * ~~~~~~~~~~~~~~~
    * 1.Define an extra field in your output table
    * 2.Define a dropdown table and pass it to ALV.
    * 3.Set your dropdown field editable and assign the fieldname of the
    *   corresponding additional field to DRDN_FIELD of the fieldcatalog.
    * 4.Set the handle of your additional field of your output
    *   table according to the listbox that shall be displayed.
    DATA: ok_code LIKE sy-ucomm,
          save_ok LIKE sy-ucomm,
          g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
          g_grid  TYPE REF TO cl_gui_alv_grid,
          g_custom_container TYPE REF TO cl_gui_custom_container,
          gt_fieldcat TYPE lvc_t_fcat,
          gs_layout TYPE lvc_s_layo,
          g_max TYPE i VALUE 100.
    *§1.Define an extra field in your output table
    *   for each column where you want to use drop down listboxes.
    *   (One additional field refers to cells of one column).
    DATA: BEGIN OF gt_outtab OCCURS 0.
            INCLUDE STRUCTURE sbook.
    DATA: drop_down_handle TYPE int4.
    DATA: END OF gt_outtab.
    *       MAIN                                                          *
    END-OF-SELECTION.
      CALL SCREEN 100.
    *       MODULE PBO OUTPUT                                             *
    MODULE pbo OUTPUT.
      SET PF-STATUS 'MAIN100'.
      SET TITLEBAR 'MAIN100'.
      IF g_custom_container IS INITIAL.
        PERFORM create_and_init_alv CHANGING gt_outtab[]
                                             gt_fieldcat.
      ENDIF.
    ENDMODULE.                    "pbo OUTPUT
    *       MODULE PAI INPUT                                              *
    MODULE pai INPUT.
      save_ok = ok_code.
      CLEAR ok_code.
      "$TMP
      g_grid->check_changed_data( ). " retrieve changes from editable grid
      CASE save_ok.
        WHEN 'EXIT'.
          PERFORM exit_program.
        "$TMP
        WHEN 'SAVE'.
          PERFORM save_data.
        WHEN OTHERS.
    *     do nothing
      ENDCASE.
    ENDMODULE.                    "pai INPUT
    *       FORM EXIT_PROGRAM                                             *
    FORM exit_program.
      LEAVE PROGRAM.
    ENDFORM.                    "exit_program
    *&      Form  SAVE_DATA
    *       text
    FORM save_data.  "$TMP
    * define local data
      data: ls_fcat   type lvc_s_fcat,
            lt_fcat   type lvc_t_fcat.
      lt_fcat = gt_fieldcat.
      ls_fcat-edit = ' '.
      modify lt_fcat from ls_fcat
          TRANSPORTING edit
        where ( edit = 'X' ).  " display ALV should be not editable
      " Simulate saving of data
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
    *     I_INTERFACE_CHECK                 = ' '
    *     I_BYPASSING_BUFFER                =
    *     I_BUFFER_ACTIVE                   =
    *     I_CALLBACK_PROGRAM                = ' '
    *     I_CALLBACK_PF_STATUS_SET          = ' '
    *     I_CALLBACK_USER_COMMAND           = ' '
    *     I_CALLBACK_TOP_OF_PAGE            = ' '
    *     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
    *     I_CALLBACK_HTML_END_OF_LIST       = ' '
    *     I_STRUCTURE_NAME                  =
    *     I_BACKGROUND_ID                   = ' '
          I_GRID_TITLE                      = 'Display modified list data'
    *     I_GRID_SETTINGS                   =
    *     IS_LAYOUT_LVC                     =
          IT_FIELDCAT_LVC                   = lt_fcat
    *     IT_EXCLUDING                      =
    *     IT_SPECIAL_GROUPS_LVC             =
    *     IT_SORT_LVC                       =
    *     IT_FILTER_LVC                     =
    *     IT_HYPERLINK                      =
    *     IS_SEL_HIDE                       =
    *     I_DEFAULT                         = 'X'
    *     I_SAVE                            = ' '
    *     IS_VARIANT                        =
    *     IT_EVENTS                         =
    *     IT_EVENT_EXIT                     =
    *     IS_PRINT_LVC                      =
    *     IS_REPREP_ID_LVC                  =
          I_SCREEN_START_COLUMN             = 5
          I_SCREEN_START_LINE               = 5
          I_SCREEN_END_COLUMN               = 120
          I_SCREEN_END_LINE                 = 20
    *     I_HTML_HEIGHT_TOP                 =
    *     I_HTML_HEIGHT_END                 =
    *     IT_EXCEPT_QINFO_LVC               =
    *     IR_SALV_FULLSCREEN_ADAPTER        =
        TABLES
          t_outtab                          = gt_outtab
        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.                    "SAVE_DATA
    *&      Form  BUILD_FIELDCAT
    *       text
    *      <--P_GT_FIELDCAT  text
    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 = 'SBOOK'
        CHANGING
          ct_fieldcat      = pt_fieldcat.
      LOOP AT pt_fieldcat INTO ls_fcat.
    * Exchange smoker field with invoice field - just to
    * make the dependance between SMOKER and CLASS more transparent
    * (Smoking is only allowed in the first class).
        IF ls_fcat-fieldname EQ 'SMOKER'.
          ls_fcat-col_pos = 11.
          ls_fcat-outputlen = 10.
          MODIFY pt_fieldcat FROM ls_fcat.
        ELSEIF ls_fcat-fieldname EQ 'INVOICE'.
          ls_fcat-col_pos = 7.
          MODIFY pt_fieldcat FROM ls_fcat.
        ELSEIF    ls_fcat-fieldname EQ 'CLASS'.
    *§3.Set your dropdown field editable and assign the fieldname of the
    *   corresponding additional field to DRDN_FIELD of the fieldcatalog.
          ls_fcat-edit = 'X'.
          ls_fcat-drdn_field = 'DROP_DOWN_HANDLE'.
          ls_fcat-outputlen = 5.
    * Field 'checktable' is set to avoid shortdumps that are caused
    * by inconsistend data in check tables. You may comment this out
    * when the test data of the flight model is consistent in your system.
          ls_fcat-checktable = '!'.        "do not check foreign keys
          MODIFY pt_fieldcat FROM ls_fcat.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    "build_fieldcat
    *&      Form  CREATE_AND_INIT_ALV
    *       text
    *      <--P_GT_OUTTAB  text
    *      <--P_GT_FIELDCAT  text
    *      <--P_GS_LAYOUT  text
    FORM create_and_init_alv CHANGING pt_outtab TYPE STANDARD TABLE
                                      pt_fieldcat TYPE lvc_t_fcat.
      DATA: lt_exclude TYPE ui_functions.
      CREATE OBJECT g_custom_container
        EXPORTING
          container_name = g_container.
      CREATE OBJECT g_grid
        EXPORTING
          i_parent = g_custom_container.
      PERFORM build_fieldcat CHANGING pt_fieldcat.
    * Optionally restrict generic functions to 'change only'.
    *   (The user shall not be able to add new lines).
      PERFORM exclude_tb_functions CHANGING lt_exclude.
      PERFORM set_drdn_table.
      PERFORM build_data CHANGING pt_outtab.
      CALL METHOD g_grid->set_table_for_first_display
        EXPORTING
          it_toolbar_excluding = lt_exclude
        CHANGING
          it_fieldcatalog      = pt_fieldcat
          it_outtab            = pt_outtab[].
    * Set editable cells to ready for input initially
      CALL METHOD g_grid->set_ready_for_input
        EXPORTING
          i_ready_for_input = 1.
    ENDFORM.                               "CREATE_AND_INIT_ALV
    *&      Form  EXCLUDE_TB_FUNCTIONS
    *       text
    *      <--P_LT_EXCLUDE  text
    FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions.
    * Only allow to change data not to create new entries (exclude
    * generic functions).
      DATA ls_exclude TYPE ui_func.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
      APPEND ls_exclude TO pt_exclude.
    ENDFORM.                               " EXCLUDE_TB_FUNCTIONS
    *&      Form  set_drdn_table
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM set_drdn_table.
    *§2.Define a dropdown table and pass it to ALV.
    *   One listbox is referenced by a handle, e.g., '1'.
    *   For each entry that shall appear in this listbox
    *   you have to append a line to the dropdown table
    *   with handle '1'.
    *   This handle can be assigned to several columns
    *   of the output table using the field catalog.
      DATA: lt_dropdown TYPE lvc_t_drop,
            ls_dropdown TYPE lvc_s_drop.
      ls_dropdown-handle = '1'.
      ls_dropdown-value = 'F'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '2'.
      ls_dropdown-value = 'F'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '2'.
      ls_dropdown-value = 'C'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '2'.
      ls_dropdown-value = 'Y'.
      APPEND ls_dropdown TO lt_dropdown.
      CALL METHOD g_grid->set_drop_down_table
        EXPORTING
          it_drop_down = lt_dropdown.
    ENDFORM.                               " set_drdn_table
    *&      Form  build_data
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM build_data CHANGING pt_outtab TYPE STANDARD TABLE.
      DATA: lt_sbook TYPE TABLE OF sbook,
            ls_sbook TYPE sbook,
            l_index TYPE i,
            ls_outtab LIKE LINE OF gt_outtab.
      SELECT * FROM sbook INTO TABLE lt_sbook UP TO g_max ROWS."#EC CI_NOWHERE
      IF sy-subrc NE 0.
        PERFORM generate_entries CHANGING lt_sbook.
      ENDIF.
    *§4.Set the handle of your additional field of your output
    *   table according to the listbox that shall be displayed.
      LOOP AT lt_sbook INTO ls_sbook.
        l_index = sy-tabix.
        MOVE-CORRESPONDING ls_sbook TO ls_outtab.
        CLEAR ls_outtab-class.
    * Alternate between smoker and non smoker to make
    * it more obvious what this example is about
        l_index = l_index MOD 2.
        IF l_index EQ 1.
          ls_outtab-smoker = 'X'.
        ELSE.
          ls_outtab-smoker = ' '.
        ENDIF.
        IF ls_outtab-smoker EQ 'X'.
          ls_outtab-drop_down_handle = '1'.
        ELSE.
          ls_outtab-drop_down_handle = '2'.
        ENDIF.
        APPEND ls_outtab TO pt_outtab.
      ENDLOOP.
    ENDFORM.                               " build_data
    *&      Form  generate_entries
    *       text
    *      <--P_LT_SLFIGHT  text
    FORM generate_entries CHANGING pt_sbook TYPE STANDARD TABLE.
      DATA: ls_sbook TYPE sbook,
            l_month(2) TYPE c,
            l_day(2) TYPE c,
            l_date(8) TYPE c,
      l_prebookid TYPE i.
      ls_sbook-carrid = 'LH'.
      ls_sbook-connid = '0400'.
      ls_sbook-forcurkey = 'DEM'.
      ls_sbook-loccurkey = 'USD'.
      ls_sbook-custtype = 'B'.
      DO 110 TIMES.
        l_prebookid = sy-index.
        ls_sbook-forcuram = sy-index * 10.
        ls_sbook-loccuram = ls_sbook-loccuram * 2.
        ls_sbook-customid = sy-index.
        ls_sbook-counter = 18.
        ls_sbook-agencynum = 11.
        l_month = sy-index / 10 + 1.
        DO 2 TIMES.
          l_day = 3 + l_month + sy-index * 2.
          l_date+0(4) = '2000'.
          l_date+4(2) = l_month.
          l_date+6(2) = l_day.
          ls_sbook-fldate = l_date.
          SUBTRACT 3 FROM l_day.
          ls_sbook-order_date+0(6) = l_date+0(6).
          ls_sbook-order_date+6(2) = l_day.
          ls_sbook-bookid = l_prebookid * 2 + sy-index.
          IF sy-index EQ 1.
            ls_sbook-smoker = 'X'.
          ELSE.
            ls_sbook-smoker = space.
          ENDIF.
          ls_sbook-luggweight = l_prebookid * 10.
          IF ls_sbook-luggweight GE 1000.
            ls_sbook-wunit = 'G'.
            ls_sbook-class = 'C'.
          ELSE.
            ls_sbook-wunit = 'KG'.
            ls_sbook-class = 'Y'.
          ENDIF.
          IF ls_sbook-bookid > 40 AND ls_sbook-wunit EQ 'KG'.
            ls_sbook-invoice = 'X'.
          ENDIF.
          IF ls_sbook-bookid EQ 2.
            ls_sbook-cancelled = 'X'.
            ls_sbook-class = 'F'.
          ENDIF.
          APPEND ls_sbook TO pt_sbook.
        ENDDO.
      ENDDO.
    ENDFORM.                               " generate_entries
    Regards
      Uwe

  • Modify database table from internal table

    Hi All,
    I need to update database table from internal table which is having around 30000 records.
    I am using MODIFY tabname FROM TABLE int_tabname...
    Using this statement, I can modify the databse records very well. But user has some additional requirement.
    He wants that the table should be modified from the internal table and after modification we should have the erroneous records to be displayed if any.
    e.g. if 1500 records out of 30000 are erroneous then only 28500 records should be updated and 1500 records should be displayed as erroneous records so that the user can correct them and use them again for executing the program.
    Is there any FM which imports the database table name and internal table, modifies the database and exports an internal tanle with erroneous records?
    Any help will be appriciated,
    Regards,
    Neha

    Hi
    modifying datbase table useing internal table
    <b>advises</b> before updating this datbase table plz lock that table to avoid incosistency
    write the logic for modifying
    Modify the database table as per new dunning procedure
      MODIFY fkkvkp FROM TABLE lt_fkkvkp   .
    and finally unlock the table
    <b>example</b>
    *To lock table for further operations
      constants: lc_tabname TYPE  rstable-tabname  VALUE 'FKKVKP'  . "FKKVKP
      CALL FUNCTION 'ENQUEUE_E_TABLE'
        EXPORTING
          tabname        = lc_tabname
        EXCEPTIONS
          foreign_lock   = 1
          system_failure = 2
          OTHERS         = 3.
      IF sy-subrc EQ 0.
      To fetch all the contract accounts for customers of the segment
      Households/SME.
        PERFORM fetch_contract_accounts using lc_tabname .
      ENDIF.                    " IF sy-subrc EQ 0.
    *wrote the logic
    Modify the database table as per new dunning procedure from internal table
      MODIFY fkkvkp FROM TABLE lt_fkkvkp   .
    *unlock the tbale
      CALL FUNCTION 'DEQUEUE_E_TABLE'
       EXPORTING
         TABNAME   =  uc_tabname .
    <b>Reward if usefull</b>

  • 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

  • How to modify DataBase Table with an internal Table

    Hi, Friends.
    I am coping Data from a Database table to an internal table after modifying data in the internal table I want to modify the db table according to the modification in the internal table. can some one help me out in this way, i am doing this modification in Table Control in Screen programing.
    My Code is as follow.
    MODULE zfsl_stinf_tc_init OUTPUT.
      IF tc_copy IS INITIAL.
        SELECT * INTO CORRESPONDING FIELDS OF TABLE it_zfsl_stinf FROM zfsl_stinf.
        tc_copy = 'X'.
        REFRESH CONTROL 'TC_FOR_ZFSL_STINF' FROM SCREEN '0001'.
      ENDIF.
    ENDMODULE.                 " zfsl_stinf_init  OUTPUT
    *&      Module  zfsl_stinf_tc_move  OUTPUT
          text
    MODULE zfsl_stinf_tc_move OUTPUT.
      MOVE-CORRESPONDING wa_it_zfsl_stinf TO zfsl_stinf.
    ENDMODULE.                 " zfsl_stinf_tc_move  OUTPUT
    *&      Module  STATUS_0001  OUTPUT
          text
    MODULE status_0001 OUTPUT.
      SET PF-STATUS 'ZFSL_SCREEN_1ONLY'.
    SET TITLEBAR 'xxx'.
    ENDMODULE.                 " STATUS_0001  OUTPUT
    *&      Module  zfsl_stinf_tc_modify  INPUT
          text
    MODULE zfsl_stinf_tc_modify INPUT.
      MOVE-CORRESPONDING zfsl_stinf TO wa_it_zfsl_stinf.
      MODIFY it_zfsl_stinf FROM wa_it_zfsl_stinf INDEX tc_for_zfsl_stinf-current_line.
    _*"" here i have the modified internal table  " it_zfsl_stinf "*_
    ENDMODULE.                 " zfsl_stinf_tc_modify  INPUT
    Kind regards,
    Faisal

    Hi
    Here you are modifying your dbtable in module pool programming
    so  better to use work area to modify the database table
    example:
    data: itab type table of zfsl_stinf .
    data: wa_itab type itab.
    select single * from zfsl_stinf INTO itab WHERE <condition>
    (pass your values to wa_itab.)
    modify zfsl_stinf from values of wa_itab.
    Regards
    Srinivasu

  • Modify Database table

    Hi,
    I need to modify a single field in a custom database table for more than 1 record.
    I need to update from the values in the internal table which has only that single field.
    how to acheive this ..Pls help
    Thanks

    hi delcare work area wa and use
      MODIFY  dbtab      FROM wa statement.

  • Subtotals in dynamic internal table using alv grid

    hi experts i have created one dynamic table.  The requirement is to display the subtotals in the output using reuse_alv_grid.
    Dynamic itab (field-symbols) and ALV event BEFORE_LINE_OUTPUT
    the above is the thread related and could any one please provide the sample code for this task.
    can any one post the solution for that.
    rewards points will be awarded.
    khazi

    * ASSINING STRUCTURE FOR FILD CATLOGS
    DATA: DYN_TABLE    TYPE REF TO DATA,
          DYN_LINE     TYPE REF TO DATA,
          LS_FIELDCAT TYPE LVC_S_FCAT,
          LT_FIELDCAT TYPE LVC_T_FCAT.
      LOOP AT LT_DMTAB INTO LS_DMTAB.
        CLEAR LS_FIELDCAT.
        LS_FIELDCAT-FIELDNAME = LS_DMTAB-SDATE .
        LS_FIELDCAT-DATATYPE  = 'DEC'.
        LS_FIELDCAT-INTTYPE   = 'P'.
        LS_FIELDCAT-INTLEN    = '16' .
        LS_FIELDCAT-DECIMALS  = '03'.
        LS_FIELDCAT-JUST      = 'C'.
        APPEND LS_FIELDCAT TO LT_FIELDCAT.
      ENDLOOP.
    *& For grouping the table rows for Under Line
      LS_FIELDCAT-FIELDNAME = 'ULFIELD' .
      LS_FIELDCAT-DATATYPE  = 'INT'.
      LS_FIELDCAT-INTTYPE   = 'P'.
      LS_FIELDCAT-INTLEN    = '2' .
      LS_FIELDCAT-DECIMALS  = ''.
      APPEND LS_FIELDCAT TO LT_FIELDCAT.
      "* Create dynamic internal table and assign to Field-Symbol
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG = LT_FIELDCAT
        IMPORTING
          EP_TABLE        = DYN_TABLE.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      ASSIGN DYN_TABLE->* TO <LT_AREA_F>.
      "* Create dynamic work area and assign to Field Symbol
      CREATE DATA DYN_LINE LIKE LINE OF <LT_AREA_F>.
      ASSIGN DYN_LINE->* TO <LS_AREA_F>.
    You check in Field cat level you will get  Check Sub total field will exist
    Thanks and regards
    Jogu

  • Table Maintenance via ALV GRID

    Hi Experts,
    I have a requirement to do table maintenance for multiple tables using ALV GRID, with options to change, delete, add records and upload multiple records via copy/paste functionality.
    Thanks.

    Your welcome.
    Rob

  • For all users having probs with OO ALV Grid

    I wanted to put this in the WIKI but it keeps bombing out when I try and save so I've put this here -- Maybe a MOD can move it for me.
    This generic class should give you far more insite into using an EDITABLE ALV table than the standard documentation.
    If you follow the steps you should be able to code very quickly a decent useable ALV OO program which can retrieve and manipulate data very easily.  The events are (hopefully) well documented as are all the steps.
    Once you understand the basics you can add more functionality like colouring Cells, adding hyperlinks etc etc.
    I've always found that stupid SEAT / AIRLINE application SAP uses for its examples far too overblown and in reality who would ever use a SAP system for Airline reservations anyway.
    The class here describes a much simpler application which CLEARLY (I hope) explains how the whole thing works.
    Jimbo's generic class for using the OO ALV GRID Class CL_GUI_ALV_GRID
    from an application program to display and manipulate ANY table
    with minimal coding needed in the Calling application program.
    Handles the following EVENTS
    1) TOOLBAR BUTTONS
    (you can add more to the toolbar method
      if you need even more functionality).
    2) DOUBLE CLICK
    3) ENTER KEY PRESSED
    4) DATA CHANGED
    5) DATA CHANGED FINISHED
    Methods available
    PUBLIC METHODS  ( Can be called directly from the application program).
    1) display_grid  displays grid with toolbar
       Table and FCAT are built dynamically - user only needs to
       define the table structure (can be DDIC or User fields)
    2) change_title  - changes title at the top of the Grid
    3) refresh_grid   - refreshes grid after table updated etc.
    4) build_dynamic_structures - this method creates a dynamic table and a dynamic FCAT
       using the structure defined in the calling application program
    PRIVATE METHODS (Internal Methods used within the class)
    1) verwerk - returns to FORM VERWERK in calling application program
       (Via Toolbar). The application program can then do any special processing
       at this point e.g update SAP tables etc.
    2) download_to_excel (via Toolbar). This creates an EXCEL spreadsheet
       directly which can be downloaded / saved to a file if required,
    3) return_structure - internal method returns the structure
       of the table defined in the calling application program. This is needed in order
       to build the dynamic table and Field Catalog.
    4) create_dynamic_table  - creates a dynamic table from the structure defined in
       the calling application program
    5) create_dynamic_fcat  - creates the dynamic field catalog from the structure
       defined in the application program.
    6) dubbleklik entered when user double clicks a cell
    activated by EVENT DOUBLE_CLICK.
    returns to FORM DUBBELKLIK  in the
    calling application program
       COOKBOOK STEP BY STEP instructions on how to use this class
       in your application program.
       In the application program :
    1) define a blank screen 100  - SE51 with a custom container
       on it called CCONTAINER1.
       you need the following logic in the screen
       The PAI is only used if you have defined a STATUS with SE41 and you exit the
       application program via the standard SAP buttons on the
       top of the Screen (NOT the GRID toolbar).
         PROCESS BEFORE OUTPUT.
          MODULE STATUS_0100.
         PROCESS AFTER INPUT.
         MODULE USER_COMMAND_0100.
    2) (optional) define a STATUS with a titlebar - SE41
       you only need this if you want the standard EXIT and menu buttons on the
       top line of the screen
    3) If you want to have your OWN colum names on the grid
       add the following macro to the start of your program
         DEFINE col_name.
         read  table it_fldcat into  wa_it_fldcat index &1.
         wa_it_fldcat-coltext = &2.
         modify it_fldcat from wa_it_fldcat index &1.
         END-OF-DEFINITION.
    4) Define the following Field symbols
       <fs1>           TYPE  ANY,
       <fs2>           TYPE  STANDARD TABLE,
       <fs3>           TYPE ANY,
       <field_catalog> TYPE STANDARD TABLE,
       <dyn_table>    TYPE  STANDARD TABLE,
       <orig_table>   TYPE  STANDARD TABLE,
       <dyn_field>,
       <dyn_wa>.
    5) After the field-symbols add the code in this class
        as an INCLUDE
        e.g INCLUDE ZZJIMBOXX_INCL.
    6) define your Internal table as follows
        TYPES:  BEGIN OF s_elements,
                  Your structure
                your structure etc.
                END OF  s_elements.
    For example
    INCLUDE  <icon>.
    TABLES: VAPMA.
    *TYPES:  BEGIN OF s_elements,
    vbeln   TYPE vapma-vbeln,
    posnr   TYPE vapma-posnr,
    matnr   TYPE vapma-matnr,
    kunnr   TYPE vapma-kunnr,
    werks   TYPE vapma-werks,
    vkorg   TYPE vapma-vkorg,
    vkbur   TYPE vapma-vkbur,
    status  TYPE c,
    *END OF  s_elements.
    7) Define the following data  IN YOUR APPLICATION PROGRAM
       (note here only data is described
       that relates to using THIS CLASS. Data purely used internally
       in the application program is NOT shown here).
    DATA: z_object          TYPE REF TO zcl_dog,  "Instantiate our class
          grid_container1    TYPE REF TO cl_gui_custom_container,
          t_elements         TYPE TABLE OF s_elements, "refers to our ITAB
          wa_elements        TYPE s_elements,
          wa_dyn_table_line  TYPE REF TO DATA,
          it_fldcat          TYPE lvc_t_fcat,
          i_gridtitle        TYPE lvc_title,
          wa_it_fldcat       TYPE lvc_s_fcat,
          new_table          TYPE REF TO DATA,
          dy_table           TYPE REF TO data,
          dy_line            TYPE REF TO data,
          row_id             TYPE sy-index.
    8) insert the following code at the start of the application program.
    *START-OF-SELECTION.
    *CALL SCREEN 100.
    *END-OF-SELECTION.
    *MODULE status_0100 OUTPUT.
    *ASSIGN  wa_elements TO <fs1>.
    *CREATE OBJECT z_object EXPORTING z_object = z_object. "Instantiate the class
    *CALL METHOD z_object->build_dynamic_structures
           CHANGING it_fldcat = it_fldcat.
    9) if you inserted the macro in step 3) then
       define your own column names as follws
      col_name 1 'Name1'.
      col_name 2 'Name2'.
      etc. The number is the colum number you want and the name is
      the name you want to assign to the column.
    for example using the table shown above
      col_name 1 'Order Nr'.
      col_name 2 'Item'.
      col_name 3 'Material'.
      col_name 4 'Customer'.
      col_name 5 'Plant'.
      col_name 6 'Sales Org'.
      col_name 7 'Sales Office'.
      col_name 8 'Status'.
    10)  perform a routine that fills your dynamic table and
         display the GRID. If you created a status with SE41 you can set
         a title etc. Further processing is dependent on the users action
         after the GRID is displayed for example if a Cell is double clicked,
         dat is entered, a toolbar button is pressed or a SAP ICON on top of the screen is pressed.
    PERFORM populate_dynamic_itab.
    CALL METHOD z_object->display_grid
          CHANGING it_fldcat = it_fldcat.
    SET PF-STATUS '0001'.
    SET TITLEBAR '000'.
    ENDMODULE.
    11) If you added a STATUS via SE41 you can exit the program via the
    standard SAP buttons at the top of the screen
    otherwise exit via the exit button on the toolbar.
    You only need this piece of code if you defined a STATUS in the application program
    MODULE user_command_0100 INPUT.
    CASE sy-ucomm.
       WHEN 'BACK'.
         LEAVE PROGRAM.
       WHEN 'EXIT'.
         LEAVE PROGRAM.
       WHEN 'RETURN'.
         LEAVE PROGRAM.
       WHEN OTHERS.
    ENDCASE.
    12)  to populate the dynamic table you only need to code something like this
    remember the class has already created and structured the field-symbol <dyn_table>
    so you don't have to do anything other than just select the fields you want
    filled and from what data source(es).
    *FORM populate_dynamic_itab.
    *SELECT vbeln posnr matnr kunnr werks vkorg vkbur
          UP TO 200 rows
          FROM vapma
          INTO  CORRESPONDING FIELDS OF TABLE <dyn_table>.
    if you want to keep the original table before making any changes etc code
    the following
    create 2nd Dyn table to hold original data. We can use
    the same field catalog as for the original table
    as we are just creating an identical copy here.
    *CALL METHOD cl_alv_table_create=>create_dynamic_table
       EXPORTING
            it_fieldcatalog = it_fldcat
         IMPORTING
            ep_table = dy_table.
      ASSIGN dy_table->* TO <orig_table>.
    CREATE DATA dy_line LIKE LINE OF <orig_table>.
    ASSIGN dy_line->* TO <dyn_wa>.
    <orig_table> = <dyn_table>.
    ENDFORM.
    13) you need these 2 processing routines in your application program.
    FORM VERWERK.  "Entered from VERW on toolbar
    *break-point 1.
    Orig table is in dynamic table <orig_table>
    ALV GRID changed table is in <dyn_table>.
    *Loop at <orig_table>  into <dyn_wa>.
      Do what you want here
    end
    endloop.
    ENDFORM.
    *form dubbleklik using     "Entered when a cell is double clicked
           e_row   type LVC_S_ROW
           e_column type LVC_S_col
           es_row_no type lvc_s_roid.
           break-point 1.
    Get Row id into a variable for this program.
           row_id =  e_row.
            SET TITLEBAR '001'.      "If you defined a status in SE41
           i_gridtitle = 'Grid Title Changed'.
           CALL METHOD  z_object->change_title
             EXPORTING i_gridtitle = i_gridtitle.
           PERFORM refresh.
    endform.
    The REFRESH routine is optional but after a double click I assume
    you want to do some processing
    and re-display the data
    so as a sample code something like
    *FORM refresh.
    data: ord_nr  TYPE vapma-vbeln.  "Your data
    *READ TABLE  <dyn_table> index row_id into wa_elements.
       ord_nr = wa_elements-vbeln.
    You've now got the Row double clicked so pick out the data element(s)
    you wnat to process and do your processing
    *set parameter id 'AUN'  field ord_nr.
    *CALL TRANSACTION  'VA02' AND SKIP FIRST SCREEN.
    You can update the dynamic table for example
    *wa_elements-status = 'C'.
    *modify <dyn_table> from wa_elements index row_id.
    now redisplay the updated grid.
    *CALL METHOD z_object->refresh_grid.
    *ENDFORM.
    *************Class ZCL_DOG*************
    CLASS zcl_dog DEFINITION.
    PUBLIC SECTION.
    METHODS:
      constructor
         IMPORTING
                      z_object TYPE REF TO zcl_dog,
       display_grid
         CHANGING
                      it_fldcat TYPE lvc_t_fcat,
           build_dynamic_structures
         CHANGING        it_fldcat TYPE lvc_t_fcat,
        change_title
         IMPORTING
                i_gridtitle  TYPE lvc_title,
         refresh_grid.
      PRIVATE SECTION.
       METHODS:
        on_user_command FOR EVENT before_user_command OF cl_gui_alv_grid
          IMPORTING       e_ucomm
                          sender,
        on_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
          IMPORTING      e_object
                         e_interactive,
         on_dubbelklik FOR EVENT double_click OF cl_gui_alv_grid
          IMPORTING e_row
                    e_column
                    es_row_no,
        handle_data_changed
                 FOR EVENT data_changed OF cl_gui_alv_grid
                 IMPORTING er_data_changed,
        handle_data_changed_finished
                 FOR EVENT data_changed_finished OF cl_gui_alv_grid
                 IMPORTING e_modified
                           et_good_cells,
        verwerk
                IMPORTING program TYPE sy-repid,
        download_to_excel,
        dubbleklik
                IMPORTING
                     e_row  type  LVC_S_ROW
                     e_column   TYPE LVC_S_COL
                     es_row_no  type lvc_s_ROID
                     program type sy-repid,
         return_structure,
         create_dynamic_fcat
          EXPORTING       it_fldcat TYPE lvc_t_fcat,
          create_dynamic_table
          IMPORTING       it_fldcat TYPE lvc_t_fcat
          EXPORTING       dy_table  TYPE REF TO DATA.
    DATA:
        lr_rtti_struc    TYPE REF TO cl_abap_structdescr,        "RTTI
        zog              LIKE LINE OF lr_rtti_struc->components, "RTTI
        wa_it_fldcat     TYPE lvc_s_fcat,
        it_fldcat        TYPE lvc_t_fcat,
        dy_table         TYPE REF TO data,
        dy_line          TYPE REF TO data,
        struct_grid_lset TYPE lvc_s_layo,
        e_row            TYPE LVC_S_ROW,
        e_column         TYPE lvc_s_col,
        es_rowid         TYPE lvc_s_roid,
        grid_container1  TYPE REF TO cl_gui_custom_container,
        grid1            TYPE REF TO cl_gui_alv_grid,
        ls_layout        TYPE kkblo_layout,
        lt_fieldcat_wa   TYPE kkblo_fieldcat,
        l_mode           TYPE raw4,
        celltab          TYPE LVC_T_STYL,
        wa_celltab       TYPE lvc_s_styl,
        lt_fieldcat      TYPE kkblo_t_fieldcat,
       l_tabname         TYPE slis_tabname.
    TYPES:
       struc            LIKE  zog.
    DATA:
        zogt           TYPE TABLE OF struc.
       ENDCLASS.
    CLASS zcl_dog IMPLEMENTATION.
    METHOD constructor.
       CREATE OBJECT grid_container1
           EXPORTING
                   container_name = 'CCONTAINER1'.
        CREATE OBJECT  grid1
            EXPORTING
                  i_parent = grid_container1.
        SET HANDLER z_object->on_user_command for grid1.
        SET HANDLER z_object->on_toolbar for grid1.
        SET HANDLER Z_OBJECT->handle_data_changed_finished FOR grid1.
        SET HANDLER Z_OBJECT->on_dubbelklik FOR grid1.
        CALL METHOD grid1->register_edit_event
            EXPORTING
                    i_event_id = cl_gui_alv_grid=>mc_evt_enter.
    ENDMETHOD.
    METHOD refresh_grid.
      CALL METHOD cl_gui_cfw=>flush.
      CALL METHOD grid1->refresh_table_display.
    ENDMETHOD.
    METHOD on_dubbelklik.
    CALL METHOD me->dubbleklik
             EXPORTING
                     e_row  = e_row
                     e_column =  e_column
                     es_row_no = es_row_no
                     program  = sy-repid.
    break-point 1.
    ENDMETHOD.
    METHOD  handle_data_changed.
    Insert user code here if required
    this method is entered if user ENTERS DATA.
    ENDMETHOD.
    METHOD handle_data_changed_finished.
    Insert user code here if required
    Method entered here after data entry has finished.
    ENDMETHOD.
    METHOD return_structure.
      lr_rtti_struc ?= cl_abap_structdescr=>DESCRIBE_BY_DATA( <fs1> ).
      zogt[]  = lr_rtti_struc->components.
      ASSIGN zogt[] TO <fs2>.
      ENDMETHOD.
    METHOD create_dynamic_fcat.
        LOOP AT <fs2>  INTO zog.
          CLEAR wa_it_fldcat.
          wa_it_fldcat-fieldname = zog-name .
          wa_it_fldcat-datatype = zog-type_kind.
          wa_it_fldcat-inttype = zog-type_kind.
          wa_it_fldcat-intlen = zog-length.
          wa_it_fldcat-decimals = zog-decimals.
          wa_it_fldcat-coltext = zog-name.
          wa_it_fldcat-lowercase = 'X'.
          APPEND wa_it_fldcat TO it_fldcat .
          ASSIGN it_fldcat[] TO <field_catalog>.
          ENDLOOP.
           ASSIGN  it_fldcat[] TO <field_catalog>.
        ENDMETHOD.
    METHOD  download_to_excel.
    break-point 5.
    CALL FUNCTION  'LVC_TRANSFER_TO_KKBLO'
        EXPORTING
          it_fieldcat_lvc   = <field_catalog>
         is_layout_lvc     = m_cl_variant->ms_layout
           is_tech_complete  = ' '
        IMPORTING
          es_layout_kkblo   = ls_layout
          et_fieldcat_kkblo = lt_fieldcat.
    LOOP AT lt_fieldcat INTO lt_fieldcat_wa.
       CLEAR lt_fieldcat_wa-tech_complete.
        IF lt_fieldcat_wa-tabname IS initial.
           lt_fieldcat_wa-tabname = '1'.
           MODIFY lt_fieldcat FROM lt_fieldcat_wa.
        ENDIF.
        l_tabname = lt_fieldcat_wa-tabname.
    ENDLOOP.
    CALL FUNCTION 'ALV_XXL_CALL'
        EXPORTING
          i_tabname           = l_tabname
          is_layout           = ls_layout
          it_fieldcat         = lt_fieldcat
          i_title             = sy-title
        TABLES
          it_outtab           = <dyn_table>
        EXCEPTIONS
          fatal_error         = 1
          no_display_possible = 2
          others              = 3.
      IF  sy-subrc <> 0.
         message id sy-msgid type 'S' number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
    ENDMETHOD.
    METHOD create_dynamic_table.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
             it_fieldcatalog = it_fldcat
          IMPORTING
             ep_table = dy_table.
    ENDMETHOD.
    METHOD build_dynamic_structures.
    CALL METHOD me->return_structure.
    CALL METHOD me->create_dynamic_fcat
       IMPORTING
         it_fldcat = it_fldcat.
    CALL METHOD me->create_dynamic_table
        EXPORTING
          it_fldcat = it_fldcat
        IMPORTING
          dy_table        = dy_table.
         ASSIGN dy_table->* TO <dyn_table>.
    CREATE DATA dy_line LIKE LINE OF <dyn_table>.
    ASSIGN dy_line->* TO <dyn_wa>.
    ENDMETHOD.
    METHOD display_grid.
      struct_grid_lset-edit = 'X'. "To enable editing in ALV
      struct_grid_lset-grid_title = 'Bulkwijzigingen inkoopprijzen'.
      struct_grid_lset-ctab_fname = 'T_CELLCOLORS'.
      struct_grid_lset-stylefname = 'CELLTAB'.
      CALL METHOD grid1->set_ready_for_input
          EXPORTING
               i_ready_for_input = '1'.
      CALL METHOD grid1->set_table_for_first_display
          EXPORTING
               is_layout       = struct_grid_lset
        CHANGING
               it_outtab       = <dyn_table>
               it_fieldcatalog = it_fldcat.
    ENDMETHOD.
    METHOD change_title.
      CALL METHOD grid1->set_gridtitle
       EXPORTING
       i_gridtitle =  i_gridtitle.
      ENDMETHOD.
    METHOD on_user_command.
      CASE e_ucomm.
          WHEN 'EXIT'.
            LEAVE PROGRAM.
         WHEN 'EXCEL'.
         CALL METHOD me->download_to_excel.
          WHEN 'SAVE'.
          WHEN 'VERW'.
          CALL METHOD me->verwerk
               EXPORTING
                  PROGRAM = SY-REPID.
      ENDCASE.
    ENDMETHOD.                    "on_user_command
    METHOD on_toolbar.
    User can add extra functionality by adding extra
    buttons if required. Functionality can also be simplified by removing buttons.
    DATA: ls_toolbar TYPE stb_button.
         CLEAR ls_toolbar.
         MOVE 0 TO ls_toolbar-butn_type.
         MOVE 'EXIT' TO ls_toolbar-function.
         MOVE SPACE TO ls_toolbar-disabled.
         MOVE icon_system_end TO ls_toolbar-icon.
         MOVE 'Click2Exit' TO ls_toolbar-quickinfo.
         APPEND ls_toolbar TO e_object->mt_toolbar.
         CLEAR ls_toolbar.
         MOVE  0 TO ls_toolbar-butn_type.
         MOVE 'SAVE' TO ls_toolbar-function.
         MOVE SPACE TO ls_toolbar-disabled.
         MOVE  icon_system_save TO ls_toolbar-icon.
         MOVE 'Save data' TO ls_toolbar-quickinfo.
         APPEND ls_toolbar TO e_object->mt_toolbar.
         CLEAR ls_toolbar.
         MOVE  0 TO ls_toolbar-butn_type.
         MOVE 'EDIT' TO ls_toolbar-function.
         MOVE  SPACE TO ls_toolbar-disabled.
         MOVE  icon_toggle_display_change TO ls_toolbar-icon.
         MOVE 'Edit data' TO ls_toolbar-quickinfo.
         MOVE  'EDIT' TO ls_toolbar-text.
         APPEND ls_toolbar TO e_object->mt_toolbar.
         CLEAR ls_toolbar.
         MOVE  0 TO ls_toolbar-butn_type.
         MOVE 'VERW' TO ls_toolbar-function.
         MOVE  SPACE TO ls_toolbar-disabled.
         MOVE   icon_businav_process to ls_toolbar-icon.
         MOVE 'Verw.' TO ls_toolbar-quickinfo.
         MOVE  'VERW' TO ls_toolbar-text.
         APPEND ls_toolbar TO e_object->mt_toolbar.
          CLEAR ls_toolbar.
         MOVE  0 TO ls_toolbar-butn_type.
         MOVE 'EXCEL' TO ls_toolbar-function.
         MOVE  SPACE TO ls_toolbar-disabled.
         MOVE  icon_xxl TO ls_toolbar-icon.
         MOVE 'Excel' TO ls_toolbar-quickinfo.
         MOVE  'EXCEL' TO ls_toolbar-text.
         APPEND ls_toolbar TO e_object->mt_toolbar.
       ENDMETHOD.
       METHOD verwerk.
          PERFORM verwerk IN PROGRAM (program).
          LEAVE PROGRAM.
      ENDMETHOD.
      METHOD dubbleklik.
      PERFORM dubbleklik IN PROGRAM (program)
        USING
            e_row
            e_column
            es_row_no.
      ENDMETHOD.
    ENDCLASS.
    Cheers
    Jimbo

    Hi Dinu,
    Before analysing ALV, please cross check the behaviour of the calling program.
    Is the control really going to the application server when you do all the above process?
    If so, when user makes some changes are they saved in the data base / affected the internal table which you are using for ALV?
    Regards
    Surya.

Maybe you are looking for

  • Why is the home button not working correctly?

    I have reset the button by holding sleep key & home button down, i have also tried to reset the home button by holding this down itself, it is still none responsive most if the time.  I have done this many times. It is also very difficult to get it t

  • Moved i tunes and files to external  drive and now have 3000 files???? help

    I moved all files to an external drive and now show all files as seperate how do i find my playlists and also put the items back into i tunes form??? so f#%@ing confused and also the library comes up as a huge dos read file? what do I need to do. i l

  • Database connection in applet works in Netscape but not in IE

    Hello, we have an applet which connects through an jdbc:odbc connection to an Access database. When we run it in Netscape 4.7, the applet connects to the database and finds records. When we run it in IE (5.5), we get an error. Haven't completely figu

  • Low quality when copied to phone..?

    When I try to copy content from my desktop design to my phone, they look very low quality in the design and preview. They are PNG files that I created from Photoshop. Do I have to resize them in Photoshop, or is there a way to fix this in Muse? And a

  • Travelling how best to bring pictures from laptop

    I have lightroom on a laptop and desktop syst em. Wondering about best way to bring the pictures I take while travelling to desktop system without losing lightroom data. On both computers I keep photographs in folders by date. In past I have simply c