Application Development and Automation 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: 
Read only

CL_GUI_ALV_GRID check changed data not triggering event handler method

Former Member
0 Likes
3,094

Halo Experts,

There is a method in my class has_data_changed( ) which asks the Grid whether any data has been chnaged so that I can update my delta tables

inside the method has_data_changed( ) I am calling

l_grid->check_changed_data( IMPORTING e_valid = l_valid ) and I have got a event handler method in the same class for event data change of GRID .

But sometimes the check_changed_data is not triggering the event handler method . I dont know what exactly is the problem .

I am setting the handlers also correctly. Could you please help.

Moderator message - Moved to the correct forum

Edited by: Rob Burbank on Nov 6, 2009 11:07 AM

8 REPLIES 8
Read only

Former Member
0 Likes
2,039

Can you please check if u changed system events to application events ...in that case u need to call CL_GUI_CFW=>DISPATCH in the PAI module.

Read only

0 Likes
2,039

Thanks

I checked in the constrcutor of ALV_GRID i changed i_appl_events = 'X' to space . Still the event handler is not getting triggered.

One more thing I noticed , I have some fields registered for event on_f4 ie

l_f4-fieldname = 'ID'.

l_f4-register = 'X'.

l_f4-GETBEFORE = 'X'.

l_f4-CHNGEAFTER = 'X'.

INSERT l_f4 INTO TABLE lt_f4.

But when I go to change mode for this field and press f4 the event handler for data_changed is getting triggered ,but when i change the data and press save ( where I am calling l_grid->check_changed_data) the event is not getting triggered.It even does not go inside the std sap code.

Now when I modify a field which is not registered for f4 and press save the event is getting triggered.

Read only

0 Likes
2,039

did u try to use

SET_REGISTERED_EVENTS method to register the event

and try

CALL METHOD g_grid->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_modified.

Edited by: rajesh khatwa on Nov 6, 2009 6:12 PM

Read only

0 Likes
2,039

Ya I have used that also but still the event inside save method( where I call l_gird->check_changed_data( ) is not getting triggered ), if the last edited field in my grid is a field that is registered for f4 event.

Read only

uwe_schieferstein
Active Contributor
0 Likes
2,039

Hello

You may have a look at thread

and the blog [A Christmas Collection of Useful Classes|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/12377] [original link is broken] [original link is broken] [original link is broken];

I am almost sure that the problem is due to a "misplacement" (i.e. wrong timing) of the method call CHECK_DATA_CHANGED.

Regards

Uwe

PS: Without parts of the coding where one can see the flow of the program it is not possible to give more concrete advice.

Read only

0 Likes
2,039

Halo Uwe,

Thanks a lot ,But i did not get my reqd answer .

in my event handler method on_data_changed I want to update my delta tables

my_new_and_changed_records( which consists of newly added records as well as changed records ) .

and also my_deleted_records( which consists of deleted records ). ie the user has freedom to do anything in the Grid.Inside on_data_changed i am getting all the updated records , modifed cells . deleted rows in to my local class attributes . Then I am using that to fill my delta tables . I am making sure that only when user presses save I am updating the delta recods( my_new_and_changed_records

and my_deleted_records)


  DATA l_record TYPE t_record.
  DATA l_display_record LIKE LINE OF my_display_records.
  DATA: l_modified_cell TYPE lvc_s_modi.
  FIELD-SYMBOLS : <fs_field_value> TYPE ANY.
 
IF i_data_changed IS BOUND.
    APPEND LINES OF i_data_changed->mt_mod_cells TO my_modified_cells.
    APPEND LINES OF i_data_changed->mt_inserted_rows TO my_inserted_rows.
    APPEND LINES OF i_data_changed->mt_deleted_rows TO my_deleted_rows.
  ENDIF.


if my_save_flag eq 'X'.  
LOOP AT my_modified_cells INTO l_modified_cell
                        WHERE value IS NOT INITIAL
                        AND error NE 'X'.
