abapalv

ALV Grid: how to manually trigger DATA_CHANGED after a call to CHANGE_DATA_FROM_INSIDE()?


I'm using an editable ALV Grid. I would like it to behave like this:

  1. A custom button fills some cells in the ALV. Data validation shouldn't be triggered yet.
  2. The user checks the filled data and accepts it by pressing ENTER. Only then is the new data checked in the handler of event DATA_CHANGED.

I'm calling CHANGE_DATA_FROM_INSIDE() to fill the cells. My problem is that pressing Enter has no effect because no cells were changed by the user. Just calling CHANGE_DATA_FROM_INSIDE() is not enough to be considered a change.

How can I trigger the DATA_CHANGED manually ? I know you can trigger it after CHANGE_DATA_FROM_INSIDE() by setting val_data to abap_true in the lvc_s_layo structure, but I do not want it to be triggered immediately.

I've registered the Enter key like this:

go_alv_grid->register_edit_event( EXPORTING i_event_id =  CL_GUI_ALV_GRID=>mc_evt_enter ).

It didn't help.

I've tried to intercept the Enter key press as a PAI event, but it doesn't trigger a PAI event, wether it is registered as an edit event or not.

It doesn't trigger a USER_COMMAND event either.

The Enter key always triggers event DATA_CHANGED_FINISHED, but it doesn't let me differentiate between Enter key presses and any other events which might also trigger this event.

Please help.


Solution

  • I ended up handling my custom function like this:

    1. Set val_data to abap_true in the lvc_s_layo structure passed to set_table_for_first_display()

    2. When the function is called, fill the ALV internal table directly and call refresh_table_display(), as Sandra Rossi suggested. It will appear but no data validation will occur.

    3. When the Enter key is pressed, catch the DATA_CHANGED_FINISHED event and call change_data_from_inside() there to change the cells again. This time the DATA_CHANGE event is raised and validation can happen. But before calling this method, clear out the values in the ALV table, because otherwise the ALV Grid would detect that they are identical, and the DATA_CHANGED event would be raised with an empty MT_GOOD_CELLS table.

    4. If validation fails and you want a protocol entry to be displayed, call method er_data_changed->display_protocol() (this is not showing up automatically for values changed with the method change_data_from_inside() ).