Tuesday 15 March 2016

Logging of table data changes

SAP provides mechanism to log the changes in any object. For some objects we CDHDR and CDPOS table. In the same way, if one wants to log the changes done in table data like when data was created, when changed and when deleted, SAP has a mechanism for this also. For this we will be taking help of table DBTABLOG and a t-code SCU3.

Now what we need to do when creating the table? I'll create a demo table and log it's data change. So in the process, I am creating a table named ZTEST_LOG. 
 Now while doing the technical settings, we have to check the option for table logging.
 Now we have to create table maintenance generator for this table. While creating table maintenance generator, authorization object S_TABU_DIS comes by-default. Now one thing to remember here. Without creating table maintenance generator also we can create the entries in table. We will b able to see them in table DBTABLOG. But t-code SCU3 won't show us anything and it will give us error for assigning the table in right authorization group. The reason for this error is that table maintenance generator is missing. So always maintain table maintenance generator.


Now we will be first seeing the table content of DBTABLOG, so that we can differentiate later on.

 
We will create 3 entries in table. 

and then we will again check the DBTABLOG table.

 First entry shows the start of change and so the last entry for the end of change. In between there are 3 entries, each for 3 rows we have created. We can click on an entry and can look inside for other fields also.
 Logkey field is the concatenation of the client where data is created and the primary key field's value. It stores the date, time and the user who have done the changes.

Now we will go into T-code SCU3 and will see how it looks. Go into SCU3 and click on "Evaluation of change log". Below screen will come and give the table name and appropriate date and time. Choose Table option in "Evaluation for" box.
 
Now we will go and change one existing entry in table. So table content now looks like below.


Check what table DBTABLOG now has in it.

Again you can see one entry marks for begging of changes and one for end of changes. And one entry in between for the actual data change. If we go inside, again it shows us in which particular row we have done the changes with the field LOGKEY.


Check in t-code SCU3 also. This time it shows the key field of the row which has been changed and also which field particularly has been changed from which value to which value.


So this way you can completely track the table data changes. Table DBTABLOG tells you about the data change done when, by whom and in which client. While as T-code SCU3 tell you exactly what has been changed. What was the old value and what was the new value.

Happy Learning :)