Change Documents:
1. Concept:

For changes to a commercial object to be able to be logged in a change document, the object must have been defined in the system as a change document object. A change document object definition contains the tables which represent a commercial object in the system. The definition can also specify whether the deletion of individual fields is to be documented. If a table contains fields whose values refer to units and currency fields, the associated table, containing the units and currencies, can also be specified.

It must be specified for each table, whether a commercial object contains only one (single case) or several (multiple case) records. For example, an order contains an order header and several order items. Normally one record for the order header and several records for the order items are passed to the change document creation when an order is changed.

Change document: A change document logs changes to a commercial object. The document is created independently of the actual database change. The change document structure is as follows:

  • Change document header
    The header data of the change to an object ID in a particular object class are stored in the change document header. The change document number is automatically issued.
  • Change document item
    The change document item contains the old and new values of a field for a particular change, and a change flag.
    The change flag can take the following values:
    • U(pdate)
      Changed data. (Log entry for each changed field which was flagged in the Dictionary as "change document-relevant")
    • I(nsert)
      Data inserted.
      Changes: Log entry for the whole table record
      Planned changes: Log entry for each table record field
    • D(elete)
      Data were deleted (log entry for the whole table record)
    • I(ndividual field documentation)
      Delete a table record with field documentation
      1 log entry per field of the deleted table entry, the deleted text is saved
  • Change document number
    The change document number is issued when a change is logged, i.e. when the change document header is created by the change document creation function module (function group SCD0).

The change number is not the same as the change document number. The change document number is issued automatically by the function group SCD0 function modules when a change document is created for a change document object. The change number is issued by the user when changes are planned. The same change number can be used for various change document objects.

2. How to Create Change Documents Object:

a)      Prerequisite: Transparent table for which Change Log has to be maintained.

Make sure that the field for which change log is to be maintained is checked as CHANGE DOCUMENT.

For this issue, double click the field and find the data-element maintained, choose the tab 'Further Characteristics' and then check change-document.[]b)     Creating Change Documents:
STEP 1: Call Change Document transaction code SCDO.

STEP 2: Click CREATE (F5) to create Change Document Object.
STEP 3: Enter name of Change Document Object name to be created, make sure it should begin with 'Y' or 'Z'. And press 'Continue'.

STEP 4: Enter Short-text about the object. Mention table name for which change log has to be maintained. Check 'Copy as Internal tab' (If the change data are to be passed in an internal table (multiple case), mark this field. If it is not marked, the change data are passed in a work area (single case)).

(If the currency and unit fields are defined in a reference table, rather than in the table passed, you must pass the name of the reference table, and the field referred to, to the function module. Create an INTTAB structure in the Dictionary, and define fields for this structure, which are made up of the names of the associated reference table and the reference fields.
Enter the name of this structure here.
In the individual case, the reference information is passed in the form of two extra work areas (old, new). In the collective case, the internal tables are extended to include the reference structure.

-          Name of the old record fields
Only possible for single case, i.e. when passing change data in a work area: If you do not want to use the * work area, enter an alternative work area name here.)

Finally, click 'Insert Entries'.


STEP 5: SAVE the entries made to change document object.

STEP 6: Click Generate Update PGM, to generate corresponding Function Modules.


STEP 7: Enter Function Group existing in the SAP system, and select 'Immediate update' to have immediate reflection of changes made.Click 'Generate'.

STEP 8: Get onto the 'Change Document Overview' screen and click on 'Generate Info(F6)' to get the wholesome information of the change-document object, with which a report in (SE38) can be created.

Make a note of the general information provided.

 3. How to use Change Documents Object in a Program:

STEP 1: Call transaction code SE38 (ABAP Editor).

              Create a Program.

              Include Program 'FYH1311_DETAILSCDT' on TOP, which consists of data declarations and table structures.

STEP 2: Note the contents of both either of includes,

