Copyright 2022 - BV TallVision IT

Error logging is something that needs to be done throughout the system for every process. Make sure you know about the Business Application Log (BAL).

The BAL is a powerful nearly-end user tool that could be used to place error messages on processes that cannot report the errors immediately, e.g. because the error is in a background process (batch job or Idoc processing). You can use the BAL for your own applications as well - here's how:

 

First of all have a good look at the Business Application Log or BAL, via transaction SLG1 - "Evaluate application log", the logs that have been produced to date can be displayed. Have a browse around and see if you can work out the following:

  • The reported messages: where do they originate from ? It should always be possible to pinpoint the origin of a message.
  • What happened ? Can you find the list of messages ?
  • What problem class are the messages you are seeing ?

The BAL allows logging of all kinds of problems or even simple notifications of completion. Normally the daily checks performed by system maintenance should include the BAL report for the serious errors.

Plans to make this work for your own application ?

Here's the main ingredients:

  1. Create a BAL object and subobject, which can be done in transaction SGL0 - "Application Log: Object Maintenance".
  2. From your ABAP program, compose log content via class CL_ISHMED_BAL
  3. Alternatively, check out (instantiate) interface IF_RECA_MESSAGE_LIST. This interface allows access to an even greated variety of methods, e.g. to check whether there are messages on the log (IS_EMPTY) or check whether errors are logged (HAS_MESSAGES_OF_MSGTY). It has no method for display. An example:
    DATA: go_log TYPE REF TO if_reca_message_list.
    
    go_log = cf_reca_message_list=>create(  
      id_object    = 'ZSLG01_OBJ'
      id_subobject = 'ZSLG01_SUBOBJ' ).
  4. If you're not too happy with the class just try again. Alternatively from your ABAP program, build up the log contents with the following function modules:
    • APPL_LOG_INIT Application Log: (Partially) Initialize local memory
    • APPL_LOG_WRITE_HEADER Application log: Enter log header data
    • APPL_LOG_WRITE_DB Application log: Copy local memory data into DB tables
  5. List the function modules from the following function groups: SLG0, SLG1, SLG2, SLG3, SLG9.

Note that the above set of function modules have been flagged "Old" on the function group descriptions. The functionality was available as described above in a 4.6 system. On newer systems, look for function modules starting with BAL_* such as BAL_LOG_CREATE, BAL_LOG_MSG_ADD and BAL_DB_SAVE.

More about the application log

The business application log can be archived via standard archiving objects. Entries can also be deleted via transaction SLG2 - "Application Log: Delete logs".

Business application log data is held on tables BALHDR, BALM and BALMP. More information on the tables can be found on "Tables and Such".

Example composing an in-report application log

This following example shows how the BAL_LOG_*function modules can be used to create logging in your application and process the output at the end of your report. Use this to gather information about problems during the program run and list them at the end.

DATA: lw_ballog TYPE bal_s_log,
      lv_balloghndl TYPE balloghndl,
      lw_statistics TYPE bal_s_scnt,
      lw_message_handle TYPE balmsghndl,
      lw_message TYPE bal_s_msg,
      lv_messagetext TYPE string.

CALL FUNCTION 'BAL_LOG_CREATE'
  EXPORTING
    i_s_log      = lw_ballog
  IMPORTING
    e_log_handle = lv_balloghndl
  EXCEPTIONS
    OTHERS       = 0.
* Add some messages
CALL FUNCTION 'BAL_LOG_MSG_ADD_FREE_TEXT'
  EXPORTING
    i_log_handle = lv_balloghndl
    i_msgty      = 'E' "Error
    i_text       = 'This went wrong here !'.

CALL FUNCTION 'BAL_LOG_MSG_ADD_FREE_TEXT'
  EXPORTING
    i_log_handle = lv_balloghndl
    i_msgty      = 'E' "Error
    i_text       = 'This went wrong as well, over there'.

* Now show the log - first determine how many messages there are
CALL FUNCTION 'BAL_LOG_HDR_READ'
  EXPORTING
    i_log_handle = lv_balloghndl
  IMPORTING
    e_statistics = lw_statistics
  EXCEPTIONS
    OTHERS       = 0.

* Pick up all messages and output them:
DO lw_statistics-msg_cnt_al TIMES.

  lw_message_handle-log_handle = lv_balloghndl.
  lw_message_handle-msgnumber = sy-index.
  CALL FUNCTION 'BAL_LOG_MSG_READ'
    EXPORTING
      i_s_msg_handle = lw_message_handle
    IMPORTING
      e_s_msg        = lw_message
    EXCEPTIONS
      OTHERS         = 0.
  MESSAGE ID lw_message-msgid TYPE lw_message-msgty 
    NUMBER lw_message-msgno
    INTO lv_messagetext
    WITH lw_message-msgv1 lw_message-msgv2 
         lw_message-msgv3 lw_message-msgv4.

  WRITE: / lw_message-msgty, lv_messagetext.

ENDDO.