‎2009 Sep 19 2:22 AM
i'm in trouble with method check_changed_data. i though i was to trigger any changes in my editable alv.
in pbo i've:
SET HANDLER g_event_receiver->handle_data_changed FOR grid1.and in the pai:
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT' OR 'BACK'.
PERFORM exit_program.
WHEN '&DATA_SAVE'.
CALL METHOD grid1->check_changed_data
IMPORTING
e_valid = l_valid.
IF l_valid = 'X'.
PERFORM call_transaction.
ENDIF.
WHEN OTHERS.
* do nothing
ENDCASE.i had expected the call_transaction only if some changes are made in the alv, but i allways have l_valid = 'X'.
where do i make a mistake?
‎2009 Sep 21 5:27 PM
Hello
Assuming that your requirement is that "When the user pushes the DATA_SAVE button AND something has changed on the ALV grid then execute the transaction" the solution is quite simple:
"(1) Call method CHECK_CHANGED_DATA at the beginning of PAI
save_ok = ok_code.
CLEAR ok_code.
CALL METHOD grid1->check_changed_data( ). " triggers DATA_CHANGED
CASE save_ok.
WHEN 'EXIT' OR 'BACK'.
PERFORM exit_program.
WHEN '&DATA_SAVE'.
" CALL METHOD grid1->check_changed_data
" IMPORTING
" e_valid = l_valid.
IF l_valid = 'X'.
PERFORM call_transaction.
ENDIF.
WHEN OTHERS.
* do nothing
ENDCASE.
Define an event handler method (e.g. HANDLE_DATA_CHANGED) which just stores a CHANGE flag:
METHOD handle_data_changed.
" E.g. define static attribute in your event handler class
lcl_eventhandler=>md_data_changed = 'X'.
" That's all if you do not need any further validations.
ENDMETHOD.
Now change your USER_COMMAND module as following:
save_ok = ok_code.
CLEAR ok_code.
CALL METHOD grid1->check_changed_data( ). " triggers DATA_CHANGED
CASE save_ok.
WHEN 'EXIT' OR 'BACK'.
PERFORM exit_program.
WHEN '&DATA_SAVE'.
" CALL METHOD grid1->check_changed_data
" IMPORTING
" e_valid = l_valid.
" IF l_valid = 'X'.
IF ( lcl_eventhandler=>md_data_changed = 'X' ).
lcl_eventhandler=>md_data_changed = ' '. " reset change flag
PERFORM call_transaction.
ENDIF.
WHEN OTHERS.
* do nothing
ENDCASE.
Regards
Uwe
‎2009 Sep 21 10:51 AM
Hi,
the e_valid flag is set when the data in the grid is consistent, not when it has been changed. This means, if the data in the editable ALV contains no errors (i.e. strings in a numeric field..) the flag will always be set. From what I understand, you want to limit the call transaction to cases where data has actually changed. There are several ways to deal with this. You can keep a copy of the data as reference and compare it with the data in the alv, or you cann play arround with the parameter ER_DATA_CHANGED of the DATA_CHANGED event.
best regards,
Hans Hohenfeld
‎2009 Sep 21 3:31 PM
Hi,
You have a table er_data_changed->MT_MOD_CELLS which give you the cells that were modified in the Editable ALV. So you can keep a flag say lv_modified.. and populate the flag incase you have a record ... This way you can restrict the Call only when Data is changed.
Hope this helps you
Raj
‎2009 Sep 21 5:27 PM
Hello
Assuming that your requirement is that "When the user pushes the DATA_SAVE button AND something has changed on the ALV grid then execute the transaction" the solution is quite simple:
"(1) Call method CHECK_CHANGED_DATA at the beginning of PAI
save_ok = ok_code.
CLEAR ok_code.
CALL METHOD grid1->check_changed_data( ). " triggers DATA_CHANGED
CASE save_ok.
WHEN 'EXIT' OR 'BACK'.
PERFORM exit_program.
WHEN '&DATA_SAVE'.
" CALL METHOD grid1->check_changed_data
" IMPORTING
" e_valid = l_valid.
IF l_valid = 'X'.
PERFORM call_transaction.
ENDIF.
WHEN OTHERS.
* do nothing
ENDCASE.
Define an event handler method (e.g. HANDLE_DATA_CHANGED) which just stores a CHANGE flag:
METHOD handle_data_changed.
" E.g. define static attribute in your event handler class
lcl_eventhandler=>md_data_changed = 'X'.
" That's all if you do not need any further validations.
ENDMETHOD.
Now change your USER_COMMAND module as following:
save_ok = ok_code.
CLEAR ok_code.
CALL METHOD grid1->check_changed_data( ). " triggers DATA_CHANGED
CASE save_ok.
WHEN 'EXIT' OR 'BACK'.
PERFORM exit_program.
WHEN '&DATA_SAVE'.
" CALL METHOD grid1->check_changed_data
" IMPORTING
" e_valid = l_valid.
" IF l_valid = 'X'.
IF ( lcl_eventhandler=>md_data_changed = 'X' ).
lcl_eventhandler=>md_data_changed = ' '. " reset change flag
PERFORM call_transaction.
ENDIF.
WHEN OTHERS.
* do nothing
ENDCASE.
Regards
Uwe
‎2009 Sep 21 6:54 PM
‎2011 Jun 10 2:43 PM
Hi There,
This is a beautiful response. I love this.
Thanks for being so detailed.
With Regards,
Kumud Singh