Application Development 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: 

Store changed data in different table

Former Member
0 Kudos
84

Hello All,

I have a requirement where in I want to store changed data from one Z table into another. When I make any changes to the existing data in one Z table I need to log the changes (old values) in another Z table. I have tried to check events in table maintainence generator, but do not get the old values in any event. Apart from using a module pool is there a way using events for a table maintenance where in changes/deletions can be recorded into another table(history table).

Thanks and Regards,

Sachin

3 REPLIES 3

pole_li
Active Participant
0 Kudos
44

Hi,

You can activate the "log table changes" in technical setting of your Ztable in SE11 , then use SCU3 to analysis the changes.

Pole

SuhaSaha
Advisor
Advisor
0 Kudos
44

Try this code snippet in Event '01' of the TMG:

DATA: f_index LIKE sy-tabix, "Index to note the lines found
        st_zabc TYPE zabc,
        it_zabc_old TYPE STANDARD TABLE OF zabc,
        st_zabc_old TYPE zabc.

  BREAK-POINT.

  LOOP AT total.
    IF <action> = aendern.
      READ TABLE extract WITH KEY total.
      IF sy-subrc EQ 0.
        f_index = sy-tabix.
        st_zabc = total.

        SELECT SINGLE * FROM zabc INTO st_zabc_old
          WHERE zzf1 = st_zabc-zzf1
          AND   zzf2 = st_zabc-zzf2.
        CHECK sy-subrc = 0.
        APPEND st_zabc_old TO it_zabc_old.
        CLEAR st_zabc_old.
      ELSE.
        CLEAR f_index.
      ENDIF.
      "(make desired changes to the line total)
      MODIFY total.
      CHECK f_index GT 0.
      extract = total.
      MODIFY extract INDEX f_index.
    ENDIF.
  ENDLOOP.

" You can use the table IT_ZABC_OLD to save the old data to another table.

  sy-subrc = 0.

Hope this helps.

BR,

Suhas

Former Member
0 Kudos
44

Thanks for the help Suhas.

Regards,

Sachin