Sap Change Documents for Custom Table and Fields

Create Change Document for Custom Table e1442419531234

This post will explain how to Create Sap Change Documents for Custom Table or Field step by step.



Change Documents Overview

Let’s first have a look on the result, we expect for this change tracking
For example, change in FI Document ( tcode FB03 to display a document and SAP Table BKPF )
To Display Changes on Document, Environment > Document Changes

Sap Change Document for Custom Table schema

All the changes are displayed as following with old value and new value for each modified field.
( Change Document tracking manage change on field level )

Sap Change Document for Custom Table

In order to compare new value and old value, go to All Changes

Sap Change Document for Custom Table All changes

Technical Overview for Change Documents

Change Documents?Objects and Tables
Technically, the changes on Document are saved in these both tables
CDHDR : Change document header
CDPOS : Change document items

The object class assigned to Business Objects can be customized in tcode SCDO (Display Change Document Objects)

SCDO- Change Documents Object

Sap Change Documents for Custom Fields
The Update function module for FI document is BELEG_WRITE_DOCUMENT

Let take for example for zzField on BKPF, object class assigned to FI document should be BELEG
Sample code following can be modified to adjust your requirement.
Or you can call directly the FM BELEG_WRITE_DOCUMENT, don’t forget to run commit work because this function module must run in UPDATE MODE in order to not disturb the main business process.

INCLUDE FF05LCDT.
 
SELECT SINGLE * FROM BKPF WHERE BUKRS = p_companycode
                            AND BELNR = p_invoicedocnumber
                            AND GJAHR = p_fiscalyear.
CHECK SY-SUBRC = 0.
" Old data 
*BKPF = BKPF.
 
" New data
BKPF-zzfield = p_link.
MODIFY BKPF.
 
UPD_BKDF  = 'X'.
INCLUDE FF05LCDC.

Sap Change Documents for Custom Table

In order to manage change document ( history ) on customize table, a change document object have to be create.

  1. Create Change document Object (SCDO)Create Change document Object
  2. Assign tables to CDO (SCDO)Assign tables to CDO
  3. Generate CDO Update Program (SCDO)Generate CDO Update Program
  4. Generate Update Program and *WRITE_DOCUMENT Function
    Generate Update Program and *WRITE_DOCUMENT Function

For me information, check the sap help documentation on Create a Change Document Object.