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.
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):
SCDO and generated write function modules are obsolete and strictly forbidden by ATC (Rule: ABAP_CLEAN_CORE_DEVELOPMENT).IN UPDATE TASK and COMMIT WORK are prohibited inside modern ABAP Cloud code.CL_CHDO_WRITE_TOOLS and CL_CHDO_READ_TOOLS for ABAP Cloud.| 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) |
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:
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.
CL_CHDO_WRITE_TOOLSMETHOD 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.
CL_CHDO_READ_TOOLSTo 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
).
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)