Skip to Content

Edit and Save ALV Display.

Hi All,

I have created a ALV display using the class the class CL_GUI_ALV_GRID. I made one column as editable, when i entered some data and tried to save it, internal table is not updating. So i as not able to update the database table. Always i am getting the message 'No changes were made'. How to update the internal table with new data.

Please let me know how to do it, Thanks in advance.

MODULE user_command_0100 INPUT.

   CASE sy-ucomm.

     WHEN 'BACK' OR 'CANC' OR 'EXIT'.
       LEAVE PROGRAM.
     WHEN 'SAVE'.
       IF it_ivcuscp[] = it_ivcus[].
         MESSAGE 'No changes are made' TYPE 'I'.
       ELSE.
         MESSAGE 'Data Changed' TYPE 'I'.
       ENDIF.

       DATA : wa_ivcuscp     TYPE ty_ivcus.
       DATA : wa_ivcus_tmp TYPE /tli/viv_ivcus.
       CLEAR it_changes[].
       LOOP AT it_ivcus INTO wa_ivcus.
         READ TABLE it_ivcuscp INTO wa_ivcuscp INDEX sy-tabix.
         IF wa_ivcuscp NE wa_ivcus.
           APPEND wa_ivcus TO it_changes.
           MOVE-CORRESPONDING wa_ivcus TO wa_ivcus_tmp.
           wa_ivcus_tmp-bname = sy-uname.
           MODIFY /tli/viv_ivcus FROM wa_ivcus_tmp .
           IF sy-subrc EQ 0.
             MESSAGE 'Data Updated' TYPE 'I'.
           ENDIF.
         ELSE.
 *      MESSAGE 'No Data changed' TYPE 'I'.
         ENDIF.
         CLEAR wa_ivcuscp.      
       ENDLOOP.
   ENDCASE.

 ENDMODULE.

Thanks & regards,

