ABAP – Change Documents (theory)

Data manipulation in SAP is done using standard documents such as Sales Orders, Purchase Orders, Vendor Invoices etc. Sometimes it’s necessary to make a change a document after it has been saved and created for the first time. From security point of view it is required/imperative that all such changes must be recorded by the system. For this purpose there is a standard functionality implemented in SAP system called “Change Documents”

If all changes are properly logged, it would be possible to find out at any given time:

  • What data has been changed
  • When the change was made
  • Who made the change

Providing this kind of “trace mechanism” makes the analysis of errors much easier and would enhance the robustness of the system. Changes to standard business objects in SAP are logged in Change Documents. This functionality applied on standard business objects can be extended to custom database tables – this will be described in the subsequent sections.

Transactions and steps involved :

Object Class:

The name under which the change document object is created is called the object class. For example the class “VERKBELEG” defines the change document object created by SAP for Sales Orders. This ensures recording of any changes to the sales order tables VBAK, VBAP, VBKD, VBEP and VBPA etc. We can create change document objects for custom tables also. The object may have one or more database tables included in it.

Object ID:

The object ID is the key for recording the particular object value that is being changed. For example if the sales order “1234567” was changed by some user, the change document would record these changes under the object class  “VERKBELEG” and the object ID “1234567”. However, this is not necessarily the key of the particular DB table being logged – rather, it indicates the object at header level that is being changed. For example, if changes were to be logged to Sales Order Item table (VBAP), then also the Object ID would remain the Sales Order Number. We do not need to include the item number in the object ID.

Change Document Number:

The change document number is a number that is issued automatically by the system to each change that has been recorded for the object, i.e., each time a change document header record is created.

Change Flag:

This is a flag that is set, which determines the nature of changes that have been made. This flag can take the following values:

  • U – This indicates that an UPDATE has been made
  • I – This indicates that data was INSERTED into the database table
  • D – This indicates that data has been DELETED from the table
  • E – This indicates that a table record with field documentation has been deleted (single field documentation).

Transaction Code (SCDO):

The transaction code SCDO is used for creating change document objects. The menu path for accessing the same is: Tools -> ABAP Workbench -> Development -> Other Tools -> Change Documents.

Change Document Header table (CDHDR):

The database table CDHDR stores the header data of any changes logged in the system. For example, object class, object ID, change document number, the user ID of the user who made changes, the date and time at which the change was made, the transaction code through which change was made, etc.

Change Document Item table (CDPOS):

The database table CDPOS stores the actual changes that have been made, i.e., the table name, field name, table key for the entry that has been changed, old value, new value, change flag etc.

Steps that are necessary to enable logging of changes in change documents

  1. Decide the database table that you want to include in the change document object. You usually would not need to log changes for all fields of the table – decide which fields’ changes need to be logged for.
  2. For each of the above fields, go to the data-element and check the “further characteristics” tab. Here there is a checkbox called “change document”. Ensure that this checkbox is checked for all data-elements of the fields that need to be logged.
  3. Create and complete the definition of the change document object through transaction SCDO.
  4. Integrate the objects generated in above step into the program(s) through which you want changes to be logged. The change document will log only those changes to the table, that have been made through the program(s) into which this functionality is integrated.
  5. You can display the changes that had been logged in change documents using the standard report RSSCD200.

Leave a Reply