Friday, March 11, 2011

ABAP creating audit trail by change document table CDPOS CDHDR

There are some cases wherein you may want to create an audit trail or a history/log for your application. One way of doing this is by utilizing the CDPOS and CDHDR table by generating a program by it.


I have found a resources in doing this and I'm thankful for this link below:

Creating Change Document in SAP

Don't forget to check the box below if you want the fields of the record you've been deleted will be saved:
SCDO tcode to manage cdhdr cdpos for logs


You may also want to use this code for your insert:

     call FUNCTION 'ZZOMNIRATE_WRITE_DOCUMENT'
     exporting
       objectid =  at_reason
       tcode = sy-tcode
       utime = sy-uzeit
       udate = sy-datum
       username = sy-uname
       planned_change_number = ''
       object_change_indicator = 'I'
       planned_or_real_changes = 'I'
       no_change_pointers = ''
       UPD_ICDTXT_ZZOMNIRATE = 'I' "'U'
       N_ZOMNI_RATE = gs_test "new
       O_ZOMNI_RATE = ls_test "old
       UPD_ZOMNI_RATE =  'I' "'U'
       lv_opt = ''
     tables
       ICDTXT_ZZOMNIRATE = gt_change.

And this one for delete:

     call FUNCTION 'ZZOMNIRATE_WRITE_DOCUMENT'
     exporting
       objectid =  at_reason
       tcode = sy-tcode
       utime = sy-uzeit
       udate = sy-datum
       username = sy-uname
       planned_change_number = ''
       object_change_indicator = 'D'
       planned_or_real_changes = 'D'
       no_change_pointers = 'D'
       UPD_ICDTXT_ZZOMNIRATE = 'D'"'U'
       N_ZOMNI_RATE = gs_test "new
       O_ZOMNI_RATE = ls_test "old
       UPD_ZOMNI_RATE = 'D'"'U'
       lv_opt = 'X'
     tables
       ICDTXT_ZZOMNIRATE = gt_change.

Thanks!

No comments:

Post a Comment