“Data Changed” on ALV Grid

1464-ppt

This entry will demonstrate a semi-pseudo code template on how to catch the “Data Changed” event on an editable non-OO ALV grid, and how to modify data further. This means, we are dealing with a grid generated by “REUSE_ALV_GRID_DISPLAY”, not “CL_GUI_ALV_GRID”.

*&------------------------------
*& STEP 1: Preparation
*&------------------------------

* Read data, create field catalog, etc.
  “todo

*&------------------------------
*& STEP 2: Calling ALV correctly
*&------------------------------

* Set “Edit Cell Callback” flag on grid settings.
* This will make the ALV grid record user changes
* into the ITAB immediately.

  lwa_gs-edt_cll_cb = abap_true.
 
* Adding “DATA_CHANGED” event to events ITAB.
* Unfortunately, you don’t see the existence of
* this event in ALV help. 
* Feel free to add other events as well; such as
* SET_PF_STATUS and USER_COMMAND.

  append initial line to lit_event reference into lrd_event.
  lrd_event->name = 'DATA_CHANGED'.
  lrd_event->form = 'DATA_CHANGED'.

* Call your grid. 
* To avoid confusion, I have left unrelevant parameters out.

  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      i_grid_settings    = lwa_gs
      it_events          = lit_event
    “TODO: Put other parameters here

*&------------------------------
*& STEP 3: Dealing with edited data
*&------------------------------

form data_changed ##called
     using lrc_i_dc type ref to cl_alv_changed_data_protocol.

  data: “TODO: Change the type of ITAB 
    lit_alv_new type standard table of zmms_dte_alv_single.

* Capture changed data and put into typed ITAB
  assign lrc_i_dc->mp_mod_rows->* to .
  lit_alv_new[] = [].

* Do whatever you want to do with the new data
* You can do validity checks, re-calculate other cells,
* refresh text fields, etc.
  “todo
 
* This is how you modify a value in ALV GRID if needed
* I_ROW_ID    = Index of line in ALV GRID
* I_TABIX     = Index of line in LIT_ALV_NEW
* I_FIELDNAME = Name of field you want to modify (doh!)
* I_VALUE     = New value of field

  lrc_i_dc->modify_cell( i_row_id    = lfd_tabix_old
                         i_tabix     = lfd_tabix_new
                         i_fieldname = 'BSAYI'
                         i_value     = lfd_bsayi ).

Posted

in

,

by

Comments

6 responses to ““Data Changed” on ALV Grid”

  1. Aleksey Avatar
    Aleksey

    Cool ! Thanks!

  2. Vamshi Mohan Avatar
    Vamshi Mohan

    Thank you for sharing this. It helped me.

  3. Yuliya Sukhareva Avatar
    Yuliya Sukhareva

    Thank you, very helpful.

    1. Dr. Kerem Koseoglu Avatar

      You are welcome 😊

  4. Paul Graylish Avatar
    Paul Graylish

    Great article. This helped me put the final piece into my project. Thanks!

    1. Dr. Kerem Koseoglu Avatar

      I’m glad you have found it useful 🙂

Leave a comment