Skip to Content
Technical Articles
Author's profile photo Shaurya Tripathi

Complete process to create Change Document in ABAP and SAPUI5

Requirement:

To show the record of changes in ‘city’ and ‘name’ defined as fields in customer-specific table using SAP Fiori app.

Solution:

Create Change Document Object for the respective table.

Implementation:

Step by step procedure to implement the solution.

Part1:

  • Create table and Activate the change document for the required fields (transaction SE11).
  • Create the change document with Change Document Objects (transaction SCDO).

Part2:

  • Expose CDS views and Insert the appropriate calls in the corresponding redefined methods.
  • Incorporate UI changes.

Creation of Change Document Object in ABAP:

  1. Run the transaction code SE11.
  2. Create a table ‘ZDB_STUDENT’. (For which you want to keep change document). Column name: MNDT, GUID, NAME, DOB, CITYTable
  3. Maintain a user defined Data Element and in ‘Further Characteristics’ check the box for ‘Change Document’ for those fields you want to maintain changes.Data%20Element

Note: Don’t check ‘log changes’ for the table in technical settings.

  1. Run the transaction code SCDO.
  2. Now create a change document for the table. Give ’zcd_student’ name of the change document object and click ‘create’ button.scdo_1
  1. Follow the instructions in the next dialog box and enter the package name, to which the change document object belongs, and enter a transport request. Click on ‘save’ button.scdo_2
  2. In the dialog box ‘Properties of Change Document Object’, enter a description for the change document under Text and enter the database tables that belong to this info type under Table. Save these changes and then click on ‘Generate’.scdo_3
  3. The “Generate Update Pgm” dialog box is displayed. Fill the required details and give the name of function group. This function group will contain function module and includes, generated by further process. Then click on ‘Generate’ button.scdo_4 scdo_5
  4. Then click on the ‘Activate’ button.scdo_6
  5. After this process Change Document Object is created and we can use created function module and includes to track created, updated and deleted entries.scdo_7

Changes will be logged in the following tables: CDHDR and CDPOS. CDHDR is a header table and CDPOS contains the actual data. Created function module ‘ZDB_STUDENT_CD_WRITE_DOCUMENT’ will be used to write changes to these tables.cdhdr

cdhdr

cdpos

cdpos

  1. Create a CDS view for the ‘ZDB_C_STUDENT’ database table in SAP HANA Studio/Eclipse.

Expose CDS views to OData service.

  1. Run the transaction code SEGW.
  2. Expose the CDS view to OData service.OData%20ServiceCDS%20ExposeCDS%20Expose_2

And redefine methods in data provider class (dpc_ext).

  1. Create_Entity Method ==> In this method:
    1. Read data (received from the front-end) using ‘io_data_provider’ into ‘ls_data’ work area.
    2. Insert entry into database table to create new record.
    3. After creating entry, write following code to create entry for change document.
      DATA: lt_cdtxt TYPE STANDARD TABLE OF cdtxt,
            lt_xstu TYPE STANDARD TABLE OF YZDB_STUDENT,
            ls_xstu TYPE YZDB_STUDENT.
      
        MOVE-CORRESPONDING ls_data TO ls_xstu.
        ls_xstu-kz = 'I'.
        APPEND ls_xstu TO lt_xstu.
      
        CALL FUNCTION 'ZDB_STUDENT_CD_WRITE_DOCUMENT' "Create Change Doc for New Domain
          EXPORTING
            objectid                  = CONV cdobjectv( lv_guid )
            tcode                     = sy-tcode
            utime                     = sy-uzeit
            udate                     = sy-datum
            username                  = sy-uname
            object_change_indicator   = 'I'
            upd_icdtxt_zdb_student_cd = 'I'
            upd_zdb_student           = 'I'
          TABLES
            icdtxt_zdb_student_cd     = lt_cdtxt
            xzdb_student              = lt_xstu.​

