Skip to content

Logging ​

Logging is critical for business processes. In ABAP systems, the standard tool is the Business Application Log (BAL), available on-premise and in ABAP Cloud environments alike. With abap2UI5, use BAL like you would in classic ABAP — and to show a log, hand it straight to client->message_box_display( ).

That method takes any message source, not just a string: a BAL table, a cl_bali_log, a bapiret2 table, sy, an exception. Anything that is not a plain string goes through the framework's message mapper, which flattens it into the lines the box shows — so every example below is the same one call with a different argument. See Message for the other sources.

BAL Tables ​

In classic ABAP, use the BAL function modules and hand the BAL table over as it is. In the bal_t_msgr structure, msgno is the message number within the message class (msgid), while msgnumber is the message's sequence number within the log:

abap
METHOD z2ui5_if_app~main.

  DATA(lt_bal) = VALUE bal_t_msgr(
    ( msgid = `Z001` msgno = `001` msgty = `S` time_stmp = `21354` msgnumber = `01` )
    ( msgid = `Z001` msgno = `001` msgty = `S` time_stmp = `21354` msgnumber = `02` ) ).

  client->message_box_display( lt_bal ).

ENDMETHOD.

ABAP Cloud ​

In ABAP Cloud, hand the logging object over the same way:

abap
METHOD z2ui5_if_app~main.

  DATA(lo_log) = cl_bali_log=>create( ).
  DATA(lo_msg) = cl_bali_message_setter=>create(
    severity   = if_bali_constants=>c_severity_status
    id         = `DEMO_LOG`
    number     = `002`
    variable_1 = `username` ).
  lo_log->add_item( lo_msg ).

  DATA(lo_bapi) = cl_bali_message_setter=>create_from_bapiret2(
    VALUE #(
      type       = `E`
      id         = `DEMO_LOG`
      number     = `002`
      message_v1 = `Dummy` ) ).
  lo_log->add_item( lo_bapi ).

  client->message_box_display( lo_log ).

ENDMETHOD.

abap-logger ​

You can also use the open-source project abap-logger. It simplifies work with BAL logs and pairs well with abap2UI5:

abap
METHOD z2ui5_if_app~main.

  DATA(lo_log) = zcl_logger_factory=>create_log( desc = `ABAP Logger` ).
  lo_log->e( `This is an error...` ).
  lo_log->s( `This is a success message...` ).

  client->message_box_display( lo_log ).

ENDMETHOD.

Whichever source it is, the box shows the messages by severity, and the most severe one decides its type. A log carries more than a message class does: a timestamp per entry and the sequence number. A box cannot show those; the message dialog of the popups add-on below can.

Something richer than a message box

A message box is a list of lines. For a sortable table of the log with its severities, timestamps and long texts, you have two options. Build the view yourself from the same data, which is an internal table like any other (see Tables). Or take the ready-made message dialog from the popups add-on.

Working Samples ​

Complete apps from the sample catalog that use what this page describes. Each is a single class in abap2UI5/samples unless its row names another of the three sample repositories — pull that repository with abapGit and start the class with ?app_start=<class>.

SampleClass
MessageBox for Any DataZ2UI5_CL_SMP_APP_502