This document briefly describes how to create a 'Change Document' for a business object.
Let us start with an example for clear understanding and to know the importance of the 'Change Document'.
- Consider MM01 transaction, here MATNR is a primary key as well as 'Change Document Object'.
- Now we try to create a Material in the MM01.
- Now once we finish creating a material, we can find that a new material has been inserted not only from the MARA table or any other material related table but also from the tables 'CDHDR' or 'CDPOS'.The material we have created in 'CDHDR' table will be something like this.
- Here since the material number i.e. MATNR is a 'Change Document Object' which we will be seeing shortly, a log has been created in the 'CDHDR' table.
- We can as well see the 'Deletion' and 'Update' logs also.
- Thus there is huge significance for 'Change Document' and it can be really helpful for objects which are subject to change. Like MATNR in the above case.
- In financial accounting 'Change Document' can also be used for Auditing Purpose.
- If changes are not yet to be made, but are planned, they can be logged as planned changes. A planned date for the changes can be specified.
Structure of the Change Document:
Ø Change Document Header (Object ID)
Ø Change Document Item (Contains Old and New value of a field and a Change Flag).
Ø Change Document Number (Issued when the change is logged).
Certain essential features of 'Change Document' have been discussed below:
- It is useful for Error analysis.
- The object we think is significant enough to have a 'Change Document' should be 'Change Document Object' ,that is it has to be declared as such at Data Element level itself by checking the checkbox beside 'Change Document' .
- A change object can be maintained for a single Object or for Multiple Objects. (Ex. MATNR and ERSDA both from the MARA table are Change Document Objects besides others).
Now we will see a detailed step by step processing of Creating Change Document for a Ztable(having multiple 'Change Document Objects') involving a ZReport and a Ztransaction .
The procedure to create a Change Document for a given Object .
- Go to transaction SCDO.
- A screen shown as above is displayed.
- Since we are creating a new Change Document
- Go to Create.
- A pop-up box is displayed where we have to enter a Name Space if required.
- The name of the Change Document Object should be given and press 'Continue'.
- Say 'Yes' to proceed further since we have not mentioned any Namespace this has come up.
- Then we get this particular screen where we have to enter a table name and check the checkbox 'Copy as internal tab. 'since there are 2 change document objects in table.
- Because there are 2 Change Document objects we have to pass them to an internal table or if there is only a single Change Document Object we need not check this checkbox.
- Then save it and the screen below appears.
- Now say BACK.
- The screen below appears we find that the object created by us on the list of objects.
- Place the cursor at our object and Click 'Generate Update Prog.'.
- A pop-up box appears as shown below say 'YES'.(This is Because we haven't mentioned any Name Space).
- A Pop-up box appears now, we have to enter a Include Name , Function group Name and choose the mode of update etc .
- Now say, 'Generate '.
- Some very crucial Data is generated here and there are 3 types of Includes and 1 Function Module which are of our prime importance.
- The 3 types of include are F_<k4>CDT, F<k4>CDF_ and F<k4>CDV.
- The Function Module id created for us 'Objectid_WRITE_DOCUMENT'.
- Now we have finished creating a Change Document for our Objects .
- The Next step is to Call the respective Includes and the Function Module in our program of SE38 editor .
1 We have to just include a 'F<k4>CDT' in our program because it contains both the 'CDV and CDF' include in it .(we can check it by Double clicking the include 'CDT' ) .
2 Now we have to insert entries into our table from the program itself .
The Code to insert an entry from the program to a table having fields Rollno , Name and Class where Rollno and Name are Change Document Objects is as follows :
Here, We Declared a field string of type our table and then declared a Table (t_cd ) .
Now we are Appending Entries into the table t_cd and then we are Inserting these entries into our ZTable .
3 Now we have to Call the Function Module that has been generated in our 'SCDO' transaction .( if sy-subrc = 0 )
4 All the values in the Function Module has to be filled as above .
5 The fields at the end XYH1330_CD and YYH1330_CD are for the multiple change document objects we have taken .
6 Now we have to execute the program.
Note : With UPD_<>_CD as 'I', the CDPOS table is created with Insert entry and old and new values are not filled. Old and New values are filled only for U (update) and X<>_CD needs to be filled with new values and Y<>_CD needs to be filled with old values before calling this function module. This creates an entry in CDPOS table with old and new values.
We can see the Change logs in 2 tables 'CDHDR' and 'CDPOS'.
Ø Go to 'SE11' and go to table 'CDHDR' or 'CDPOS'.
Ø Enter our Object ID in the respective field and execute.
Ø Change can be displayed for our insertion.
Ø Similarly we see the logs for Updating or Deletion also.
This is how the Change Document log looks like in 'CDHDR table.
Thus we can see the changes in these tables.
They also provide us with old value and new value.