Back To ABAP Basics – “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 ).
Advertisements

One thought on “Back To ABAP Basics – “Data Changed” on ALV Grid

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s