Hi folks,
this post is about a common problem when using alv grid.
The normal change validation system in the alv operates only on data the user has changed.
Often it happens that you need to do changes on data that the user has not changed in that moment.
For example you copy a line. At the beginning it is necessarily a duplicate of the original
and you disable checks in on data changed to give the user time to change the line to its purpose.
But this is the only moment where the alv recognizes the new cells as changed.
Later on they are not "changed" anymore.
I solved it using a "confim data" pushbutton that appears after the copy button is pressed until the editing is complete.
At this time in the pushbutton callback i
1) Build a modi table with "modified" cells i want to check and their values
2) call the method "set_delta_cells"
3) call the method "check_changed_data".
The first method marks the cells as if they had been edited.
The second method causes the data validation to be triggered including the "on_data_changed" event.
You find sample coding below.
Interestingly enough it is also possibile to raise the event directly with the raise event statement. ( you find the correspongin coding commented below)
The problem is that the "er_data_changed" is empty so basically change validation cannot issue any message without some havoc.
Hope this helps.
Cheers
Method pushbutton_callback.
* More coding here to read the new line assigning it to the generic field symbol
*......
*....
DATA lt_modi TYPE lvc_t_modi.
DATA ls_modi TYPE lvc_s_modi.
FIELD-SYMBOLS:
DATA ls_fcat TYPE lvc_s_fcat.
LOOP AT at_fldcat INTO ls_fcat.
CLEAR ls_modi.
ASSIGN COMPONENT ls_fcat-fieldname OF STRUCTURE
ls_modi-row_id = a_created_line_idx.
ls_modi-fieldname = ls_fcat-fieldname.
ls_modi-value =
APPEND ls_modi TO lt_modi.
ENDLOOP.
CALL METHOD me->set_delta_cells
EXPORTING
it_delta_cells = lt_modi
i_modified = 'X'
* i_frontend_only =
.
DATA l_valid TYPE char01.
CALL METHOD check_changed_data
IMPORTING
e_valid = l_valid.
**6) data changed
* RAISE EVENT data_changed EXPORTING er_data_changed = ar_data_changed
* e_onf4 = space
* e_onf4_before = space
* e_onf4_after = space
* e_ucomm = m_ucomm.
*
**Raise event data changed finished.
* DATA lt_c TYPE lvc_t_modi.
* DATA l_modi TYPE char01 VALUE 'X'.
*
* RAISE EVENT data_changed_finished
* EXPORTING e_modified = l_modi
* et_good_cells = lt_c.
ENDMETHOD. "pushbutton_callback