📜 Clean Core Cheat Sheet

SAP Clean Core Application Log (cl_bali_log) Guide

A definitive guide to enterprise diagnostics, exception logging, and audit trails in ABAP Cloud without violating RAP transactional integrity.

1. The Clean Core Logging Paradigm Shift

In legacy ECC and early S/4HANA systems, developers relied on function module suites such as BAL_LOG_CREATE, BAL_LOG_MSG_ADD, and BAL_DB_SAVE. In ABAP Cloud (Language Version: ABAP for Cloud Development), all classic BAL_* function modules are strictly prohibited (ATC error: Use of non-released API).

Furthermore, calling COMMIT WORK to flush application logs during RAP execution (e.g. inside validations, determinations, or actions) triggers catastrophic runtime dumps (DBSQL_DUPLICATE_KEY or BEHAVIOR_ILLEGAL_STATEMENT). SAP introduced the Business Application Log Interface (BALI) rooted in the released class cl_bali_log to solve this architectural dilemma.

2. Core Components of the BALI Framework

Class / Interface Role in Architecture Clean Core Status
cl_bali_log Primary container representing a single application log instance. Released (Contract C1)
cl_bali_header_setter Configures Log Object, Sub-Object, External ID, and Expiry Date. Released (Contract C1)
cl_bali_message_setter Adds structured T100 messages (MsgID, MsgNo, MsgV1..V4). Released (Contract C1)
cl_bali_free_text_setter Adds unstructured diagnostic string messages. Released (Contract C1)
cl_bali_exception_setter Captures full CX_ROOT exception objects with callstacks. Released (Contract C1)
cl_bali_log_db Database persistence engine. Synchronizes with RAP LUW phases. Released (Contract C1)

3. The RAP LUW Dilemma: Saving Logs Safely

In SAP RAP, database modifications are segregated into strict phases:

METHOD save_modified.
  DATA(lo_logger) = cl_bali_log=>create_with_header(
    cl_bali_header_setter=>create(
      iv_object    = 'Z_CLEAN_CORE'
      iv_subobject = 'PROCUREMENT' ) ).

  lo_logger->add_item(
    cl_bali_free_text_setter=>create(
      iv_severity_category = if_bali_constants=>c_severity_information
      iv_text              = 'Purchase Order committed successfully.' ) ).

  // Safe inside save_modified - no explicit COMMIT WORK needed!
  cl_bali_log_db=>get_instance( )->save_log( io_log = lo_logger ).
ENDMETHOD.

4. Exception Callstack Capture

One of BALI's biggest advantages over legacy BAL_LOG_* is direct exception integration:

TRY.
    // Risky BTP HTTP Destination Call
    lo_http_client->execute( ).
  CATCH cx_web_http_client_error INTO DATA(lx_http).
    DATA(lo_exc_item) = cl_bali_exception_setter=>create(
      iv_severity_category = if_bali_constants=>c_severity_error
      ix_exception         = lx_http ).
    lo_log->add_item( lo_exc_item ).
    cl_bali_log_db=>get_instance( )->save_log( io_log = lo_log ).
ENDTRY.

5. Consuming Logs in SAP Fiori (App F1487)

Logs created via cl_bali_log are instantly visible in the standard SAP Fiori App Application Logs (F1487 / F1487A) without requiring any custom UI code. Users can search by Object, Sub-Object, External ID, or Creation User, and view detailed exception drill-downs natively.

Interactive BALI Logging Code Generator

Generate reusable ABAP Cloud BALI helper classes, RAP save sequence adapters, and CDS query views with our free interactive architect.

📜 Launch BALI Logging Architect