Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

check_changed_data

Former Member
0 Likes
14,073

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?

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
6,383

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

5 REPLIES 5
Read only

Former Member
0 Likes
6,383

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

Read only

0 Likes
6,383

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

Read only

uwe_schieferstein
Active Contributor
0 Likes
6,384

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

Read only

0 Likes
6,383

working pretty well, thanks!!!!

Read only

0 Likes
6,383

Hi There,

This is a beautiful response. I love this.

Thanks for being so detailed.

With Regards,

Kumud Singh