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.

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

  • 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

  • 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

  • Enqueue and Dequeue before updating Database table

    Hi all,
    We are updating database tables using INSERT, MODIFY and UPDATE statements. Since many people will be running the application at the same time we need to lock the table before updating database table. So we need to use ENQUEUE and DEQUEUE functionality for this purpose.
    Can any plz explain what are the steps we should follow now?
    Thanks in advance.

    Hi,
    Any Database access should carefully handled as multiple applications may be accessing the database at the same time. To read a record from the database you don't need to implement a lock, but to write you need not only locks but also ideally should use the Update Function Modules to comply SAP "All or Nothing" Principle. This will prevent data inconsistency of the database and the data will be proper state. You need to use the COMMIT WORK and ROLLBACK WORK in you code to handle the consistency part of the database.
    The best design approach would be seperate the Database Layer completely from the business layers. This will make your code robust and easy to maintain.
    As, for the Locking Concepts, you will get multiple resources from SDN as how to create Locks and implement the Locking modules in your code. But more than that what matters is why and how to implement the SAP Locking concepts to make your application run better.
    Have a look at the following link
    http://help.sap.com/saphelp_nw70/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
    Hope this helps.
    Thanks,
    Samantak.

  • Require some tutorials to use ALV grids to access database

    I am new to ALV grids
    I want step by step method to use ALV grids in ABAP reports to access database.

    Hi,
    pls go throgugh this link.
    http://www.erpgenie.com/abap/controls/alvgrid.htm
    sample program
    Sample programs on ALV Grid
    report zbnstest.
    TABLES AND DATA DECLARATION.
    *TABLES: mara,makt.",marc.
    data syrepid like sy-repid.
    data sydatum(10). " LIKE sy-datum.
    data sypagno(3) type n.
    WHEN USING MORE THAN ONE TABLE IN ALV WE NEEED TO DECLARE THE TYPE
    GROUP (TYPE-POOLS--------->SLIS)
    type-pools : slis.
    INTERNAL TABLE DECLARATION.
    INTERNAL TABLE TO HOLD THE VALUES FROM THE MARA TABLE
    data: begin of t_mara occurs 0,
    matnr like mara-matnr,
    meins like mara-meins,
    mtart like mara-mtart,
    matkl like mara-matkl,
    end of t_mara.
    INTERNAL TABLE TO HOLD THE CONTENTS FROM THE EKKO TABLE
    data : begin of t_marc occurs 0,
    matnr like mara-matnr,
    werks like marc-werks,
    minbe like marc-minbe.
    data: end of t_marc.
    INTERNAL TABLE TO HOLD THE VALUES FROM MAKT TABLE.
    data : begin of t_makt occurs 0,
    matnr like mara-matnr,
    maktx like makt-maktx,
    spras like makt-spras,
    end of t_makt.
    INTERNAL TABLE WHICH ACTUALLY MERGES ALL THE OTHER INTERNAL TABLES.
    data: begin of itab1 occurs 0,
    matnr like mara-matnr,
    meins like mara-meins,
    maktx like makt-maktx,
    spras like makt-spras,
    werks like marc-werks,
    minbe like marc-minbe,
    end of itab1.
    THE FOLLOWING DECLARATION IS USED FOR DEFINING THE FIELDCAT
    AND THE LAYOUT FOR THE ALV.
    HERE AS slis_t_fieldcat_alv IS A INTERNAL TABLE WITHOUT A HEADER LINE
    WE EXPLICITELY DEFINE AN INTERNAL TABLE OF THE SAME STRUCTURE AS THAT
    OF slis_t_fieldcat_alv BUT WITH A HEADER LINE IN THE DEFINITION.
    THIS IS DONE TO MAKE THE CODE SIMPLER.
    OTHERWISE WE MAY HAVE TO DEFINE THE STRUCTURE AS IN THE NORMAL SAP
    PROGRAMS.
    IN THE FIELDCATALOG TABLE WE ACTUALLY PASS THE FIELDS FROM ONE OR
    MORE TABLES AND CREATE A STRUCTURE
    IN THE LAYOUT STRUCTURE WE BASICALLY DEFINE THE FORMATTING OPTIONS
    LIKE DISPLAY IN THE ZEBRA PATTERN ,THE HOTSPOT OPTIONS ETC.
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
    fieldlayout type slis_layout_alv.
    DECLARING THE EVENTTABLE INTERNL TABLE FOR USING EVENTS LIKE
    TOP-OF-PAGE ETC.
    data : eventstab type slis_t_event with header line.
    DECLARING AN INTERNAL TABLE TO HOLD THE DATA FOR THE TOP-OF-PAGE
    data : heading type slis_t_listheader with header line.
    data : heading1 type slis_t_listheader with header line.
    data : heading2 type slis_t_listheader with header line.
    data : heading3 type slis_t_listheader with header line.
    data : heading4 type slis_t_listheader with header line.
    data : heading5 type slis_t_listheader with header line.
    data : heading6 type slis_t_listheader with header line.
    data : heading7 type slis_t_listheader with header line.
    data : heading8 type slis_t_listheader with header line.
    STRUCTURE TO PASS THE COLOR ATTRIBUTES FOR DISPLAY.
    data : colorstruct type slis_coltypes.
    INITIALIZATION. *
    initialization.
    syrepid = sy-repid.
    sypagno = sy-pagno.
    clear fieldcatalog.
    START-OF-SELECTION. *
    start-of-selection.
    SUBROUTINE TO POPULATE THE COLORSTRUCT
    perform fill_colorstruct using colorstruct.
    SUBROUTINE TO POPULATE THE FIELDS OF THE FIELD CATALOGUE
    perform populate_fieldcatalog.
    SUBROUTINE TO SELECT DATA FROM VARIOUS TABLES AND POPULATE IT IN THE
    INTERNAL TABLE.
    perform selectdata_and_sort.
    SUBROUTINE TO POPULATE THE LAYOUT STRUCTURE.
    perform populate_layout using fieldlayout.
    SUBROUTINE TO CALL THE FUNCTION MERGE TO ENSURE PROPER DISPLAY.
    perform merge_fieldcatalog.
    SUBROUTINE TO POPULATE THE EVENTSTAB.
    perform fill_eventstab tables eventstab.
    SUBROUTINE TO POPULATE THE HEADING TABLES.
    perform fill_headingtable tables heading using 'HEADING'.
    perform fill_headingtable tables heading1 using 'HEADING1'.
    perform fill_headingtable tables heading2 using 'HEADING2'.
    perform fill_headingtable tables heading3 using 'HEADING3'.
    perform fill_headingtable tables heading4 using 'HEADING4'.
    perform fill_headingtable tables heading5 using 'HEADING5'.
    perform fill_headingtable tables heading6 using 'HEADING6'.
    perform fill_headingtable tables heading7 using 'HEADING7'.
    perform fill_headingtable tables heading8 using 'HEADING8'.
    SUBROUTINE TO DISPLAY THE LIST.
    perform display_alv_list.
    FORMS
    IN THIS SUBROUTINE WE POPULATE THE FIELDCATALOG TABLE WITH THE NAMES
    OF THE TABLE,FIELDNAME,WHETHER IT IS KEY FIELD OR NOT,HEADING AND
    COLUMN JUSTIFICATION.
    form populate_fieldcatalog.
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'MATNR' 'X' .
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'MEINS' ' '.
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'MAKTX' ' ' .
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'MTART' ' ' .
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'MATKL' ' ' .
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'SPRAS' ' ' .
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'WERKS' ' ' .
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'MINBE' ' ' .
    endform. " POPULATE_FIELDCATALOG
    FORM FILL_FIELDS_OF_FIELDCATALOG *
    --> FIELDCATALOG *
    --> P_TABNAME *
    --> P_FIELDNAME *
    --> P_KEY *
    --> P_KEY *
    form fill_fields_of_fieldcatalog tables fieldcatalog
    structure fieldcatalog
    using p_tabname
    p_fieldname
    p_key.
    p_no_out.
    fieldcatalog-tabname = p_tabname.
    fieldcatalog-fieldname = p_fieldname.
    fieldcatalog-key = p_key.
    fieldcatalog-emphasize = '1234'.
    *fieldcatalog-no_out = p_no_out.
    append fieldcatalog.
    endform. " FILL_FIELDSOFFIELDCATALOG
    FORM POPULATE_LAYOUT *
    --> FIELDLAYOUT *
    form populate_layout using fieldlayout type slis_layout_alv.
    fieldlayout-f2code = '&ETA' .
    fieldlayout-zebra = 'X'.
    FOR THE WINDOW TITLE.
    fieldlayout-window_titlebar = 'ALV with Events'.
    fieldlayout-colwidth_optimize = 'X'.
    fieldlayout-no_vline = ' '.
    *fieldlayout-no_input = 'X'.
    fieldlayout-confirmation_prompt = ''.
    fieldlayout-key_hotspot = 'X'.
    This removes the column headings if the flag is set to 'X'
    fieldlayout-no_colhead = ' '.
    *fieldlayout-hotspot_fieldname = 'MAKTX'.
    fieldlayout-detail_popup = 'X'.
    fieldlayout-coltab_fieldname = 'X'.
    endform. " POPULATE_LAYOUT
    FORM SELECTDATA_AND_SORT *
    form selectdata_and_sort.
    select matnr meins mtart matkl from mara
    into corresponding fields of t_mara
    up to 500 rows .
    select matnr maktx spras from makt
    into corresponding fields of t_makt
    where matnr = t_mara-matnr and
    spras = sy-langu.
    select matnr werks minbe from marc
    into corresponding fields of t_marc
    where matnr = t_mara-matnr.
    append t_marc.
    endselect.
    append t_makt.
    endselect.
    append t_mara.
    endselect.
    perform populate_itab1.
    sort itab1 by matnr.
    endform. " SELECTDATA_AND_SORT
    FORM MERGE_FIELDCATALOG *
    form merge_fieldcatalog.
    call function 'REUSE_ALV_FIELDCATALOG_MERGE'
    exporting
    i_program_name = syrepid
    i_internal_tabname = 'ITAB1'
    i_structure_name = 'COLORSTRUCT'
    I_CLIENT_NEVER_DISPLAY = 'X'
    i_inclname = syrepid
    changing
    ct_fieldcat = fieldcatalog[]
    exceptions
    inconsistent_interface = 1
    program_error = 2
    others = 3.
    endform. " MERGE_FIELDCATALOG
    IN THIS FUNCTION THE MINIMUM PARAMETERS THAT WE NEED TO PASS IS AS
    FOLLOWS:-
    i_callback_program --> CALLING PROGRAM NAME
    i_structure_name --> STRUCTURE NAME.
    is_layout --> LAYOUT NAME.
    it_fieldcat ---> BODY OF THE FIELD CATALOGUE INTERNAL TABLE
    form display_alv_list.
    call function 'REUSE_ALV_LIST_DISPLAY'
    exporting
    I_INTERFACE_CHECK = ' '
    i_callback_program = syrepid
    I_CALLBACK_PF_STATUS_SET = ' '
    I_CALLBACK_USER_COMMAND = ' '
    i_structure_name = 'ITAB1'
    is_layout = fieldlayout
    it_fieldcat = fieldcatalog[]
    IT_EXCLUDING =
    IT_SPECIAL_GROUPS =
    IT_SORT =
    IT_FILTER =
    IS_SEL_HIDE =
    I_DEFAULT = 'X'
    THE FOLLOWING PARAMETER IS SET AS 'A' INORDER TO DISPLAY THE STANDARD
    TOOL BAR
    i_save = 'A'
    IS_VARIANT = ' '
    it_events = eventstab[]
    IT_EVENT_EXIT =
    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 =
    tables
    t_outtab = itab1
    exceptions
    program_error = 1
    others = 2.
    endform. " DISPLAY_ALV_LIST
    *& Form POPULATE_ITAB1
    text
    --> p1 text
    <-- p2 text
    form populate_itab1.
    loop at t_mara.
    loop at t_makt where matnr = t_mara-matnr.
    loop at t_marc where matnr = t_mara-matnr.
    move-corresponding t_mara to itab1.
    move-corresponding t_makt to itab1.
    move-corresponding t_marc to itab1.
    append itab1.
    endloop.
    endloop.
    endloop.
    endform. " POPULATE_ITAB1
    *& Form FILL_EVENTSTAB
    text
    -->P_EVENTSTAB text *
    form fill_eventstab tables p_eventstab structure eventstab.
    WHEN THE FOLLOWING FUNCTION IS CALLED THE SYSTEM POPULATES THE
    INTERNAL TABLE EVENTSTAB WITH A LIST OF EVENTS NAME.
    AS SHOWN BELOW WHEN USING I_LIST_TYPE = 0 THE FUNCTION RETURNS 14
    EVENTS NAME.
    call function 'REUSE_ALV_EVENTS_GET'
    exporting
    i_list_type = 0
    importing
    et_events = p_eventstab[]
    exceptions
    list_type_wrong = 1
    others = 2.
    BY CALLING THE ABOVE FUNCTION WE FIRST POPULATE THE EVENTSTAB WITH
    THE PREDEFINED EVENTS AND THEN WE MOVE THE FORM NAME AS SHOWN BELOW.
    WE ASSIGN A FORM NAME TO THE EVENT AS REQUIRED BY THE USER.
    FORM NAME CAN BE ANYTHING.THE PERFORM STATEMENT FOR THIS FORM
    IS DYNAMICALY CALLED.
    read table p_eventstab with key name = slis_ev_top_of_page.
    if sy-subrc = 0 .
    move 'TOP_OF_PAGE' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_top_of_coverpage.
    if sy-subrc = 0 .
    move 'TOP_OF_COVERPAGE' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_end_of_coverpage .
    if sy-subrc = 0 .
    move 'END_OF_COVERPAGE' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_foreign_top_of_page.
    if sy-subrc = 0 .
    move 'FOREIGN_TOP_OF_PAGE' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_foreign_end_of_page.
    if sy-subrc = 0 .
    move 'FOREIGN_END_OF_PAGE' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_list_modify.
    if sy-subrc = 0 .
    move 'LIST_MODIFY' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_top_of_list.
    if sy-subrc = 0 .
    move 'TOP_OF_LIST' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_end_of_page.
    if sy-subrc = 0 .
    move 'END_OF_PAGE' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_end_of_list .
    if sy-subrc = 0 .
    move 'END_OF_LIST' to p_eventstab-form.
    append p_eventstab.
    endif.
    endform. " FILL_EVENTSTAB
    *& Form FILL_HEADINGTABLE
    text
    -->P_HEADING text *
    form fill_headingtable tables p_heading structure heading
    using tablename.
    case tablename.
    when 'HEADING'.
    p_heading-typ = 'H'.
    concatenate
    ' REPORT NAME:-' syrepid
    ' ABB Industry Pte Ltd' into p_heading-info.
    append p_heading.
    write sy-datum using edit mask '__/__/____' to sydatum.
    concatenate
    ' DATE:-' sydatum ' USER: ' sy-uname 'PAGE NO:' sypagno
    into p_heading-info.
    append p_heading.
    when 'HEADING1'.
    p_heading-typ = 'H'.
    p_heading-info = 'TOP-OF-COVER-PAGE'.
    append p_heading.
    when 'HEADING2'.
    p_heading-typ = 'H'.
    p_heading-info = 'END-OF-COVER-PAGE'.
    append p_heading.
    when 'HEADING3'.
    p_heading-typ = 'H'.
    p_heading-info = 'FOREIGN-TOP-OF-PAGE'.
    append p_heading.
    when 'HEADING4'.
    p_heading-typ = 'H'.
    p_heading-info = 'FOREIGN-END-OF-PAGE'.
    append p_heading.
    WHEN 'HEADING5'.
    P_HEADING-TYP = 'H'.
    P_HEADING-INFO = 'LIST-MODIFY'.
    APPEND P_HEADING.
    when 'HEADING6'.
    p_heading-typ = 'H'.
    p_heading-info = 'END-OF-PAGE'.
    append p_heading.
    when 'HEADING7'.
    p_heading-typ = 'H'.
    p_heading-info = 'END-OF-LIST'.
    append p_heading.
    when 'HEADING8'.
    p_heading-typ = 'H'.
    p_heading-info = 'TOP-OF-LIST'.
    append p_heading.
    endcase.
    endform. " FILL_HEADINGTABLE
    FORM TOP_OF_PAGE *
    form top_of_page.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading[]
    exceptions
    others = 1.
    endform.
    *& Form FILL_COLORSTRUCT
    text
    -->P_COLORSTRUCT text *
    form fill_colorstruct using p_colorstruct type slis_coltypes .
    p_colorstruct-heacolfir-col = 6.
    p_colorstruct-heacolfir-int = 1.
    p_colorstruct-heacolfir-inv = 1.
    endform. " FILL_COLORSTRUCT
    FORM TOP_OF_COVERPAGE *
    form top_of_coverpage.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading1[]
    exceptions
    others = 1.
    endform.
    FORM END_OF_COVERPAGE *
    form end_of_coverpage.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading2[]
    exceptions
    others = 1.
    endform.
    FORM FOREIGN_TOP_OF_PAGE *
    form foreign_top_of_page.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading3[]
    exceptions
    others = 1.
    endform.
    FORM FOREIGN_END_OF_PAGE *
    form foreign_end_of_page.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading4[]
    exceptions
    others = 1.
    endform.
    FORM LIST_MODIFY *
    *FORM LIST_MODIFY.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
    IT_LIST_COMMENTARY = HEADING5[]
    EXCEPTIONS
    OTHERS = 1.
    *ENDFORM.
    FORM END_OF_PAGE *
    form end_of_page.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading6[]
    exceptions
    others = 1.
    endform.
    FORM END_OF_LIST *
    form end_of_list.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading7[]
    exceptions
    others = 1.
    endform.
    FORM TOP_OF_LIST *
    form top_of_list.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading8[]
    exceptions
    others = 1.
    endform.
    *--- End of Program
    Thanks,
    Shankar

  • How to update field values in a database table using module pool prg?

    hi
    how to update field values in a database table using module pool prg?
    we created a customized table, and we put 2 push buttons in screen painter update and display.
    but update is not working?
    data is enter into screen fields and to internal table, but it is not updated in database table.
    thanks in adv
    vidya

    HI,
    we already used the update statement. but its not working.
    plz check this.
    *& Module Pool       ZCUST_CALL_REC
    PROGRAM  ZCUST_CALL_REC.
    TABLES: ZCUST_CALL_REC,ZREMARKS.
    data:  v_kun_low like ZCUST_CALL_REC-kunnr ,
           v_kun_high like ZCUST_CALL_REC-kunnr,
           v_bud_low like ZCUST_CALL_REC-budat,
           v_bud_high like ZCUST_CALL_REC-budat.
    ranges r_kunnr for ZCUST_CALL_REC-kunnr  .
    ranges r_budat for zcust_call_rec-budat.
    DATA: ITAB TYPE STANDARD TABLE OF ZCUST_CALL_REC WITH HEADER LINE,
          JTAB TYPE STANDARD TABLE OF ZREMARKS WITH HEADER LINE.
    *data:begin of itab occurs 0,
        MANDT LIKE ZCUST_CALL_REC-MANDT,
        kunnr like ZCUST_CALL_REC-kunnr,
        budat like ZCUST_CALL_REC-budat,
        code like ZCUST_CALL_REC-code,
        remarks like ZCUST_CALL_REC-remarks,
        end of itab.
    *data:begin of Jtab occurs 0,
        MANDT LIKE ZCUST_CALL_REC-MANDT,
        kunnr like ZCUST_CALL_REC-kunnr,
        budat like ZCUST_CALL_REC-budat,
        code like ZCUST_CALL_REC-code,
        remarks like ZCUST_CALL_REC-remarks,
        end of Jtab.
    CONTROLS:vcontrol TYPE TABLEVIEW USING SCREEN '9001'.
    CONTROLS:vcontrol1 TYPE TABLEVIEW USING SCREEN '9002'.
    *start-of-selection.
    *&      Module  USER_COMMAND_9000  INPUT
          text
    MODULE USER_COMMAND_9000 INPUT.
    CASE sy-ucomm.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
    SET SCREEN 0.
    LEAVE SCREEN.
    CLEAR sy-ucomm.
    WHEN 'ENQUIRY'.
    perform multiple_selection.
    perform append_CUSTOMER_code.
    PERFORM SELECT_DATA.
    call screen '9001'.
    WHEN 'UPDATE'.
          perform append_CUSTOMER_code.
          PERFORM SELECT_DATA.
          call screen '9002'.
          perform update on commit.
    WHEN 'DELETE'.
          perform append_CUSTOMER_code.
          PERFORM SELECT_DATA.
          call screen '9002'.
    ENDCASE.
    ENDMODULE.                 " USER_COMMAND_9000  INPUT
    *&      Module  STATUS_9000  OUTPUT
          text
    MODULE STATUS_9000 OUTPUT.
      SET PF-STATUS 'ZCUSTOMER'.
    SET TITLEBAR 'xxx'.
    ENDMODULE.                 " STATUS_9000  OUTPUT
    *&      Module  USER_COMMAND_9001  INPUT
          text
    MODULE USER_COMMAND_9001 INPUT.
    CASE sy-ucomm.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
    SET SCREEN 0.
    LEAVE SCREEN.
    CLEAR sy-ucomm.
    endcase.
    ENDMODULE.                 " USER_COMMAND_9001  INPUT
    *&      Module  STATUS_9001  OUTPUT
          text
    MODULE STATUS_9001 OUTPUT.
      SET PF-STATUS 'ZCUSTOMER'.
    SET TITLEBAR 'xxx'.
    move itab-MANDT   to zcust_call_rec-MANDT.
    move itab-kunnr   to zcust_call_rec-kunnr.
    move itab-budat   to zcust_call_rec-budat.
    move itab-code    to zcust_call_rec-code.
    move itab-remarks to zcust_call_rec-remarks.
    vcontrol-lines = sy-dbcnt.
    ENDMODULE.                 " STATUS_9001  OUTPUT
    *&      Module  USER_COMMAND_9002  INPUT
          text
    module  USER_COMMAND_9002 input.
    CASE sy-ucomm.
       WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
          SET SCREEN 0.
          LEAVE SCREEN.
          CLEAR sy-ucomm.
       WHEN 'UPDATE'.
             perform move_data.
         UPDATE ZCUST_CALL_REC FROM TABLE ITAB.
            IF SY-SUBRC = 0.
               MESSAGE I000(0) WITH 'RECORDS ARE UPDATED'.
             ELSE.
               MESSAGE E001(0) WITH 'RECORDS ARE NOT UPDATED'.
            ENDIF.
      WHEN 'DELETE'.
             perform move_data.
             DELETE ZCUST_CALL_REC FROM TABLE ITAB.
              IF SY-SUBRC = 0.
               MESSAGE I000(0) WITH 'RECORDS ARE DELETED'.
             ELSE.
               MESSAGE E001(0) WITH 'RECORDS ARE NOT DELETED'.
            ENDIF.
    endcase.
    endmodule.                 " USER_COMMAND_9002  INPUT
    *&      Module  STATUS_9002  OUTPUT
          text
    module STATUS_9002 output.
      SET PF-STATUS 'ZCUSTOMER1'.
    SET TITLEBAR 'xxx'.
    endmodule.                 " STATUS_9002  OUTPUT
    *&      Module  update_table  OUTPUT
          text
    module update_table output.
         move itab-MANDT   to zcust_call_rec-MANDT.
         move itab-kunnr   to zcust_call_rec-kunnr.
         move itab-budat   to zcust_call_rec-budat.
         move itab-code    to zcust_call_rec-code.
         move itab-remarks to zcust_call_rec-remarks.
    vcontrol-lines = sy-dbcnt.
    endmodule.                 " update_table  OUTPUT
    ***Selection Data
    FORM SELECT_DATA.
    SELECT  mandt kunnr budat code remarks  FROM zcust_call_rec INTO
                            table itab
                             WHERE kunnr IN r_kunnr AND BUDAT IN R_BUDAT.
    ENDFORM.
    ****append vendor code
    FORM APPEND_CUSTOMER_CODE.
    clear r_kunnr.
    clear itab.
    clear r_budat.
    refresh r_kunnr.
    refresh itab.
    refresh r_kunnr.
    IF r_kunnr  IS INITIAL
                  AND NOT v_kun_low IS INITIAL
                   AND NOT v_kun_high IS INITIAL.
                        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                                    EXPORTING
                                       input         = v_kun_low
                                    IMPORTING
                                       OUTPUT        = r_kunnr-low.
                       CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                                  EXPORTING
                                      input         = v_kun_high
                                  IMPORTING
                                      OUTPUT        = r_kunnr-high.
                     r_kunnr-option = 'BT'.
                     r_kunnr-sign = 'I'.
                     append r_kunnr.
       PERFORM V_BUDAT.
    ELSEIF r_kunnr  IS INITIAL
                  AND NOT v_kun_low IS INITIAL
                   AND  v_kun_high IS INITIAL.
                        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                                    EXPORTING
                                       input         = v_kun_low
                                    IMPORTING
                                       OUTPUT        = r_kunnr-low.
                    r_kunnr-SIGN = 'I'.
                    r_kunnr-OPTION = 'EQ'.
                    APPEND r_kunnr.
       PERFORM V_BUDAT.
    ELSEIF r_kunnr IS INITIAL
                  AND  v_kun_low IS INITIAL
                   AND NOT v_kun_high IS INITIAL.
                        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                                    EXPORTING
                                       input         = v_kun_low
                                    IMPORTING
                                       OUTPUT        = r_kunnr-low.
                    r_kunnr-SIGN = 'I'.
                    r_kunnr-OPTION = 'EQ'.
                    APPEND r_kunnr.
          PERFORM V_BUDAT.
    ELSEIF r_kunnr IS INITIAL
                  AND  v_kun_low IS INITIAL
                   AND  v_kun_high IS INITIAL.
                        IF SY-SUBRC = 0.
                             MESSAGE I003(0) WITH 'ENTER CUSTOMER NUMBER'.
                              CALL SCREEN '9000'.
                        ENDIF.
    PERFORM V_BUDAT.
    ENDIF.
    ENDFORM.
    FORM V_BUDAT.
    IF  R_BUDAT IS INITIAL
                   AND NOT v_BUD_low IS INITIAL
                   AND NOT v_BUD_high IS INITIAL.
                     r_budat-low = v_bud_low.
                     r_budat-high = v_bud_high.
                     r_budat-option = 'BT'.
                     r_budat-sign = 'I'.
                     append r_budat.
             ELSEIF  R_BUDAT IS INITIAL
                   AND NOT v_BUD_low IS INITIAL
                   AND  v_BUD_high IS INITIAL.
                     r_budat-low = v_bud_low.
                     r_budat-high = v_bud_high.
                     r_budat-option = 'EQ'.
                     r_budat-sign = 'I'.
                     append r_budat.
             ELSEIF  R_BUDAT IS INITIAL
                   AND  v_BUD_low IS INITIAL
                   AND NOT v_BUD_high IS INITIAL.
                     r_budat-HIGH = v_bud_HIGH.
                     r_budat-option = 'EQ'.
                     r_budat-sign = 'I'.
                     append r_budat.
              ELSEIF  R_BUDAT IS INITIAL
                   AND  v_BUD_low IS INITIAL
                   AND  v_BUD_high IS INITIAL.
                   IF SY-SUBRC = 0.
                       MESSAGE I002(0) WITH 'ENTER POSTING DATE'.
                      CALL SCREEN '9000'.
                    r_budat-low = ''.
                    r_budat-option = ''.
                    r_budat-sign = ''.
                    ENDIF.
            ENDIF.
    ENDFORM.
    *&      Form  update
          text
    -->  p1        text
    <--  p2        text
    form update .
    commit work.
    endform.                    " update
    *&      Form  move_data
          text
    -->  p1        text
    <--  p2        text
    form move_data .
       clear itab.
      refresh itab.
           move-corresponding  zcust_call_rec to itab.
           MOVE ZCUST_CALL_REC-MANDT   TO ITAB-MANDT.
           MOVE ZCUST_CALL_REC-KUNNR   TO ITAB-KUNNR.
           MOVE ZCUST_CALL_REC-BUDAT   TO ITAB-BUDAT.
           MOVE ZCUST_CALL_REC-CODE    TO ITAB-CODE.
           MOVE ZCUST_CALL_REC-REMARKS TO ITAB-REMARKS.
         APPEND ITAB.
         delete itab where kunnr is initial.
    endform.                    " move_data
    thanks in adv
    vidya

  • How to update the database table using webdynpro??

    Hi,
    Can anybody helm me in updating database table....by entering the values on the output screen of webdynpro component??should i use any commit statement in function module ,which i used to update.

    hi martina....
    consider you are having two input fields bound to attr1 and attr2.
    now after pressing the save button:
    just read teh two attributes to field1, field2 using code wizard. then
    <db name>-<fieldname1> = <field1>.
    <db name>-<fieldname2> = <field2>.
    insert <dbname>.
    ---regards,
       alex b justin

  • How to use ALV Grid?

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

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

  • Updating a table through ALV

    Hi all,
    I have one requirement.
    I need to display output using alv grid display.Next when somebody select the rows in the grid display and press a push button then the selected fields are updated in the ztable created.
    How can i achieve this.
    How to get a push button on the alv.
    how to update the the table with the selected rows.
    Please give some suggestions for this.
    Thanks to all in advance.

    CHk this program...
    U have to mention button names in PF-status creation
    REPORT  ZVA0T_PRCTR_FAL NO STANDARD PAGE HEADING MESSAGE-ID RA.
                              Modification Log                           *
    Program Name  : ZVA0T_PRCTR_FAL                                      *
    Author        : Suman K                                              *
    Date Written  : 04/27/2004                                           *
    Request #     : SAGK901471                                           *
    Requested by  : Torrence Roundtree                                   *
    Description   : This program is for maintainance of table            *
                    ZVA0T_PRCTR_FAL. The program has been copied from    *
                    custom program named ZSSVT_USR_TBL_MAINTENANCE and   *
                    done with essential changes to include table         *
                    ZVA0T_PRCTR_FAL and selection screen options. The    *
                    existing program documentation is as below           *
    Program Specifications:                                              *
    Mod date  Programmer        Reference    Description                 *
    *04/27/2005 Suman K           SAGK901471   Initial Development         *
    Type pools                                                           *
    TYPE-POOLS : slis.                     " Used for ALV display
    Tables
    TABLES: ZVA0T_PRCTR_FAL .              " LO43 Profit Center Listings
    Constants
    CONSTANTS:
    For authorization check for modifying Table Entries
      c_act_auth_01 LIKE tactz-actvt VALUE '01',
      c_act_auth_02 LIKE tactz-actvt VALUE '02',
      c_act_auth_06 LIKE tactz-actvt VALUE '06',
      c_table       LIKE dd02l-tabname VALUE 'ZVA0T_PRCTR_FAL',
                                           " Table name
      c_save        TYPE c VALUE 'A',      " Save
      c_chg(3)      TYPE c VALUE 'CHG',    " Change Group
      c_a           TYPE c VALUE 'A',      " Cancel Indicator
      c_ct(2)       TYPE c VALUE 'CT'.     " Style Name
    Work Variables declaration
    DATA:
      w_transaction_code LIKE tstc-tcode,  " Transaction Code
      w_variant          TYPE disvariant,  " Variant
      ok_code            LIKE sy-ucomm.    " OK Code
    Reference variables for the ALV grid control........................
    DATA:
      w_grid TYPE REF TO cl_gui_alv_grid,  " ALV Grid
      w_custom_container TYPE REF TO cl_gui_custom_container.
                                           " Reference to Container
    Variables used in User_command_0100
    DATA:
      w_confirm_ind    TYPE c,             " Deletion Indicator
      W_SUBRC          LIKE SY-SUBRC.      " Subrc
    Flag declaration
    DATA:
      fl_chng   TYPE c,                    " Flag
      fl_cancel TYPE c.                    " Flag
    Internal tables declaration
    To store the function codes.........................................
    DATA:
      BEGIN OF wa_fcode,
        fcode LIKE sy-ucomm,               " User Command
      END OF wa_fcode.
    Table for User Command
    DATA: t_fcode LIKE STANDARD TABLE OF wa_fcode.
    To store the data of ZVA0T_PRCTR_FAL table
    DATA:
      T_ZVA0T_PRCTR_FAL LIKE STANDARD TABLE
                          OF ZVA0T_PRCTR_FAL.
    Table used in User_command_0100
    DATA:
      t_selected_rows  TYPE lvc_t_row.     " Selected row information
    DATA:
      FS_SELECTED_ROWS LIKE LINE OF T_SELECTED_ROWS.
                                           " Work area for Selected Rows
    Selection screen elements
    SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE text-008.
    SELECT-OPTIONS:
      s_prctr FOR ZVA0T_PRCTR_FAL-leg_prctr.
                                           " Profit Center
    SELECTION-SCREEN: END OF BLOCK blk1.
    SELECTION-SCREEN: BEGIN OF BLOCK blk2 WITH FRAME TITLE text-009.
    PARAMETERS:
      p_varant  LIKE ltdx-variant.         " ALV variant
    SELECTION-SCREEN: END OF BLOCK blk2.
    Initialization
    INITIALIZATION.
    Authorization check for transaction code
      SELECT tcode
        FROM tstc
        INTO w_transaction_code
          UP TO 1 ROWS
       WHERE pgmna EQ sy-repid.
      ENDSELECT.
      IF sy-subrc EQ 0.
        AUTHORITY-CHECK OBJECT 'S_TCODE'
                     ID 'TCD' FIELD w_transaction_code.
        IF sy-subrc NE 0.
          MESSAGE e100 WITH text-e01 w_transaction_code.
        ENDIF.                             " IF SY-SUBRC NE 0
      ENDIF.                               " IF SY-SUBRC EQ 0
    At selection screen                                                 *
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_varant.
    to get the existing values for the display variant
      PERFORM f4_on_display_variant CHANGING p_varant.
    AT SELECTION-SCREEN ON p_varant.
    validates the diplay variant
      IF p_varant IS NOT INITIAL.
        PERFORM validate_variant.
      ENDIF.                               " IF P_VARANT IS NOT INITIAL
    Start Of Selection
    START-OF-SELECTION.
      CALL SCREEN 0100.
    *&      Form  f4_on_display_variant
    This subroutine is used to get the existing values for display variant
    The parameter passed to the subroutine is Variant parameter
    FORM f4_on_display_variant CHANGING p_varant TYPE any.
      DATA: lw_variant LIKE disvariant.    " Variant
      lw_variant-report   = sy-repid.
      lw_variant-username = sy-uname.
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
        EXPORTING
          is_variant = lw_variant
          i_save     = c_save
        IMPORTING
          es_variant = lw_variant
        EXCEPTIONS
          OTHERS     = 1.
      IF sy-subrc EQ 0.
        p_varant = lw_variant-variant.
      ELSE.
        MESSAGE s100 WITH text-012.
      ENDIF.                               " IF SY-SUBRC EQ 0
    ENDFORM.                               " F4_ON_DISPLAY_VARIANT
    *&      Form  validate_variant
    This subroutine validates the variant entered onthe selection screen
    There are no interface parameters to be passed to the subroutine
    FORM validate_variant .
      CLEAR w_variant.
      w_variant-report = sy-repid.
      MOVE p_varant TO w_variant-variant.
      CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
        EXPORTING
          i_save        = c_save
        CHANGING
          cs_variant    = w_variant
        EXCEPTIONS
          wrong_input   = 1
          not_found     = 2
          program_error = 3
          OTHERS        = 4.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.                               " IF SY-SUBRC <> 0
    ENDFORM.                               " VALIDATE_VARIANT
    *&      Module  STATUS_0100  OUTPUT
    This is the PBO module for the ALV GRid dispaly
    MODULE status_0100 OUTPUT.
    Check the User authorizations and display the PF status accordingly
      PERFORM check_authorizations.
    Set the user status as per Authorizations
      SET PF-STATUS 'ZVA0T_PRCTR_FAL' EXCLUDING t_fcode.
      SET TITLEBAR 'ZVA0T_PRCTR_FAL'.
    Instantiate the container control and Grid control.
      IF w_custom_container IS INITIAL.
        CREATE OBJECT w_custom_container
           EXPORTING
              container_name = 'CUSTOM_CONTAINER'.
        CREATE OBJECT w_grid
           EXPORTING
             i_parent = w_custom_container.
      ENDIF.                               " IF W_CUSTOM_CONTAINER IS ...
    Clearing the work variables
      PERFORM intialize.
    Retrieve the table contents
      PERFORM get_data.
    Display the data in the ALV Grid control
      PERFORM display_data.
    ENDMODULE.                             " STATUS_0100  OUTPUT
    *&      Form  check_authorizations
    This subroutine is used to check the user authorizations
    There are no interface parameters to be passed
    FORM check_authorizations .
      REFRESH t_fcode.
    Authorization check for Create entry
      AUTHORITY-CHECK OBJECT 'ZZ:TABLMNP'
               ID 'ACTVT' FIELD c_act_auth_01
               ID 'TABLE' FIELD c_table.
      IF sy-subrc NE 0.
        PERFORM fillcode USING 'CREA'.
        PERFORM fillcode USING 'COPY'.
      ENDIF.                               " IF SY-SUBRC NE 0
    Authorization check for Change the entry
      AUTHORITY-CHECK OBJECT 'ZZ:TABLMNP'
               ID 'ACTVT' FIELD c_act_auth_02
               ID 'TABLE' FIELD c_table.
      IF sy-subrc NE 0.
        PERFORM fillcode USING 'CHNG'.
      ENDIF.                               " IF SY-SUBRC NE 0
    Authorization check for Delete the entry
      AUTHORITY-CHECK OBJECT 'ZZ:TABLMNP'
               ID 'ACTVT' FIELD c_act_auth_06
               ID 'TABLE' FIELD c_table.
      IF sy-subrc NE 0.
        PERFORM fillcode USING 'DELE'.
      ENDIF.                               " IF SY-SUBRC NE 0
    ENDFORM.                               " CHECK_AUTHORIZATIONS
    *&      Form  fillcode
    This subroutine is used to fill the function code in the table t_fcode
    The parameter that passed to this subroutine is function code
    FORM fillcode  USING    value(p_fcode) TYPE any.
      CLEAR wa_fcode.
      MOVE p_fcode TO wa_fcode-fcode.
      APPEND wa_fcode TO t_fcode.
    ENDFORM.                               " FILLCODE
    *&      Form  intialize
    This subroutine is used to initialize the work variables
    There are no interface parameters that need to be passed
    FORM intialize .
      CLEAR   t_ZVA0T_PRCTR_FAL.
      REFRESH t_ZVA0T_PRCTR_FAL.
    ENDFORM.                               " INITIALIZE
    *&      Form  get_data
    This subroutine is used to get data from the table
    There are no interfaces parameters that need to be passed
    FORM get_data .
    retrieve the status and codegroup from the table
      REFRESH t_ZVA0T_PRCTR_FAL.
      SELECT *
        FROM ZVA0T_PRCTR_FAL
        INTO TABLE t_ZVA0T_PRCTR_FAL
       WHERE leg_prctr IN s_prctr.
      IF sy-subrc NE 0.
      ENDIF.                               " IF SY-SUBRC NE 0
    ENDFORM.                               " GET_DATA
    *&      Form  display_data
    This subroutine is used to display the data in the ALV Grid control
    *There are no interface parameters that need to be passed to subroutine
    FORM display_data .
      DATA:
        w_grid_layout TYPE lvc_s_layo,     " Grid Layout
        LT_fieldcat   TYPE lvc_t_fcat.     " Field Catalog
      DATA:
        FS_FIELDCAT LIKE LINE OF LT_FIELDCAT.
    Filling the Layout
      w_grid_layout-grid_title = text-001.
      w_grid_layout-sel_mode   = c_save.
      w_grid_layout-stylefname = c_ct.
      w_grid_layout-cwidth_opt = 'X'.
    Filling the Variant structure
      w_variant-report   = sy-repid.
      w_variant-username = sy-uname.
      w_variant-variant  = p_varant.
    Filling the fieldcatalog.............................................
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name = c_table
        CHANGING
          ct_fieldcat      = lt_fieldcat.
    To make the ALV list use the medium text label from DDIC
      LOOP AT lt_fieldcat INTO FS_FIELDCAT.
        MOVE 'M' TO fs_fieldcat-colddictxt.
        MODIFY lt_fieldcat FROM FS_FIELDCAT.
      ENDLOOP.                             " LOOP AT T_FIELDCAT
      CALL METHOD w_grid->set_table_for_first_display
        EXPORTING
          i_structure_name              = c_table
          is_variant                    = w_variant
          i_save                        = c_save
          is_layout                     = w_grid_layout
        CHANGING
          it_outtab                     = t_ZVA0T_PRCTR_FAL
          it_fieldcatalog               = lt_fieldcat
        EXCEPTIONS
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          OTHERS                        = 4.
      IF sy-subrc NE 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.                               " IF SY-SUBRC NE 0
    ENDFORM.                               " DISPLAY_DATA
    *&      Module  USER_COMMAND_0100  INPUT
    This is the PAI module for the screen 100.
    MODULE user_command_0100 INPUT.
      REFRESH t_selected_rows.
      CLEAR   FS_SELECTED_ROWS.
      CLEAR fl_chng.
    Getting the selected rows
      CALL METHOD w_grid->get_selected_rows
        IMPORTING
          et_index_rows = t_selected_rows.
    If more than one record is selected, error message
      DESCRIBE TABLE t_selected_rows.
      IF sy-tfill GT 1
      AND SY-UCOMM NE 'REFR'
      AND SY-UCOMM NE 'CREA'
      AND SY-UCOMM NE 'DELE'.
        MESSAGE e048(zcsv_sfdr).
      ENDIF.                               " IF SY-TFILL GT 1
    Read the first record
      READ TABLE t_selected_rows INTO FS_SELECTED_ROWS INDEX 1.
      READ TABLE t_ZVA0T_PRCTR_FAL
            INTO ZVA0T_PRCTR_FAL INDEX fs_selected_rows-index.
      CLEAR W_SUBRC.
      W_SUBRC = SY-SUBRC.
      CASE ok_code.
        WHEN 'CREA'.
          CLEAR ZVA0T_PRCTR_FAL.
          CALL SCREEN 0200.
        WHEN 'COPY'.
          IF W_SUBRC EQ 0.
            IF t_selected_rows IS NOT INITIAL.
              CALL SCREEN 0200.
            ELSE.
              MESSAGE e100 WITH text-013.
            ENDIF.                         " IF T_SELECTED_ROWS IS NOT ...
          ELSE.
            MESSAGE e100 WITH text-014.
          ENDIF.                           " IF W_SUBRC EQ 0
        WHEN 'CHNG'.
          IF W_SUBRC EQ 0.
            MOVE 'X' TO fl_chng.
            IF t_selected_rows IS NOT INITIAL.
              CALL SCREEN 0200.
            ELSE.
              MESSAGE e100 WITH text-e04.
            ENDIF.                         " IF T_SELECTED_ROWS IS NOT ...
          ELSE.
            MESSAGE e100 WITH text-014.
          ENDIF.                           " IF W_SUBRC EQ 0
        WHEN 'DELE'.
          IF t_selected_rows IS NOT INITIAL.
            IF W_SUBRC EQ 0.
              CALL FUNCTION 'POPUP_TO_CONFIRM'
                EXPORTING
                  titlebar              = text-002
                  text_question         = text-003
                  text_button_1         = text-004
                  text_button_2         = text-005
                  default_button        = '1'
                  display_cancel_button = 'X'
                IMPORTING
                  answer                = w_confirm_ind.
              IF w_confirm_ind EQ '1'.
                LOOP AT T_SELECTED_ROWS INTO FS_SELECTED_ROWS.
                  CLEAR ZVA0T_PRCTR_FAL.
                  READ TABLE T_ZVA0T_PRCTR_FAL
                        INTO ZVA0T_PRCTR_FAL INDEX fs_selected_rows-index.
                  IF SY-SUBRC EQ 0.
                    DELETE ZVA0T_PRCTR_FAL.
                    IF sy-subrc NE 0.
                      W_SUBRC = 4.
                    ENDIF.                 " IF SY-SUBRC EQ 0
                  ENDIF.                   " IF SY-SUBRC EQ 0
                ENDLOOP.                   " LOOP AT T_SELECTED_ROWS ...
                IF W_SUBRC EQ 0.
                  MESSAGE s100 WITH text-010.
                ELSE.
                  MESSAGE   e100 WITH text-e03.
                ENDIF.                     " IF W_SUBRC EQ 0
              ELSEIF w_confirm_ind EQ '2'.
              ENDIF.                       " IF W_CONFIRM_IND EQ '1'
            ELSE.
              MESSAGE e100 WITH text-014.
            ENDIF.                         " IF W_SUBRC EQ 0
          ELSE.
            MESSAGE e100 WITH text-e05.
          ENDIF.                           " IF T_SELECTED_ROWS IS NOT ...
        WHEN 'BACK'.
          SET SCREEN 0.
          LEAVE SCREEN.
        WHEN 'CANCEL'.
          SET SCREEN 0.
          LEAVE SCREEN.
      ENDCASE.                             " CASE OK_CODE
      CLEAR ok_code.
    ENDMODULE.                             " USER_COMMAND_0100  INPUT
    *&      Module  exit  INPUT
    This subroutine is used to leave the current screen
    MODULE exit INPUT.
      CALL METHOD w_custom_container->free.
      CALL METHOD cl_gui_cfw=>flush.
      SET SCREEN 0.
      LEAVE SCREEN.
    ENDMODULE.                             " EXIT  INPUT
    *&      Module  STATUS_0200  OUTPUT
    This module is used to set the PF Status of the modify screen
    MODULE status_0200 OUTPUT.
      SET PF-STATUS 'STATUS_200'.
    ENDMODULE.                             " STATUS_0200  OUTPUT
    *&      Module  modify_0200  OUTPUT
    This module is used to print the values on the screen
    MODULE modify_0200 OUTPUT.
      IF NOT fl_chng IS INITIAL.
        LOOP AT SCREEN.
          IF screen-group1 EQ c_chg.
            screen-required = '0'.
            screen-output   = '1'.
            screen-input    = '0'.
            MODIFY SCREEN.
          ENDIF. 
        ENDLOOP.                           " LOOP AT SCREEN
      ELSE.
        LOOP AT SCREEN.
          IF screen-group1 EQ c_chg.
            screen-required = '1'.
            screen-output   = '1'.
            screen-input    = '1'.
            MODIFY SCREEN.
          ENDIF. 
        ENDLOOP.                           " LOOP AT SCREEN
      ENDIF.                               " IF NOT FL_CHNG IS INITIAL
    ENDMODULE.                             " MODIFY_0200  OUTPUT
    *&      Module  exit_0200  INPUT
    This module is used to exit from the screen on pressing exit button
    MODULE exit_0200 INPUT.
      IF sy-datar IS INITIAL
      AND fl_cancel IS INITIAL.
        CLEAR fl_chng.
        LEAVE PROGRAM.
      ELSE.
        CALL FUNCTION 'POPUP_TO_CONFIRM'
          EXPORTING
            titlebar              = text-011
            text_question         = text-006
            text_button_1         = text-004
            text_button_2         = text-005
            default_button        = '1'
            display_cancel_button = 'X'
          IMPORTING
            answer                = w_confirm_ind.
        CASE w_confirm_ind.
          WHEN '1'.
            sy-ucomm = 'SAVE'.
            CLEAR fl_cancel.
          WHEN '2'.
            CLEAR fl_chng.
            CLEAR fl_cancel.
            LEAVE PROGRAM.
          WHEN c_a.
            fl_cancel = 'X'.
        ENDCASE.                           " CASE W_CONFIRM_IND
      ENDIF.                               " IF SY-DATAR IS INITIAL
    ENDMODULE.                             " EXIT_0200  INPUT
    *&      Module  USER_COMMAND_0200  INPUT
    This module is used to update the database table with the user values
    MODULE user_command_0200 INPUT.
      IF sy-ucomm EQ 'SAVE'.
        PERFORM SAVE.
      ELSEIF SY-UCOMM EQ 'BACK'.
        PERFORM BACK_CANCEL.
        IF SY-UCOMM EQ 'SAVE'.
          PERFORM SAVE.                    " IF SY-UCOMM EQ 'SAVE'
        ENDIF.
      ELSEIF SY-UCOMM EQ 'CANC'.
        PERFORM BACK_CANCEL.
        IF SY-UCOMM EQ 'SAVE'.
          PERFORM SAVE.                    " IF SY-UCOMM EQ 'SAVE'
        ENDIF.
      ELSEIF SY-UCOMM EQ 'ENTE'.
        fl_cancel = 'X'.
      ENDIF.                               " IF SY-UCOMM EQ 'SAVE'
    ENDMODULE.                             " USER_COMMAND_0200  INPUT
    *&      Form  BACK_CANCEL
    This subroutine provides functionality for BACK & CANCEL
    form BACK_CANCEL .
      IF sy-datar IS INITIAL
      AND fl_cancel IS INITIAL.
        CLEAR fl_chng.
        SET SCREEN 0.
        LEAVE SCREEN.
      ELSE.
        CALL FUNCTION 'POPUP_TO_CONFIRM'
          EXPORTING
            titlebar              = text-011
            text_question         = text-006
            text_button_1         = text-004
            text_button_2         = text-005
            default_button        = '1'
            display_cancel_button = 'X'
          IMPORTING
            answer                = w_confirm_ind.
        CASE w_confirm_ind.
          WHEN '1'.
            sy-ucomm = 'SAVE'.
            CLEAR fl_cancel.
          WHEN '2'.
            CLEAR fl_chng.
            CLEAR fl_cancel.
            SET SCREEN 0.
            LEAVE SCREEN.
          WHEN 'A'.
            fl_cancel = 'X'.
        ENDCASE.                           " CASE W_CONFIRM_IND
      ENDIF.                               " IF SY-DATAR IS INITIAL
    endform.                               " BACK_CANCEL
    *&      Form  SAVE
    This subroutine provides functionality for SAVE
    form SAVE .
        MOVE:
          SY-DATUM TO ZVA0T_PRCTR_FAL-erdat,
          SY-UZEIT TO ZVA0T_PRCTR_FAL-erzet,
          SY-UNAME TO ZVA0T_PRCTR_FAL-ernam.
        IF fl_chng IS INITIAL.
          INSERT ZVA0T_PRCTR_FAL.
          IF sy-subrc EQ 0.
            MESSAGE s100 WITH text-010.
          ELSE.
            MESSAGE e100 WITH text-e03.
          ENDIF.                           " IF SY-SUBRC EQ 0
        ELSE.
          MODIFY ZVA0T_PRCTR_FAL.
          IF sy-subrc EQ 0.
            MESSAGE s100 WITH text-010.
          ELSE.
            MESSAGE e100 WITH text-e03.
          ENDIF.                           " IF SY-SUBRC EQ 0
          CLEAR t_ZVA0T_PRCTR_FAL.
        ENDIF.                             " IF FL_CHNG IS INITIAL
        SET SCREEN 0.
        LEAVE SCREEN.
    endform.                               " SAVE
    Reward if helpful...

  • F4 Help in ALV GRID class based

    hi
    you have any idea about how to invoke the F4 help in ALV GRID Class based program.,
    if u have any other related document or program using F4 function in ALV GRId please send to me for reference
    Thanks & Regards
    K.G

    hi for what kind of fields you need to give f4.
    are they std or custom...
    please let me know about the fields..
    try to check my logic which i gave in the below post..
    it will give f4 help to the fields(if thet are standard table fieldS)
    Message was edited by: Vijay Babu Dudla

  • Using ALV Grid for data Input

    Hi experts.
    Can someone assist me with information on using ALV grid for data input. Please give a simple example if possible.
    I am mainly interested in the part in which we can transfer data from the grid changing the internal table's data.

    Try this code:
    REPORT z_demo_alv_jg.
    TYPE-POOLS                                                          *
    TYPE-POOLS: slis.
    INTERNAL TABLES/WORK AREAS/VARIABLES                                *
    DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
          i_index TYPE STANDARD TABLE OF i WITH HEADER LINE,
          w_field TYPE slis_fieldcat_alv,
          p_table LIKE dd02l-tabname,
          dy_table TYPE REF TO data,
          dy_tab TYPE REF TO data,
          dy_line TYPE REF TO data.
    FIELD-SYMBOLS                                                       *
    FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
                   <dyn_wa> TYPE ANY,
                   <dyn_field> TYPE ANY,
                   <dyn_tab_temp> TYPE STANDARD TABLE.
    SELECTION SCREEN                                                    *
    PARAMETERS: tabname(30) TYPE c,
                lines(5)  TYPE n.
    START-OF-SELECTION                                                  *
    START-OF-SELECTION.
    Storing table name
      p_table = tabname.
    Create internal table dynamically with the stucture of table name
    entered in the selection screen
      CREATE DATA dy_table TYPE STANDARD TABLE OF (p_table).
      ASSIGN dy_table->* TO <dyn_table>.
      IF sy-subrc <> 0.
        MESSAGE i000(z_zzz_ca_messages) WITH ' No table found'.
        LEAVE TO LIST-PROCESSING.
      ENDIF.
    Create workarea for the table
      CREATE DATA dy_line LIKE LINE OF <dyn_table>.
      ASSIGN dy_line->* TO <dyn_wa>.
    Create another temp. table
      CREATE DATA dy_tab TYPE STANDARD TABLE OF (p_table).
      ASSIGN dy_tab->* TO <dyn_tab_temp>.
      SORT i_fieldcat BY col_pos.
    Select data from table
      SELECT * FROM (p_table)
      INTO TABLE <dyn_table>
      UP TO lines ROWS.
      REFRESH <dyn_tab_temp>.
    Display report
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          i_callback_program       = sy-repid
          i_structure_name         = p_table
          i_callback_user_command  = 'USER_COMMAND'
          i_callback_pf_status_set = 'SET_PF_STATUS'
        TABLES
          t_outtab                 = <dyn_table>
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
      IF sy-subrc <> 0.
      ENDIF.
    *&      Form  SET_PF_STATUS
          Setting custom PF-Status
         -->RT_EXTAB   Excluding table
    FORM set_pf_status USING rt_extab TYPE slis_t_extab.
      SET PF-STATUS 'Z_STANDARD'.
    ENDFORM.                    "SET_PF_STATUS
    *&      Form  user_command
          Handling custom function codes
         -->R_UCOMM      Function code value
         -->RS_SELFIELD  Info. of cursor position in ALV
    FORM user_command  USING    r_ucomm LIKE sy-ucomm
                               rs_selfield TYPE slis_selfield.
    Local data declaration
      DATA: li_tab TYPE REF TO data,
            l_line TYPE REF TO data.
    Local field-symbols
      FIELD-SYMBOLS:<l_tab> TYPE table,
                    <l_wa>  TYPE ANY.
    Create table
      CREATE DATA li_tab TYPE STANDARD TABLE OF (p_table).
      ASSIGN li_tab->* TO <l_tab>.
    Create workarea
      CREATE DATA l_line LIKE LINE OF <l_tab>.
      ASSIGN l_line->* TO <l_wa>.
      CASE r_ucomm.
      When a record is selected
        WHEN '&IC1'.
        Read the selected record
          READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX
          rs_selfield-tabindex.
          IF sy-subrc = 0.
          Store the record in an internal table
            APPEND <dyn_wa> TO <l_tab>.
          Fetch the field catalog info
            CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
              EXPORTING
                i_program_name         = 'Z_DEMO_PDF_JG'
                i_structure_name       = p_table
              CHANGING
                ct_fieldcat            = i_fieldcat
              EXCEPTIONS
                inconsistent_interface = 1
                program_error          = 2
                OTHERS                 = 3.
            IF sy-subrc = 0.
            Make all the fields input enabled except key fields*
              w_field-input = 'X'.
              MODIFY i_fieldcat FROM w_field TRANSPORTING input
              WHERE key IS INITIAL.
            ENDIF.
          Display the record for editing purpose
            CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
              EXPORTING
                i_callback_program    = sy-repid
                i_structure_name      = p_table
                it_fieldcat           = i_fieldcat
                i_screen_start_column = 10
                i_screen_start_line   = 15
                i_screen_end_column   = 200
                i_screen_end_line     = 20
              TABLES
                t_outtab              = <l_tab>
              EXCEPTIONS
                program_error         = 1
                OTHERS                = 2.
            IF sy-subrc = 0.
            Read the modified data
              READ TABLE <l_tab> INDEX 1 INTO <l_wa>.
            If the record is changed then track its index no.
            and populate it in an internal table for future
            action
              IF sy-subrc = 0 AND <dyn_wa> <> <l_wa>.
                <dyn_wa> = <l_wa>.
                i_index = rs_selfield-tabindex.
                APPEND i_index.
              ENDIF.
            ENDIF.
          ENDIF.
      When save button is pressed
        WHEN 'SAVE'.
        Sort the index table
          SORT i_index.
        Delete all duplicate records
          DELETE ADJACENT DUPLICATES FROM i_index.
          LOOP AT i_index.
          Find out the changes in the internal table
          and populate these changes in another internal table
            READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX i_index.
            IF sy-subrc = 0.
              APPEND <dyn_wa> TO <dyn_tab_temp>.
            ENDIF.
          ENDLOOP.
        Lock the table
          CALL FUNCTION 'ENQUEUE_E_TABLE'
            EXPORTING
              mode_rstable   = 'E'
              tabname        = p_table
            EXCEPTIONS
              foreign_lock   = 1
              system_failure = 2
              OTHERS         = 3.
          IF sy-subrc = 0.
          Modify the database table with these changes
            MODIFY (p_table) FROM TABLE <dyn_tab_temp>.
            REFRESH <dyn_tab_temp>.
          Unlock the table
            CALL FUNCTION 'DEQUEUE_E_TABLE'
              EXPORTING
                mode_rstable = 'E'
                tabname      = p_table.
          ENDIF.
      ENDCASE.
      rs_selfield-refresh = 'X'.
    ENDFORM.                    "user_command

  • How to trigger New page while using ALV with classes/oops?

    Hi All
    I am trying to print a report which has to show the data in two pages.
    I am using ALV with classes/oops.
    Though I am able to print the report but a new page is not coming. Whole of the data is coming in one single page.
    Please tell me as to how to trigger a NEW PAGE while using ALV with classes/oops.
    Please send some code samples also if available.
    Thanks in advance.
    Jerry

    using sort option you can do it. in case of grid/oo alv class ALV you can view that only in print mode/preview mode.
    in case of list you can view that directly.
    sort-fieldname = 'FIELDNAME'.
    sort-group = '*'  "triggers new page
    sort-up = 'X'.
    append sort to it_sort.

  • Update database table

    I have 1 million records in application server and I want to update database table from that.
    Is UPDATE statement the best technique to do it.
    Just wanted to know if there is any other better tehcniques.
    Also i want to write the errors to job log. How can we do that?
    Regards,
    DNP

    If they are all new records or all changes, it would be best to use INSERT or UPDATE. You will also want to do mass inserts/changes using an internal table. Since you have so many records, you will probably have to do this in chunks in order to avoid dumping on the rollback area.
    Rob

  • Code to update a table using sqlldr

    Hi all,
    can anybody give the code to update a table using sqlldr with an example
    thank you

    You want add the new line and modified the existing line (based on empno) from file e:\scripts\sql\emp2_ext.dat into table emp2 :
    7782,CLARK,MANAGER,7839,09/06/81,80000,,10
    8000,ORACLE,DATABASE,,11/02/07,99999,,20Then :
    SQL> conn system/mypwd
    Connected.
    SQL>
    SQL> create directory my_dir as 'e:\scripts\sql';
    Directory created.
    SQL>
    SQL> grant read,write on directory my_dir to scott;
    Grant succeeded.
    SQL>
    SQL> conn scott/mypwd
    Connected.
    SQL> create table emp2_ext
      2  (EMPNO    NUMBER(4),
      3   ENAME    VARCHAR2(10),
      4   JOB      VARCHAR2(9),
      5   MGR      NUMBER(4),
      6   HIREDATE DATE,
      7   SAL      NUMBER(7,2),
      8   COMM     NUMBER(7,2),
      9   DEPTNO   NUMBER(2)
    10  )     
    11  ORGANIZATION EXTERNAL
    12  ( TYPE ORACLE_LOADER
    13    DEFAULT DIRECTORY my_dir
    14    ACCESS PARAMETERS
    15    ( records delimited by newline
    16      badfile my_dir:'emp2_ext.bad'
    17      logfile my_dir:'emp2_ext.log'
    18      fields terminated by ','
    19      missing field values are null
    20      ( empno, ename, job, mgr, hiredate char date_format date mask "dd/mm/yy",
    21        sal, comm, deptno
    22      )
    23    ) LOCATION ('emp2_ext.dat')
    24  ) ;
    Table created.
    SQL>
    SQL> select * from emp2_ext;
         EMPNO ENAME      JOB              MGR HIREDATE        SAL       COMM     DEPTNO
          7782 CLARK      MANAGER         7839 09/06/81      80000                    10
          8000 ORACLE     DATABASE             11/02/07      99999                    20
    SQL> select * from emp2;
         EMPNO ENAME      JOB              MGR HIREDATE        SAL       COMM     DEPTNO
          7782 CLARK      MANAGER         7839 09/06/81      24500                    10
          7839 KING       PRESIDENT            17/11/81      50000                    10
          7934 MILLER     CLERK           7782 23/01/82      13000                    10
    SQL> merge into emp2 a
      2  using (select * from emp2_ext) b
      3  on    (a.empno=b.empno)
      4  when matched then update set a.ename=b.ename,
      5                               a.job=b.job,
      6                               a.mgr=b.mgr,
      7                               a.hiredate=b.hiredate,
      8                               a.sal=b.sal,
      9                               a.comm=b.comm,
    10                               a.deptno=b.deptno
    11  when not matched then insert (a.empno, a.ename, a.job, a.mgr, a.hiredate, a.sal, a.comm, a.deptno)
    12                        values (b.empno, b.ename, b.job, b.mgr, b.hiredate, b.sal, b.comm, b.deptno);
    2 rows merged.
    SQL>
    SQL> select * from emp2;
         EMPNO ENAME      JOB              MGR HIREDATE        SAL       COMM     DEPTNO
          7782 CLARK      MANAGER         7839 09/06/81      80000                    10 --modified line
          7839 KING       PRESIDENT            17/11/81      50000                    10
          7934 MILLER     CLERK           7782 23/01/82      13000                    10
          8000 ORACLE     DATABASE             11/02/07      99999                    20 --added line
    SQL> HTH,
    Nicolas.
    Well, Hans has already give good explanation with docs links...
    Message was edited by:
    N. Gasparotto

Maybe you are looking for

  • How can i get currency values from flatfile to function module

    Dear All,            I have to take  currency values from flat file and i have to assign those flat file value to function module . Eg: "Convert_to_local_currency".  I need technical code how to calculate those amount in work area and how to assign t

  • I want iChat back

    I have a problem: iChat stopped working for me, so I deleted it in hopes of reinstalling it. However, the only downloads I find of iChat are just updates. I tried installing my software bundle again, which worked for every other application, but iCha

  • Oracle Enterprise edition 10g features

    Hi Team, customer has a oracle 10g EE at primary. so mu questions related are - Do i require license for a remote standby Lic while replcating using oracle data guard - IS "RMAN" and oracle "enterprise manager" is free in DR Site if i purchase oracle

  • Add new dictionaries or languages to 10.9.2

    Hi, I need to add some Danish-English, English-Danish dictionaries to the native Dictionary app. This was possible in 10.8 and earlier, but now I can't get it to work, or i've forgotten how to. Back in the days, I just download the dictionaries I nee

  • Release strategy in Condition records

    Hello We have a requirement where we can maintain price rates for condition type using VK11 and these rates are audited and released by audit team then only Sales team can use that rates in Sales order. Regards, Nimit