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


Provide the function group and click on the generate button.  


9. The following screen appears.  

When we see the above information one function module (ZCHOBJ_WRITE_DOCUMENT) is generated. The naming convention of this generated function module is as follows.  

Name of the changing document object + keyword (WRITE_DOCUMENT).  

Click on the save button.  

Now we will use this function module to maintain the logs in CDPOS & CDHDR tables.

11. Now see the parameters of this generated function module.  

When we see the parameters of this function module it has 2 parameters. (N_ZEMP_TABLE, O_ ZEMP_TABLE).  

Where N stands for new data & O stands for old data. The naming conventions of these generated parameters are as follows-  

N_name of the table & O_name of the table.  

Imp Points:

  1. To maintain a log for the insert entries: Pass the data to the new parameter. (N_ZEMP_TABLE).
  2. To maintain a log for the update entries: Pass the new data to the new parameter (N_ZEMP_TABLE) and old data to the old parameter. (O_ZEMP_TABLE) 
  3. To maintain a log for the Delete entries: Pass the data to the old parameter (O_ZEMP_TABLE).   

Now we will maintain log for insert, update and delete entries.  

12. Insert Log: We will insert one entry in table ZEMP_TABLE and maintain   the insertion log in CDHDR and CDPOS table.    

Create one executable program and write the following code.  

REPORT  zinsert.

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-empid = 
ls_emp-ename = 
ls_emp-eloc = 

INSERT zemp_table FROM ls_emp.

lv_objectid = ls_emp-empid.
ls_emp_new = ls_emp.

    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 = 
    icdtxt_zchobj  = lt_cdtxt.

Note: In case of insertion pass the value of the parameter UPD_ZEMP_TABLE = ‘I’.  

Execute the program.  

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


Now check the log in CDHDR and CDPOS tables.  

Go to table CDHDR and Pass the object class ‘ZCHOBJ’ (Which we have created using SCDO) and creation date (UDATE). (We can also give additional filter criteria).  

Click here to continue...

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