FYH1311_DETAILSCDF.DATA: OBJECTID                                          TYPE CDHDR-OBJECTID,
              TCODE                                               TYPE CDHDR-TCODE,
              PLANNED_CHANGE_NUMBER    TYPE CDHDR-PLANCHNGNR,
              UTIME                                                TYPE CDHDR-UTIME,
              UDATE                                               TYPE CDHDR-UDATE,
              USERNAME                                       TYPE CDHDR-USERNAME,
              CDOC_PLANNED_OR_REAL         TYPE CDHDR-CHANGE_IND,
                CDOC_UPD_OBJECT                      TYPE CDHDR-CHANGE_IND VALUE 'U',
                CDOC_NO_CHANGE_POINTERS TYPE CDHDR-CHANGE_IND.
 
FYH1311_DETAILSCDV.* declaration for the long text
DATA: BEGIN OF ICDTXT_YH1311_DETAILS OCCURS 20.
        INCLUDE STRUCTURE CDTXT.
DATA: END OF ICDTXT_YH1311_DETAILS.
DATA: UPD_ICDTXT_YH1311_DETAILS TYPE C.
* table with the NEW content of: ZAHACK
DATA: BEGIN OF XZAHACK OCCURS 20.
        INCLUDE STRUCTURE YZAHACK.
DATA: END OF XZAHACK.
* table with the OLD content of: ZAHACK
DATA: BEGIN OF YZAHACK OCCURS 20.
        INCLUDE STRUCTURE YZAHACK.
DATA: END OF YZAHACK.
 DATA: UPD_ZAHACK TYPE C.
   STEP 3:
(SINGLE-CASE)

Create a field string for the database table 'zahack', including its all fields. DATA:
  fs_emp TYPE zahack.
Create a field string and an internal table for 'Change Documents: Text Changes', to pass the changes made to the fields of 'zahack' table.
*---------------------------------------------------------------------*
* FIELD-STRING FOR CHANGE DOCUMENTS: TEXT CHANGES                     *
*---------------------------------------------------------------------*
DATA:
  fs_cdtxt TYPE cdtxt.
 *---------------------------------------------------------------------*
* TABLE FOR CHANGE DOCUMENTS: TEXT CHANGES                            *
*---------------------------------------------------------------------*
DATA:
           t_cdtxt   LIKE
  STANDARD TABLE
                  OF fs_cdtxt.
Insert a record into 'zahack' table; simultaneously append data in 'ICDTXT_YH1311_DETAILS', 'XZAHACK' and 'YZAHACK'.
fs_emp-empid = 'YH1311'.
fs_emp-name = 'Tanveer Zahaque'.
fs_emp-dept = 'ABAP'.
fs_emp-salary = '25000'.
INSERT zahack FROM fs_emp.
 APPEND ICDTXT_YH1311_DETAILS.
APPEND xzahack.                        " Table with Old Content
APPEND yzahack.                        " Table with New Content
NOTE: Check SY-SUBRC value before calling function-module 'YH1311_DETAILS_WRITE_DOCUMENT', since function-module will be called and inappropriate values get entered even if the insertion fails.
upd_icdtxt_yh1311_details       = 'I', can be in I(nsert), U(pdate), D(elete) modes.
IF sy-subrc EQ 0.
  CALL FUNCTION 'YH1311_DETAILS_WRITE_DOCUMENT'
    EXPORTING
      objectid                        = objectid
      tcode                            = sy-tcode
      utime                            = sy-uzeit
      udate                            = sy-datum
      username                      = sy-uname
*   PLANNED_CHANGE_NUMBER           = ' '
     object_change_indicator                            = 'I'
*   PLANNED_OR_REAL_CHANGES        = ' '
*   NO_CHANGE_POINTERS                      = ' '
     upd_icdtxt_yh1311_details                        = 'I'
     upd_zahack                                                = 'I'
    TABLES
      icdtxt_yh1311_details   = icdtxt_yh1311_details
      xzahack                         = xzahack
      yzahack                         = yzahack.
  MESSAGE 'Log Created' TYPE 'S'.
ELSE.
  MESSAGE 'Insert Error' TYPE 'S'.
ENDIF.                                 " IF SY-SUBRC EQ 0
 STEP 4:
