11-22-2011 12:59 PM
My program has a grid display using OOPS with two fields editable namely price and seats occupied. If i make a change in either of those two fields, the total payment sum column should get automatically calculated and displayed. I have made the field editable by using EDIT in field catalog.
I got theoretical notes regarding implementation of event handler, cl_gui_alv_grid=>mc_evt_enter etc. But I didnt understand how to practically implement it in the program.
How to detect change in the two mentioned columns and how to use the edited values to calculate the new amount. Please guide me in this . It would be much appreciated if someone can provide a clear code for a similar case. I am a beginner to the OOPS concepts in ALV. Provide simple solutions.
11-22-2011 1:26 PM
Hi
You can use the the internal table mt_mod_cells that gives you the cells that have been modified.
Take a look at this code snippet
method handle_data_changed.
perform handle_data_changed using er_data_changed.
endmethod.
.....
form handle_data_changed using p_data_changed type ref to
cl_alv_changed_data_protocol.
data: ls_mod_cell type lvc_s_modi,
lv_value_dni type lvc_value.
loop at p_data_changed->mt_mod_cells into ls_mod_cell.
call method p_data_changed->get_cell_value
exporting
i_row_id = ls_mod_cell-row_id
i_fieldname = 'FINI_SUST' <== Your field
importing
e_value = lv_value_dni .
endloop.
endform.
Basically when you modify the fields PRICE and SEATS you can get the modified values by using this technique and then modify the total amount in your internal table accordingly.
After that you should call the method REFRESH_TABLE_DISPLAY
PS: Note that if you are using cl_gui_alv_grid=>mc_evt_enter, the event HANDLE_DATA_CHANGED will only be fired when you hit INTRO after having done the changes in your editable fields.