NarsiReddy.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 15, 2015 at 05:07 PM

    hi,

    try this code.

    you are using set table for first table,so set layout for alv like

    is_layout = layo.

    declare check type c in data declaration for internal table.

    then u wil get changed data.

    then loop table where condition check = 'x'.

    use update dbtab set fieldname = column value where cond.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Vinoth,

      I have registered the event in PBO like below.

      CALL METHOD o_grid->register_edit_event
             EXPORTING
               i_event_id = cl_gui_alv_grid=>mc_evt_modified.
      

      In the PAI when user clicks SAVE button, i am capturing the changed data and saving it as below.

      DATA w_valid TYPE char01.
             CALL METHOD o_grid->check_changed_data
               IMPORTING
                 e_valid = w_valid.
      
      
             DATA : wa_ivcuscp     TYPE /tli/viv_ivcus.
             DATA : wa_ivcus_tmp TYPE /tli/viv_ivcus,
                    wa_itab      TYPE /tli/viv_ivcus.
             DATA it_changes TYPE STANDARD TABLE OF /tli/viv_ivcus.
             CLEAR it_changes[].
      
             IF itab_tmp[] NE itab[].
               LOOP AT itab INTO wa_itab.
                 READ TABLE itab_tmp INTO wa_ivcuscp INDEX sy-tabix.
                 IF wa_ivcuscp NE wa_itab.
                   MOVE-CORRESPONDING wa_itab TO wa_ivcus_tmp.
                   wa_ivcus_tmp-bname = sy-uname.
                   wa_ivcus_tmp-/tli/date = sy-datum.
                   wa_ivcus_tmp-time = sy-uzeit.
                   APPEND wa_ivcus_tmp TO it_changes.
                   CLEAR wa_ivcus_tmp.
       *      MODIFY /tli/viv_ivcus FROM wa_ivcus_tmp .     "It will be used if we need to save every record, for Ex: when all the key fields are same then only one record will be saved using the it_changes table which might be considered as a bug.
                 ENDIF.
                 CLEAR wa_ivcuscp.
               ENDLOOP.
             ENDIF.
             MODIFY /tli/viv_ivcus FROM TABLE it_changes.
             IF sy-subrc EQ 0.
               MESSAGE 'Data Updated' TYPE 'I'.
      

      Now its working as required.

      Thanks & regards,

      NarsiReddy.

  • author's profile photo Former Member
    Former Member
    Posted on Sep 15, 2015 at 09:09 AM

    hi,

    try this code,

    call this below method in ur PAI of ur screen.

    CALL METHOD CL_GUI_ALV_GRID->check_changed_data

    IMPORTING

    e_valid = w_valid.

    also you need to register the events in PBO of ur screen.I hope u have done as

    CALL METHOD CL_GUI_ALV_GRID->register_edit_event

    EXPORTING

    i_event_id = cl_gui_alv_grid=>mc_evt_modified.

    CALL METHOD CL_GUI_ALV_GRID->register_edit_event

    EXPORTING

    i_event_id = cl_gui_alv_grid=>mc_evt_enter.

    Instantiate the event or it won't work.

    CREATE OBJECT w_event_receiver.

    SET HANDLER w_event_receiver->handle_data_changed FOR w_alvgd2.

    and the method will be declared in global section of the program as

    CLASS lcl_grid_event_receiver DEFINITION.

    PUBLIC SECTION.

    METHODS: handle_data_changed

    FOR EVENT data_changed OF cl_gui_alv_grid

    IMPORTING er_data_changed,

    endclass.

    CLASS lcl_grid_event_receiver IMPLEMENTATION.

    METHOD handle_data_changed.

    *event is ttriggered when data is changed in the output

    "your logic".

    ENDMETHOD.

    endclass.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Vinodh,

      I have implemented your solution but the problem is, it is not caching the first change. For example when i change the value of a first row, internal table is not getting changed. When i change the value of the first and second rows, the second row value is not updating in the internal table.

      Please let me know where i went wrong. But when i do the logic in PAI its working fine. Even without the class definition, implementation and handler syntax in PBO.

      CLASS lcl_event_receiver DEFINITION.
         PUBLIC SECTION.
           CLASS-METHODS:   handle_data_changed
                         FOR EVENT data_changed OF cl_gui_alv_grid
             IMPORTING er_data_changed.
       ENDCLASS.
      
       CLASS lcl_event_receiver IMPLEMENTATION.
         METHOD  handle_data_changed.
       *event is ttriggered when data is changed in the output
           "your logic".
           DATA : wa_ivcuscp     TYPE /tli/viv_ivcus.
           DATA : wa_ivcus_tmp TYPE /tli/viv_ivcus,
                  wa_itab      TYPE /tli/viv_ivcus.
           DATA it_changes TYPE STANDARD TABLE OF /tli/viv_ivcus.
           CLEAR it_changes[].
      
           IF itab_tmp[] NE itab[].
             LOOP AT itab INTO wa_itab.
               READ TABLE itab_tmp INTO wa_ivcuscp INDEX sy-tabix.
               IF wa_ivcuscp NE wa_itab.
                 MOVE-CORRESPONDING wa_itab TO wa_ivcus_tmp.
                 wa_ivcus_tmp-bname = sy-uname.
                 wa_ivcus_tmp-/tli/date = sy-datum.
                 wa_ivcus_tmp-time = sy-uzeit.
                 APPEND wa_ivcus_tmp TO it_changes.
                 CLEAR wa_ivcus_tmp.
       *      MODIFY /tli/viv_ivcus FROM wa_ivcus_tmp .
               ENDIF.
               CLEAR wa_ivcuscp.
             ENDLOOP.
           ENDIF.
           MODIFY /tli/viv_ivcus FROM TABLE it_changes.
           IF sy-subrc EQ 0.
             MESSAGE 'Data Updated' TYPE 'I'.
           ENDIF.
         ENDMETHOD.
       ENDCLASS.
      
       *&---------------------------------------------------------------------*
       *&      Module  STATUS_9000  OUTPUT
       *&---------------------------------------------------------------------*
       *       PBO
       *----------------------------------------------------------------------*
      
       MODULE status_9000 OUTPUT.
         IF o_container IS INITIAL.
           SET PF-STATUS 'ZSTATUS'. "GUI Status
           SET TITLEBAR 'ZTITLE'.   "Title
      
           CREATE OBJECT o_container
             EXPORTING
               container_name = 'ALV_GRID'.
      
           IF sy-subrc EQ 0.
       * Creating Grid
             CREATE OBJECT o_grid
               EXPORTING
                 i_parent = o_container.
           ENDIF.
      
           CALL METHOD o_grid->register_edit_event
             EXPORTING
               i_event_id = cl_gui_alv_grid=>mc_evt_modified.
      
           CALL METHOD o_grid->register_edit_event
             EXPORTING
               i_event_id = cl_gui_alv_grid=>mc_evt_enter.
      
      
           SET HANDLER lcl_event_receiver=>handle_data_changed FOR o_grid.
           PERFORM create_fieldcat.
           itab_tmp = itab.
           w_variant-report = sy-repid.
      
           CALL METHOD o_grid->set_table_for_first_display
             EXPORTING
               is_variant                    = w_variant
               i_save                        = 'A'
             CHANGING
               it_outtab                     = itab
               it_fieldcatalog               = fieldcat[]
             EXCEPTIONS
               invalid_parameter_combination = 1
               program_error                 = 2
               too_many_lines                = 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.
         ENDIF.
      
       ENDMODULE.                 " STATUS_9000  OUTPUT
      
       *&---------------------------------------------------------------------*
       *&      Module  USER_COMMAND_9000  INPUT
       *&---------------------------------------------------------------------*
       *       PAI
       *----------------------------------------------------------------------*
      
       MODULE user_command_9000 INPUT.
         DATA lv_ucomm TYPE sy-ucomm.
         lv_ucomm = sy-ucomm.
         CASE lv_ucomm.
           WHEN 'CANCEl' OR 'EXIT'.
       *      PERFORM free_objects.
             LEAVE PROGRAM.
           WHEN 'BACK'.
       *      PERFORM free_objects.
       *      SET SCREEN '0'.
             LEAVE PROGRAM.
           WHEN 'SAVE'.
       *      PERFORM save_database.
             DATA w_valid TYPE char01.
             CALL METHOD o_grid->check_changed_data
               IMPORTING
                 e_valid = w_valid.
             CALL METHOD o_grid->refresh_table_display.
         ENDCASE.
      
       ENDMODULE.                 " USER_COMMAND_9000  INPUT
      
  • author's profile photo Former Member
    Former Member
    Posted on Sep 15, 2015 at 09:28 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 15, 2015 at 05:44 PM

    Like one of the above posters mentioned, you need to capture the changed data from ALV screen back to internal table.

    Use this

    DATA: o_grid TYPE REF TO cl_gui_alv_grid.

    ....


    o_grid->check_changed_data( ).

    PERFORM save_database.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.