Skip to Content
Author's profile photo Aiolos Yang

Trigger ALV data_change event manual

As we know, when we changed something in the alv grid, event data_changed will be triggered, and we can do some custom check.

but do you face this situation, after you changed this alv and push on some user command, like ‘SAVE’, the data_changed event will not be triggered again, because no cell is changed in alv grid, but actually, you want to trigger it and do something you want.

below i will give you 1 solution to trigger it by compulsion.

in PAI, use method IF_CACHED_PROP~SET_PROP of class CL_GUI_ALV_GRID to set property ‘GridModified’ as modified, then call CHECK_CHANGED_DATA of CL_GUI_ALV_GRID, data_changed event will be triggered.

1.add code in PAI

图像 001.png

2.Run your program and update data, then save.

图像 007.png

图像 010.png

3.Push ‘SAVE’, event will be triggered.

图像 003.png

图像 004.png

This is my first time to write blog, please give your comment if you also have some experience on this topic. Thanks.

Assigned Tags

      15 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Ramesh T
      Ramesh T

      Good.. Thanks for Sharing...

      Author's profile photo Dinesh K
      Dinesh K

      It is very helpful to me and beginners.Thank you very much for sharing.

      Keep going on..All the best

      Author's profile photo Swadhin Ghatuary
      Swadhin Ghatuary

      Hello Aiolos ,

      Thanks a lot for this blog, it not only save time but also a good trick to trigger the data_change  event manually. one more thing i want to add that i use this event in classical alv to find out data in editable alv grid is changed or not.  i add the code with hope it will help other

      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

      IMPORTING

      e_repid = sy-repid

      e_grid = it_grid.

      CALL METHOD it_grid->check_changed_data

      IMPORTING

      e_valid = p_valid.

      if P_VALID = 'X'.

      now you add your custom task to be done if data changed.

      Author's profile photo Aiolos Yang
      Aiolos Yang
      Blog Post Author

      Yes, swadhin.

      Thanks to Reply, this will be useful for FM ALV.

      Author's profile photo Eduardo Campos
      Eduardo Campos

      Thanks a lot!

      Author's profile photo Former Member
      Former Member

      Hi Aiolos,

      Is good post, but one thing You miss. 😉

      We called pv_grid->check_changed_data -> the event data_change is trigger and data are changed. After this must call again   IF_CACHED_PROP~SET_PROP of class CL_GUI_ALV_GRID  with PROPNAME = 'GridModified'  and set PROPVALUE = '0'.

      If we will not set PROPVALUE to zero the ALV instance will be always in modified mode and for every action( for example : click on button, etc..) will trigger the DATA_CHANGE event.

      Cheers.

      Author's profile photo Sandra Rossi
      Sandra Rossi

      I'm curious to know what is the interest of triggering manually the DATA_CHANGED event? (I've written many editable ALV grids, and I think I explored almost all possible functions, seen many issues, but I never needed to trigger it manually)

      Author's profile photo Łukasz Pęgiel
      Łukasz Pęgiel

      In most cases I also don't see a need for that but I faced a situation when users wanted to be allowed to enter anything into grid and at save function they wanted to get all errors. In this case manuall triggger suits well.

      Author's profile photo Sandra Rossi
      Sandra Rossi

      Thanks! It's good to know a situation for which it can be used 🙂 I had found a solution with the standard events to put aside the messages, so the user was not bothered with the popup at every invalid cell, and he/she could also see his erroneous entries while typing, but well, that would be another discussion 🙂

      Author's profile photo Chaouki Akir
      Chaouki Akir

      If it is still possible can you give more information about your solution ?

       

      Author's profile photo Sandra Rossi
      Sandra Rossi

      Create a docking container where to display the log, and during the event DATA_CHANGED, call the method ER_DATA_CHANGED->DISPLAY_PROTOCOL to indicate the log container. You should also initiate the ALV grid by calling the method GRID->ACTIVATE_DISPLAY_PROTOCOL( 'X' ) to avoid the focus moving from the ALV grid to this log container.

      Author's profile photo Chaouki Akir
      Chaouki Akir

      Triggering manually the DATA_CHANGED event has been used by some developers to manage the following situation :

      • report displaying an editable ALV grid with data loaded from an uploaded text file
      • if the user hits the button CHECK
        • without changing any of these uploaded entries,
          • then these uploaded entries are not checked at all (event DATA_CHANGED is not triggered ; <=> nothing added to the log ).
        • with checking only one single of these uploaded entries,
          • then only the single changed uploaded entry is checked (event DATA_CHANGED is triggered as usual)

      Examples of thread :

      • https://archive.sap.com/discussions/thread/292747
      • https://archive.sap.com/discussions/thread/263500 (post Former Member)

       

      Author's profile photo ananthachari enjarapu
      ananthachari enjarapu

      Thanks for sharing

      Author's profile photo Former Member
      Former Member

      Thanks a lot

      Author's profile photo Don Jeffrey Sison
      Don Jeffrey Sison

      Thank you ,  unfortunately when you forced to triiger the event  mt_mod_cells has no values. How will you identify the modified cells instead of selecting all records to increase performance of it?