Architecture Guide #21 • ABAP Cloud Audit Logging

SAP Change Documents & Audit Trail Architecture in ABAP Cloud

A comprehensive engineering guide on configuring Change Document Objects (CHDO) and implementing CL_CHDO_WRITE_TOOLS and CL_CHDO_READ_TOOLS in Clean Core SAP RAP applications.

Interactive Generator: You can automatically configure and generate the complete Change Document Object writer, reader, and RAP behavior pool implementation with our In-Browser Change Document Generator.

1. The Evolution of Change Documents in SAP

In classic SAP ERP (ECC 6.0 and standard ABAP), audit logging was achieved by defining change document objects in transaction SCDO. The generation program created function modules (e.g. <OBJECT>_WRITE_DOCUMENT) with classic update task execution (IN UPDATE TASK).

Under Clean Core Tier-1 (ABAP Cloud):

2. Architectural Comparison: SCDO vs CL_CHDO_WRITE_TOOLS

Dimension Classic SAP (SCDO) Modern ABAP Cloud (CHDO)
IDE & Tooling SAP GUI Transaction SCDO Eclipse ADT Repository Object (`CHDO`)
API Mechanism Generated FM *_WRITE_DOCUMENT Released Class CL_CHDO_WRITE_TOOLS
LUW Execution IN UPDATE TASK Managed within RAP commit phase (save_modified)
Read API FMs CHANGEDOCUMENT_READ Released Class CL_CHDO_READ_TOOLS
Clean Core Status Classic ABAP (Tier 2/3 only) Tier-1 Clean Core Released API (Contract C1)

3. The RAP Transactional Model: Where to Trigger CHDO

In the RESTful Application Programming (RAP) model, audit logging must never take place in interaction phase methods (such as validations, determinations, or actions). It must strictly occur during the RAP Save Sequence inside the save_modified method of the Behavior Pool:

Transactional Integrity: save_modified is executed only after all validations have passed and the RAP framework is committing the transaction. Any error raised here aborts the LUW cleanly.

4. Implementing Audit Logging with CL_CHDO_WRITE_TOOLS

METHOD save_modified.
  DATA(lo_writer) = cl_chdo_write_tools=>get_write_tools(
    objectclass = 'ZPR_REQ'
  ).

  " Open the change document transaction
  lo_writer->changedocument_open(
    objectclass     = 'ZPR_REQ'
    objectid        = CONV #( ls_pr-purchase_requisition_id )
    planned_or_real = 'R'
  ).

  " Pass old and new images for automated differential logging
  lo_writer->changedocument_multiple_case(
    tablename = 'ZT_PR_HEADER'
    table_new = lt_new_records
    table_old = lt_old_records
    updkz     = 'U' " Update
  ).

  " Finalize and close the audit entry
  lo_writer->changedocument_close(
    objectclass    = 'ZPR_REQ'
    objectid       = CONV #( ls_pr-purchase_requisition_id )
    date_of_change = cl_abap_context_info=>get_system_date( )
    time_of_change = cl_abap_context_info=>get_system_time( )
    username       = cl_abap_context_info=>get_user_technical_name( )
  ).
ENDMETHOD.

5. Reading Historical Audit Logs via CL_CHDO_READ_TOOLS

To display audit trails in SAP Fiori apps, use the read API instead of querying raw CDHDR or CDPOS tables:

DATA(lo_reader) = cl_chdo_read_tools=>get_read_tools( ).

lo_reader->changedocument_read_headers(
  EXPORTING
    objectclass         = 'ZPR_REQ'
    objectid            = iv_object_id
    date_of_change_from = iv_from_date
  IMPORTING
    et_cdhdr            = rt_change_headers
).

Master Enterprise RAP & Clean Core Architecture

Get the complete 400+ page guide with end-to-end architectures, testing patterns, and migration blueprints:

Unlock Complete Enterprise Suite (80% Off • €9.80) → Also available in Paperback & Kindle on Amazon ($19.99)