10-14-2008 9:51 AM
Hi,
I have a Z database table.
I have a program that gets data from an excel file and uploads the content to the Z database table.
I need to track the creation/update/deletion of the records in the Z database table.
The Z database table can also have records changed/updated/deleted manually thru table maintenance. These changes also need to be tracked.
How do I do this?
~ Eric
10-14-2008 9:53 AM
Hi
Try using custom data element or some standard data element where "change document" flag is switched on inside the data element. Then you should be able to track the changes via CDHDR/CDPOS table.
Regards,
Rudra
10-14-2008 9:57 AM
Hi,
I already have (key) fields that have "Change Document" checked. I have put sample records in the Z table and modified it many times but still, I cannot see any entries in CDHDR/CDPOS.
~ Eric
10-14-2008 10:05 AM
Hi Eric
You need to create an your Z<Object> to create the modification documents (CDHDR/CDPOS), u can do it by trx SCDO.
After creating the object, the system'll generate a fm (usually called <Object name>_WRITE_DOCUMENT) to saved the modification documents and the routines to call that fm.
So u need to change the program for updating of Z<table> in order to insert the call of the fm for modifcation documents.
Max
10-14-2008 10:15 AM
>
> Hi Eric
>
> After creating the object, the system'll generate a fm (usually called <Object name>_WRITE_DOCUMENT) to saved the modification documents and the routines to call that fm.
>
> So u need to change the program for updating of Z<table> in order to insert the call of the fm for modifcation documents.
>
> Max
Hi Max,
I have gotten this far. But I am stuck with the <>_WRITE_DOCUMENT FM since I don't exactly know how to use it. And as there is no documentation, I am lost. Thanks.
~ Eric
10-14-2008 10:37 AM
Hi
For a my z-table (called ZFAGTD01), I created the object for change documents, this is the log after generating it:
Change documents: Display information about generated sources
Change doc. object Z_PROAGE_PRV
Generation on 23.07.2004 11:51:28
of SVIL01
Include programs and function modules
Data declaration, TOP...................... FZAGPCDT
Consisting of............................. FZAGPCDF
and....................................... FZAGPCDV
Update function module..................... Z_PROAGE_PRV_WRITE_DOCUMENT
Call update function module................ FZAGPCDC
Dictionary structures
VZFAGTD01
Just as you see, the system has created the fm and some includes containing all data it needs to call the fm.
So u need only to use those includes, just only u need to consider before calling the fm u need to fill:
- The change flag: usually called UPD_<Z table>;
- Fill the header Y<ZTABLE> of z-table with old data;
- Fill the header X<ZTABLE> of z-table with new data;
- Fill the variables TCODE, UTIME, UDATE, USERNAME,
- Fill the variable OBJECTID with the key of Z-table
For example my object is used in my program in this way:
FORM INSERT_CHANGE_DOCUMENT.
CHECK FL_CHANGE_DOC = 'X'.
CHECK SY-SUBRC = 0.
CONCATENATE XZFAGTD01-MANDT XZFAGTD01-BUKRS XZFAGTD01-GJAHR
XZFAGTD01-BELNR INTO OBJECTID.
TCODE = SY-TCODE.
UTIME = SY-UZEIT.
UDATE = SY-DATUM.
USERNAME = SY-UNAME.
* Load old data: header
IF ZFAGTD0K IS INITIAL.
CLEAR YZFAGTD0K.
ELSE.
SELECT SINGLE * INTO YZFAGTD0K
FROM ZFAGTD0K WHERE BUKRS = XZFAGTD01-BUKRS
AND GJAHR = XZFAGTD01-GJAHR
AND BELNR = XZFAGTD01-BELNR.
ENDIF.
* Load old data: items
SELECT * INTO TABLE YZFAGTD01 FROM ZFAGTD01
FOR ALL ENTRIES IN XZFAGTD01
WHERE BUKRS = XZFAGTD01-BUKRS
AND GJAHR = XZFAGTD01-GJAHR
AND BELNR = XZFAGTD01-BELNR
AND POSNR_P = XZFAGTD01-POSNR_P.
SORT: XZFAGTD01 BY POSNR_P,
YZFAGTD01 BY POSNR_P.
* Check if heade was changed
IF YZFAGTD0K <> ZFAGTD0K.
UPD_ZFAGTD0K = 'U'.
ELSE.
CLEAR UPD_ZFAGTD0K.
ENDIF.
UPD_ZFAGTD01 = 'U'.
PERFORM CD_CALL_Z_PROAGE_PRV.
REFRESH XZFAGTD01.
ENDFORM. " INSERT_CHANGE_DOCUMENT
Max
10-15-2008 3:30 AM
Hi Max,
Another question. The generated FM has the parameter ICDTXT_<ZTable> and it is required. What is the use of this? Or how do I use this? Thanks.
~ Eric
12-07-2010 3:58 PM
Hi. Not to hijack this thread, but I am encountering the same scenario.
I can follow the tips here but at some point, I could not figure out how to populate the old and new tables thingy.
Sample code:
CALL FUNCTION 'Z*****_WRITE_DOCUMENT'
EXPORTING
objectid = c_prog
tcode = sy-tcode
utime = sy-uzeit
udate = sy-datum
username = sy-uname
upd_icdtxt_ztxxetbsid = c_capital_letter_i
upd_ztxxetbsid = c_capital_letter_i
TABLES
icdtxt_ztxxetbsid = is_icdtxt_zprog
xztxxetbsid = is_xprog "new table entries
yztxxetbsid = is_yprog. " old table entries
Can someone please enlighten me?
Best regards
Upon doing research, I found out that ...
"Note : With UPD_<>_CD as 'I', the CDPOS table is created with Insert entry and old and new values are not filled. Old and New values are filled only for U (update) and X<>_CD needs to be filled with new values and Y<>_CD needs to be filled with old values before calling this function module. This creates an entry in CDPOS table with old and new values. "
12-08-2010 8:04 AM
>
> - Fill the header Y<ZTABLE> of z-table with old data;
> - Fill the header X<ZTABLE> of z-table with new data;
>
> Max
Hi Max,
Care to share how do I do this?
I am having trouble filling up the tables with old and new data.
Thanks
10-14-2008 9:58 AM
Easiest way ist to switch on table logging in the technical settings of your table. After this, all changes will be logged in DBTABLOG and can be viewed via SCU3.
Change documents (CDHDR/CDPOS) require far more development work (see tx SCDO), it's not done by just checking that box in the data element.
Thomas
10-14-2008 10:04 AM
>
> Change documents (CDHDR/CDPOS) require far more development work (see tx SCDO), it's not done by just checking that box in the data element.
> Thomas
Hi,
If you don't mind, will you give me the basics on this? I have searched the web and found out that SCDO will generate a function module which needs to be called before any modify, delete, update and etc. to the table. I don't know how to use the generated FM. Thanks.
~ Eric
10-14-2008 11:53 AM
You will get there with Max' help, but I still think that table logging would be the better approach for a single table. Change documents make sense for application data consisting of several hierarchically connected tables, imho.
Thomas
10-15-2008 3:36 AM
Hi Thomas,
I also considered this approach but when I go to SCU3, a message says that table logging is not currently active. How do I activate this? Thanks.
~ Eric
10-15-2008 10:30 AM
Go to the technical settings via tx SE11, activate "log data changes".
In SCU3, you should choose option "evaluation for tables".
Thomas
12-07-2010 9:42 PM
I think that change documents are one way. The other way, by far easier though not recommended by SAP is table logging switched on for the table in dictionary (flag record changes). But system parameter rec/client must be set to ALL clients to record and system rebooted
regards,
Clemens
12-08-2010 2:17 AM
Hi ,
Go to the Technical Settings of the custom table, then check field Log data changes. Then activate the table. Also better to active and adjust the database utility from SE14.
Then in you program use the FM DBLOG_READ_TABLE to get the log.
Also you can select data from table DBTABLOG .
Here you no need to check in CDHDR and CDPOS.
Thanks
Subhankar
12-08-2010 3:44 AM
Hello Subhankar,
Pre-requisite for Table change logging is the param rec/client (as mentioned by Clemens). You need to set the proper value & restart the system to activate the table logging.
BR,
Suhas