(MULTIPLE-CASE)

Create a field string for the database table 'zahack', including its all fields.DATA:
  fs_emp TYPE zahack.

Create an Internal table for field string 'fs_emp'.DATA:
              t_emp LIKE
  STANDARD TABLE
                  OF fs_emp.
Create a field string and an internal table for 'Change Documents: Text Changes', to pass the changes made to the fields of 'zahack' table.
*---------------------------------------------------------------------*
* FIELD-STRING FOR CHANGE DOCUMENTS: TEXT CHANGES                     *
*---------------------------------------------------------------------*
DATA:
  fs_cdtxt TYPE cdtxt.
 *---------------------------------------------------------------------*
* TABLE FOR CHANGE DOCUMENTS: TEXT CHANGES                            *
*---------------------------------------------------------------------*
DATA:
             t_cdtxt LIKE
  STANDARD TABLE
                  OF fs_cdtxt.
Insert a record into 'zahack' table; simultaneously append data in 'ICDTXT_YH1311_DETAILS', 'XZAHACK' and 'YZAHACK'.
fs_emp-empid = 'YH1311'.
fs_emp-name = 'Tanveer'.
fs_emp-dept = 'ABAP'.
fs_emp-salary = '25000'.
APPEND fs_emp TO t_emp.
 fs_emp-empid = 'YH1312'.
fs_emp-name = 'Sudha'.
fs_emp-dept = 'ABAP'.
fs_emp-salary = '25000'.
APPEND fs_emp TO t_emp.
 fs_emp-empid = 'YH1313'.
fs_emp-name = 'Rama'.
fs_emp-dept = 'XI'.
fs_emp-salary = '25000'.
APPEND fs_emp TO t_emp.
 fs_emp-empid = 'YH1314'.
fs_emp-name = 'Jyoti'.
fs_emp-dept = 'XI'.
fs_emp-salary = '25000'.
APPEND fs_emp TO t_emp.
 fs_emp-empid = 'YH1315'.
fs_emp-name = 'Kiran Saka'.
fs_emp-dept = 'ABAP'.
fs_emp-salary = '25000'.
APPEND fs_emp TO t_emp.
 fs_emp-empid = 'YH1316'.
fs_emp-name = 'Richa Tripathi'.
fs_emp-dept = 'ABAP'.
fs_emp-salary = '25000'.
APPEND fs_emp TO t_emp.
 INSERT zahack FROM TABLE t_emp.
 APPEND icdtxt_yh1311_details.
APPEND xzahack.                        " Table with Old Content
APPEND yzahack.                        " Table with New Content
upd_icdtxt_yh1311_details       = 'I', can be in I(nsert), U(pdate), D(elete) modes.
IF sy-subrc EQ 0.
  CALL FUNCTION 'YH1311_DETAILS_WRITE_DOCUMENT'
    EXPORTING
      objectid                        = objectid
      tcode                           = sy-tcode
      utime                           = sy-uzeit
      udate                           = sy-datum
      username                     = sy-uname
*   PLANNED_CHANGE_NUMBER           = ' '
     object_change_indicator         = 'I'
*   PLANNED_OR_REAL_CHANGES         = ' '
*   NO_CHANGE_POINTERS              = ' '
     upd_icdtxt_yh1311_details       = 'I'
     upd_zahack                               = 'I'
    TABLES
      icdtxt_yh1311_details           = icdtxt_yh1311_details
      xzahack                                 = xzahack
      yzahack                                 = yzahack.
  MESSAGE 'Log Created' TYPE 'S'.
ELSE.
  MESSAGE 'Insert Error' TYPE 'S'.
ENDIF.                                 " IF SY-SUBRC EQ 0
STEP 5: Open 'CDHDR' - 'Change Document Header'.
              Utilities->Table Contents-> Display.

 Enter change document object name and execute (F8).
Similarly, open 'CDPOS' - 'Change Document Item', to draw items information.
NOTE: In the above example, we tried with only I(nsert), in the same fashion U(pdate), D(elete) can also be tried.

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