After successful creation of entry in database, we’ll call ‘ZDB_STUDENT_CD_WRITE_DOCUMENT’ function module to create entry in change document object.

  1. Update_Entity Method ==> In this method:
    1. Read data (received from the front-end) using ‘io_data_provider’ into ‘lt_new’ table.
    2. Before updating database record, select the old record into ‘ls_data’ work area.
      SELECT SINGLE * FROM ZDB_STUDENT INTO @DATA(ls_data) WHERE guid EQ @lv_guid. "#EC CI_ALL_FIELDS_NEEDED​
    3. Write the logic to update database record.
    4. After Updating record in database table, write following code to maintain changes for change document.
      DATA: lt_cdtxt TYPE STANDARD TABLE OF cdtxt,
            lw_cdtxt TYPE cdtxt,
            lt_xstu TYPE STANDARD TABLE OF YZDB_STUDENT,
            ls_xstu TYPE YZDB_STUDENT,
            lt_ystu TYPE STANDARD TABLE OF YZDB_STUDENT.
      
            MOVE-CORRESPONDING lt_new TO lt_xstu.
            READ TABLE lt_xstu INTO ls_xstu INDEX 1.
            REFRESH lt_xstu.
            ls_xstu-guid = lv_guid.
            ls_xstu-mandt = sy-mandt.
            ls_xstu-kz = 'U'.
            APPEND ls_xstu TO lt_xstu.
      
            CLEAR ls_xstu.
            MOVE-CORRESPONDING ls_data TO ls_xstu.
            ls_xstu-kz = 'U'.
            APPEND ls_xstu TO lt_ystu.
      
            CALL FUNCTION 'ZDB_STUDENT_CD_WRITE_DOCUMENT' " Function Module for writing changes in Change Documents
              EXPORTING
                objectid                = conv CDOBJECTV( lv_guid )
                tcode                   = sy-tcode
                utime                   = sy-uzeit
                udate                   = sy-datum
                username                = sy-uname
                object_change_indicator = 'U'   " For Updating 
                upd_zdb_student        = 'U'
              TABLES
                icdtxt_zdb_student_cd        = lt_cdtxt
                XZDB_STUDENT                  = lt_xstu  " Updated Data 
                YZDB_STUDENT                  = lt_ystu. " Old Data ​
  1. Delete_Entity Method ==> In this method:
    1. Take primary key(’iv_guid’) of the record to be deleted.
    2. Before deleting record from the database, select the record into ‘ls_xstu’ work area.
    3. Write the logic to delete database record.
    4. After deleting record from the database table, write code to maintain changes for change document.
      DATA: lt_cdtxt TYPE STANDARD TABLE OF cdtxt,
            lt_xstu TYPE STANDARD TABLE OF YZDB_STUDENT,
            ls_xstu TYPE YZDB_STUDENT,
            lt_ystu TYPE STANDARD TABLE OF YZDB_STUDENT.
      
        SELECT SINGLE * FROM ZDB_STUDENT INTO ls_xstu WHERE guid = iv_guid. "#EC CI_ALL_FIELDS_NEEDED
        DELETE FROM ZDB_STUDENT WHERE guid =  iv_guid.
      
          ls_xstu-kz = 'D'.
          APPEND ls_xstu TO lt_ystu.
          CALL FUNCTION 'ZDB_STUDENT_CD_WRITE_DOCUMENT' " Create Change Document for Deleted Domain
            EXPORTING
              objectid                = conv CDOBJECTV( iv_guid )
              tcode                   = sy-tcode
              utime                   = sy-uzeit
              udate                   = sy-datum
              username                = sy-uname
              object_change_indicator = 'D'
              upd_zdb_student            = 'D'
            TABLES
              icdtxt_zdb_student_cd   = lt_cdtxt
              YZDB_STUDENT         = lt_ystu.​
  1. Expose ‘C_ChangeDocuments’ CDS view in OData Service. This CDS view will fetch data from CDHDR and CDPOS tables. This is standard CDS view to show the details of all available change document objects. To see the change records of only our change document object, we will filter records from the UI based on change document object name (ChangeDocObjectClass) and primary key field of our database table (ChangeDocObject).

SAPUI5 Changes

  1. Create Project.
  2. OData service:
    1. Add destination for OData service.
    2. Right click on the project and then click on new then choose OData service.
  3. View and Controller.
    1. ‘Main’ View: Create a ‘Main’ view to show the records of ‘zdb_student’ table. Create a smart table and bind it to created CDS entity for ‘zdb_student’ table.
    2. ‘ChangeHistory’ View: Create another view to show the list of changes made in ‘city’ and ‘name’ field of the selected record from ‘Main’ view. Create a smart table in view and on ‘beforeRebindTable’ event, add filter and set ‘entitySet’ to this smart table.
      beforeRebindTable%20Event

      • Set ‘setDefaultCountMode’ of model to ‘inline’ so that there is no OData call to count.
      • Then it will set following filters to make sure that only necessary records are being fetched.
        • ‘ChangeDocObjectClass’ should be equal to ’zcd_student’ (Change Document of ‘zdb_student’ table).
        • ‘ChangeDocObject’ should be equal to value of Key (primary key of the record).
      • Then set property ‘setEntitySet’ to ‘C_ChangeDocuments’ of change history smart table.

This is the whole process to create the change document object for your customer specific table in ABAP and displaying changes in a SAP Fiori App.

Assigned tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Albert Moran Lopez
      Albert Moran Lopez

      Hi,

      Thanks for all the info, is very usefull!

      I made a SAP Fiori App where I also want to make the updates and not only see them. In my case I used entity and entity set imported from DDIC structures and mapped the update_entity to an RFC module function.

      My problem is when I call my mapped function to update via Fiori App,  the sy-tcode is empty. Is it a problem and I have to put another text on the tcode import variable of the function who creates change documents or can I leave it blank?