* Mae sure that it is not Inserted rows whihc is handled separately
    READ TABLE my_inserted_rows WITH KEY row_id = l_modified_cell-row_id TRANSPORTING NO FIELDS.

    IF sy-subrc NE 0.

      READ TABLE my_display_records  INDEX l_modified_cell-row_id INTO l_display_record.

      IF l_display_record IS NOT INITIAL.

        ASSIGN COMPONENT l_modified_cell-fieldname OF   STRUCTURE l_display_record TO <fs_field_value>.

        <fs_field_value> = l_modified_cell-value.

        MOVE-CORRESPONDING l_display_record TO l_record.

        READ TABLE my_new_and_changed_records WITH KEY id = l_record-id
                                                       valid_from = l_record-valid_from
                                                       valid_to = l_record-valid_to
                 TRANSPORTING NO FIELDS.

        IF sy-subrc EQ 0.
          MODIFY my_new_and_changed_records FROM l_record INDEX sy-tabix.
        ELSE.
          APPEND l_record TO my_new_and_changed_records.
        ENDIF.

      ENDIF.

    ENDIF.

    CLEAR: l_display_record,
            l_record.


  ENDLOOP.
************************Modification Operation ends*********************

**************************Insert operation*********************************

LOOP AT my_inserted_rows INTO l_inserted_row.

      READ TABLE my_deleted_rows WITH KEY row_id = l_inserted_row-row_id
      TRANSPORTING NO FIELDS.

      IF sy-subrc NE 0.

        IF i_data_changed IS BOUND.

          l_record = get_cell_values( i_row_id = l_inserted_row-row_id
                                   i_data_changed = i_data_changed ).

        ELSE.

          READ TABLE my_display_records  INDEX l_inserted_row-row_id INTO l_display_record.

          MOVE-CORRESPONDING l_display_record TO l_record.

        ENDIF.

        IF l_record IS NOT INITIAL.

          APPEND l_record TO my_new_and_changed_records.

        ENDIF.

      ENDIF.

    ENDLOOP.
*************End of Insert operation*****************

Now here I have two problems

1 I am explicitly calling on_data_change event handler method in my save bcs l_grid->check_changed_data is not working fine .

Is htere any way to find l_grid->check_changed_data is triggered or not

2 I am having a problem with the combination of deelted rows and inserted rows . If the user deletes

the first row in my_display_records and then inserts a new one . He presses save , then both the row ids in my_inserted_row as well as my_deleted_row are one. How to differentiate b/w/ this two what the user did first?

Read only

0 Likes
2,039

Hello Arshad

In my opinion your approach is much too complicated. Instead of trying to collect all the changes during the editing process by the user I would recommend a much simpler way:

1. Before displaying your ALV list store a PBO image of your data


DATA:
  gt_outtab            TYPE ty_t_outtab,
  gt_outtab_pbo    TYPE ty_t_outtab.
...

gt_outtab_pbo = gt_outtab.
...
CALL METHOD go_grid->SET_TABLE_FOR_FIRST_DISPLAY(...). 

2. When the user pushes the SAVE button compare the PAI vs PBO data, e.g.:

[Comparing Two Internal Tables - A Generic Approach|http://wiki.sdn.sap.com/wiki/display/Snippets/ComparingTwoInternalTables-AGeneric+Approach]

3. Update the PBO data after saving the data:


gt_outtab_pbo = gt_outtab.

Regards

Uwe

Read only

0 Likes
2,039

Hi Uwe ,

Thanks for the reply .

I changed the coding only to see that this compare method does not work for global structures and global table types with line type structures .

I am not displaying the table as such in the grid , I am showing a global structure with different fields ( compared to the global table ).

*It is catching the exception name_tab error inside

FM CHANGEDOCUMENT_PREPARE_TABLES*

Now I have to write back the display records in PBO and PAI to the table records and do the compare I suppose : (