How to maintain log for custom tables (Log Maintenance in CDHDR & CDPOS tables)

...Previous

Execute it and we will get the record in table CDHDR.

 

Copy the object class (OBJECTCLAS), object id (OBJECTID) and Document change number (CHANGENR) and go to table CDPOS. 

Provide the object class, object id and document change number.

 

Execute it and the Table CDPOS consists of following data.

So the log for insert in maintained in CDPOS and CDHDR table.  

13. Update log: In this we will change the Employee name (ENAME) to ‘EMPLOYEE’ and Employee Location (ELOC) to ‘KURUKSHETRA’ in table ‘ZEMP_TABLE’ and maintain the Updation log.  

Create one executable program and write the following code.  

REPORT  ZCHANGE.

DATA:ls_emp TYPE zemp_table.
DATA:ls_emp_new TYPE zemp_table.
DATA:ls_emp_old TYPE zemp_table.
DATA:lt_cdtxt TYPE TABLE OF cdtxt.
DATA:lv_objectid TYPE cdhdr-objectid.


ls_emp_new-empid = 
'1'.
ls_emp_new-ename = 
'EMPLOYEE'.
ls_emp_new-eloc = 
'KURUKSHETRA'.

MODIFY zemp_table FROM ls_emp_new.

ls_emp_old-empid = 
'1'.
ls_emp_old-ename = 
'STUDENT'.
ls_emp_old-eloc = 
'GANDHINAGAR'.

lv_objectid = ls_emp_new-empid.

CALL FUNCTION 'ZCHOBJ_WRITE_DOCUMENT'
  
EXPORTING
    objectid       = lv_objectid
    tcode          = sy-tcode
    utime          = sy-uzeit
    udate          = sy-datum
    username       = sy-uname
    n_zemp_table   = ls_emp_new
    o_zemp_table   = ls_emp_old
    upd_zemp_table = 
'U'
  
TABLES
    icdtxt_zchobj  = lt_cdtxt.
 

Note: In case of Updation pass the value of the parameter UPD_ZEMP_TABLE = ‘U’.  

Execute the program.  

After executing the program the table ZEMP_TABLE consists of following data.

Now check the log in CDHDR and CDPOS tables.  

CDHDR Entries:  

CDPOS Entries:

In the field VALUE_NEW we will get the new values and in the field VALUE_OLD we will get the old values.  

14. Delete Log: In this we will delete this entry from table ‘ZEMP_TABLE’ and maintain the deletion log.  

Create an executable program and write the following code.  

REPORT  zdelete.

DATA:ls_emp TYPE zemp_table.
DATA:ls_emp_new TYPE zemp_table.
DATA:ls_emp_old TYPE zemp_table.
DATA:lt_cdtxt TYPE TABLE OF cdtxt.
DATA:lv_objectid TYPE cdhdr-objectid.

ls_emp_old-empid = 
'1'.
DELETE zemp_table FROM ls_emp_old.

lv_objectid = ls_emp-empid.

CALL FUNCTION 'ZCHOBJ_WRITE_DOCUMENT'
  
EXPORTING
    objectid       = lv_objectid
    tcode          = sy-tcode
    utime          = sy-uzeit
    udate          = sy-datum
    username       = sy-uname
    n_zemp_table   = ls_emp_new
    o_zemp_table   = ls_emp_old
    upd_zemp_table = 
'D'
  
TABLES
    icdtxt_zchobj  = lt_cdtxt.
 

Note: In case of deletion pass the value of the parameter UPD_ZEMP_TABLE = ‘D’.  

Execute the program. After executing the program the entry will be deleted from the table ZEMP_TABLE.  

Now check the log in CDHDR and CDPOS tables.  

CDHDR Entries:

CDPOS Entries:

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image