Application Log II – New FMs

By | September 8, 2011 | Application Log | 5,343 | 2

We’ll see how we can generate the Application Log using the New Set of Function Modules BAL* which are available since Release 4.6. We have already seen how to Generate Application Log using the old set of the FMs APPL_LOG_*. Check SAP Help on availability of new FMs BAL*.

Check my older post Generate Application Log on basic configuration for generating application log.

We’ll use these FMs to generate the application log:

  • BAL_LOG_CREATE – Log: Create with Header Data
  • BAL_LOG_MSG_ADD – Add Log Messages
  • BAL_DB_SAVE – Save Log to Database

Code Lines

Code Lines to generate the Application Log using the New FMs.

PROGRAM ztest_np_temp.

* Local Data
DATAls_log          TYPE bal_s_log.
DATAlv_log_handle   TYPE balloghndl.
DATAlt_log_handle   TYPE bal_t_logh,
      lt_log_num      TYPE bal_t_lgnm.
DATAlt_msg          TYPE STANDARD TABLE OF bal_s_msg.
DATAls_msg          LIKE LINE OF lt_msg.

FIELD-SYMBOLS<lfs_log_num> LIKE LINE OF lt_log_num.


* Create the Log
  ls_log-object    'APPLOG'.
  ls_log-subobject 'SUBAPP'.
  ls_log-aldate    sy-datum.
  ls_log-altime    sy-uzeit.
  ls_log-aluser    sy-uname.

      i_s_log                 ls_log
      e_log_handle            lv_log_handle
      log_header_inconsistent 1
      OTHERS                  2.
  IF sy-subrc <> 0.
    RAISE EXCEPTION TYPE zcx_idoc_app_log_error.

    lw_callback_param  TYPE bal_s_parm.

    <lw_param>          TYPE bal_s_par.

* Fill the Application Log messages.
*   Here we can append our own messages as per our application
*   behaviour
* ------- Message 1 ---------
* Information message will generate the Green Light
  ls_msg-msgty 'I'.
  ls_msg-msgid '00'.
  ls_msg-msgno '398'.
  ls_msg-msgv1 'Information - Testing 1234'.
  APPEND ls_msg TO lt_msg.
  CLEAR  ls_msg.

* ------- Message 2 ---------
* Warning message will generate the Yellow light
  ls_msg-msgty 'W'.
  ls_msg-msgid '00'.
  ls_msg-msgno '398'.
  ls_msg-msgv1 'Warning Testing 1234'.
  APPEND ls_msg TO lt_msg.
  CLEAR  ls_msg.

* ------- Message 3 ---------
* Error message will generate the Red Light
  ls_msg-msgty 'E'.
  ls_msg-msgid '00'.
  ls_msg-msgno '398'.
  ls_msg-msgv1 'Error Testing 1234'.
  APPEND ls_msg TO lt_msg.
  CLEAR  ls_msg.

* ------- Message 4 ---------
* user interaction
  DATAlv_order TYPE char10 VALUE '100012345'.
  ls_msg-msgty 'I'.
  ls_msg-msgid '00'.
  ls_msg-msgno '001'.
  ls_msg-msgv1 'Double Click to navigate to Order'.
  ls_msg-msgv2 lv_order.
  ls_msg-msgv1_src 'ZTEST_NP'.
* for callback
  ls_msg-params-callback-userexitp 'ZTEST_NP_TEMP'.
  ls_msg-params-callback-userexitf 'F_CALLBACK_AT_LINE_SELECTION'.
  ls_msg-params-callback-USEREXITT space.             " External Perform
  APPEND INITIAL LINE TO ls_msg-params-t_par ASSIGNING <lw_param>.
  <lw_param>-parname  'P_VBELN'.
  <lw_param>-parvalue lv_order.
  APPEND ls_msg TO lt_msg.
  CLEAR  ls_msg.

* ------- Message 5 ---------
* Additional Context for messages
  ls_msg-msgty 'W'.
  ls_msg-msgid '00'.
  ls_msg-msgno '398'.
  ls_msg-msgv1 'Warning Testing 1234'.
* context
  DATAl_s_context          TYPE bal_s_ex03.
  l_s_context-carrid  'AA'.
  l_s_context-connid  'ABC'.
  l_s_context-fldate  sy-datum + 20.
  l_s_context-invoice lv_order.
  ls_msg-context-tabname 'BAL_S_EX03'.
  ls_msg-context-value   l_s_context.
  APPEND ls_msg TO lt_msg.
  CLEAR  ls_msg.

  LOOP AT lt_msg INTO ls_msg.

        i_log_handle              lv_log_handle
        i_s_msg                   ls_msg
*      E_S_MSG_HANDLE            = E_S_MSG_HANDLE
       log_not_found             1
       msg_inconsistent          2
       log_is_full               3
       OTHERS                    4
    IF sy-subrc <> 0.
      WRITE'Error while adding message to Log'.

* Save Logs to DB
  INSERT lv_log_handle INTO lt_log_handle INDEX 1.
      i_client         sy-mandt
      i_save_all       ' '
      i_t_log_handle   lt_log_handle
      e_new_lognumbers lt_log_num
      log_not_found    1
      save_not_allowed 2
      numbering_error  3
      OTHERS           4.
  IF sy-subrc <> 0.
    WRITE'Error while Saving Log to DB'.
    WRITE'Log Generated'.

FORM f_callback_at_line_selection TABLES
                  lt_param   TYPE bal_t_par.                "#EC CALLED

  DATAlwa_param LIKE LINE OF lt_param.
  DATAlv_vbeln TYPE vbak-vbeln.

  READ TABLE lt_param INTO lwa_param WITH KEY parname 'P_VBELN'.
  IF sy-subrc EQ 0.
    lv_vbeln lwa_param-parvalue.
    MESSAGE 'Error reading data from Parameters' TYPE 'S'.



The demo program will generate this output.

Explanation of Advance Features

This report generates the application log with 5 messages. First three message are standard messages – Information message with green light, Warning message with yellow light and error message with red light.

Message 4 has additional details attached to it. When we press the details icon, system will call our callback perform. While creating the message, we have passed additional information in the deep structured field PARAMS of the message structure.Fields of PARAMS-CALLBACK:

  • USEREXITP – Program name in which perform exist
  • USEREXITF – Subroutine or FM name
  • USEREXITT – User Exit type. SPACE calls the External Perform. F calls the FM. Currently OO is not supported

Field PARAMS-T_PAR is used to pass the parameters from the message to the callback subroutine or FM.For this example, I have used the user exit type callback. When we click on details, it calls our callback subroutine. Inside the subroutine, we extract the data from the T_PAR and use it to call VA03.

Message 5 also has additional details attached. These additional details is different that the message 4. Message 4 has user interaction type of additional detail whereas this message has additional context. We can specify a structure name and 255 character value to display it in technical details of the message.

Have you used Application Log, yet?

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{268 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 268 articles.

Load comments


  • [...] The FMs used here to generate Application Log are replaced by new set of FMs. Check out the New FMs to generate Application Log. [...]

  • Allage

    Excellent post man, you’re a life saver.

    Thank you.

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.