Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Check if any data was changed in ALV with FM

Former Member
0 Kudos
3,584

Hi!

I have a ALV with FM REUSE_ALV_GRID_DISPLAY_LVC with editable fields.

In USER_COMMAND event, i execute FM GET_GLOBALS_FROM_SLVC_FULLSCR and call method CHECK_ CHANGED_DATA to get data from screen.

Has any way to check if any data was changed in screen? Or i will have to do LOOP, if t_report-field1 <> t_report2-field1, endloop.

I need to know if any data in internal table has changed for display a message "Data was changed". How can i do that?

Thanks!

1 ACCEPTED SOLUTION

former_member209703
Active Contributor
0 Kudos
861

Hi

You can use the event DATA_CHANGED. One of the parameters of this event ( ER_DATA_CHANGED TYPE CL_ALV_CHANGED_DATA_PROTOCOL ) provides you with the data that has been modified:


MT_MOD_CELLS
MT_INSERTED_ROWS
MT_DELETED_ROWS
MP_MOD_ROWS

You can take a look at the demo program BCALV_TEST_FULLSCREEN This event will be fired when you execute CHECK_CHANGED_DATA method after you have set the corresponding handler

This is the relevant code




*---------------------------------------------------------------------*
*       CLASS lcl_events_d1003 DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
class lcl_events_d1003 definition.
  public section.
    methods:
    onf4                 for event onf4
                         of cl_gui_alv_grid
                         importing e_fieldname
                                   e_fieldvalue
                                   es_row_no
                                   er_event_data
                                   et_bad_cells
                                   e_display,

    data_changed         for event data_changed
                         of cl_gui_alv_grid
                         importing er_data_changed
                                   e_onf4
                                   e_onf4_before
                                   e_onf4_after,

    data_changed_finished
                         for event data_changed_finished
                         of cl_gui_alv_grid.

endclass.                    "lcl_events_D1003 DEFINITION



*&---------------------------------------------------------------------*
*&      Form  d1001_set_grid_evts
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form d1001_set_grid_evts .

  create object gr_events_d1001.

  set handler gr_events_d1001->data_changed
              for gr_grid_d1001.

  set handler gr_events_d1001->data_changed_finished
              for gr_grid_d1001.

endform.                    " d1001_set_grid_evts

3 REPLIES 3

former_member209703
Active Contributor
0 Kudos
862

Hi

You can use the event DATA_CHANGED. One of the parameters of this event ( ER_DATA_CHANGED TYPE CL_ALV_CHANGED_DATA_PROTOCOL ) provides you with the data that has been modified:


MT_MOD_CELLS
MT_INSERTED_ROWS
MT_DELETED_ROWS
MP_MOD_ROWS

You can take a look at the demo program BCALV_TEST_FULLSCREEN This event will be fired when you execute CHECK_CHANGED_DATA method after you have set the corresponding handler

This is the relevant code




*---------------------------------------------------------------------*
*       CLASS lcl_events_d1003 DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
class lcl_events_d1003 definition.
  public section.
    methods:
    onf4                 for event onf4
                         of cl_gui_alv_grid
                         importing e_fieldname
                                   e_fieldvalue
                                   es_row_no
                                   er_event_data
                                   et_bad_cells
                                   e_display,

    data_changed         for event data_changed
                         of cl_gui_alv_grid
                         importing er_data_changed
                                   e_onf4
                                   e_onf4_before
                                   e_onf4_after,

    data_changed_finished
                         for event data_changed_finished
                         of cl_gui_alv_grid.

endclass.                    "lcl_events_D1003 DEFINITION



*&---------------------------------------------------------------------*
*&      Form  d1001_set_grid_evts
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form d1001_set_grid_evts .

  create object gr_events_d1001.

  set handler gr_events_d1001->data_changed
              for gr_grid_d1001.

  set handler gr_events_d1001->data_changed_finished
              for gr_grid_d1001.

endform.                    " d1001_set_grid_evts

0 Kudos
861

Has any program for example more simple? BCALV_TEST_FULLSCREEN is complexy because it´s complety ALV example.

0 Kudos
861

Hi

U can use the event DATA_CHANGED for fm REUSE_ALV_GRID_DISPLAY_LVC:

TYPE-POOLS: SLIS.

DATA: T_SFLIGHT     TYPE STANDARD TABLE OF SFLIGHT.
DATA: IS_LAYOUT_LVC TYPE  LVC_S_LAYO.
DATA: IT_EVENTS     TYPE  SLIS_T_EVENT.
DATA: LT_EVENT      TYPE  SLIS_ALV_EVENT.
DATA: L_REPORT      TYPE SY-REPID.

START-OF-SELECTION.
*
  IS_LAYOUT_LVC-EDIT = 'X'.
  LT_EVENT-NAME      = 'DATA_CHANGED'.
  LT_EVENT-FORM      = 'ALV_DATA_CHANGED'.
  APPEND LT_EVENT TO IT_EVENTS.
*
  L_REPORT = SY-REPID.
*
  SELECT * UP TO 10 ROWS INTO TABLE T_SFLIGHT
    FROM SFLIGHT.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      I_CALLBACK_PROGRAM = L_REPORT
      I_STRUCTURE_NAME   = 'SFLIGHT'
      IS_LAYOUT_LVC      = IS_LAYOUT_LVC
      IT_EVENTS          = IT_EVENTS
    TABLES
      T_OUTTAB           = T_SFLIGHT.

FORM ALV_DATA_CHANGED  USING
         ER_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.

  DATA: LS_GOOD TYPE LVC_S_MODI.

  LOOP AT ER_DATA_CHANGED->MT_GOOD_CELLS INTO LS_GOOD.
    MESSAGE I208(00) WITH 'Data changed'.
    EXIT.
  ENDLOOP.
ENDFORM.                    "ALV_DATA_CHANGED

Max