Skip to Content
0
Former Member
Jan 11, 2012 at 03:53 PM

Application log & Assertion Faild problem

3404 Views

Dear SAP community,

does SAP support writting log messages not into database but into log file?

My Problem:

I am trying to check if the bal messages would be saved in database even if an ASSERTION_FAILED occures. As you see in the report below, the function 'BAL_DB_SAVE' doesn't really save the logs directly into the database table but it waits until a COMMIT WORK is executred which means if any ASSERTION-FAILED occurs in between no BAL will be saved and I'll loose the traces of my program flow which I've written in that BAL handler.

Thank you in advance.

Bahjat

Here is a short report demonstrating my problem.

REPORT  Z_BAL_AFTER_ASSERT_TEST.

PARAMETERS: pv_x  type abap_bool as CHECKBOX.


data:
      lv_bool type abap_bool,
      lt_but  type table of but000,
      ls_but  type but000.


DATA: lv_log_handle        TYPE                   balloghndl,
      ls_log               TYPE                   bal_s_log,
      ls_msg               TYPE                   bal_s_msg,
      lv_msgno             TYPE                   symsgno,
      lt_log_handle        TYPE                   bal_t_logh.
* -------------------------------------------------------------------------------------


START-OF-SELECTION.


* Start BAL Logging
* -----------------------------------------------------------------
CONCATENATE sy-datum sy-uzeit INTO ls_log-extnumber SEPARATED BY space.  "Unique number for the current log
ls_log-object    = 'ZSALBAH_BAL'. "See table BALOBJ for possible entries (new entries via SLG0) CRM_DOCUMENT
ls_log-subobject = 'BAL_TEST'.      "See table BALSUB for possible entries (new entries via SLG0) SINGLE

* Initialize BAL Logging (see TX SLG1)
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
  i_s_log      = ls_log
IMPORTING
  e_log_handle = lv_log_handle
EXCEPTIONS
  OTHERS       = 1.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid
  TYPE sy-msgty
  NUMBER sy-msgno
  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  EXIT.
ENDIF.
* -----------------------------------------------------------------

ls_msg-msgid     = 'ZCRM'.
ls_msg-msgno     = '000'.
ls_msg-msgty     = 'S'.
ls_msg-probclass = '3'.

CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
  i_log_handle = lv_log_handle
  i_s_msg      = ls_msg
EXCEPTIONS
  OTHERS       = 1.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid
  TYPE sy-msgty
  NUMBER sy-msgno
  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*   --------------------------------------------------------------------




* Save log
* -----------------------------------------------------------------
APPEND lv_log_handle TO lt_log_handle.
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
  i_in_update_task = ' '
  i_save_all       = ' '
  i_t_log_handle   = lt_log_handle
EXCEPTIONS
  log_not_found    = 1
  save_not_allowed = 2
  numbering_error  = 3
  OTHERS           = 4.

IF sy-subrc <> 0.
  MESSAGE ID sy-msgid
  TYPE sy-msgty
  NUMBER sy-msgno
  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* -----------------------------------------------------------------


IF pv_x = abap_true.  
  ASSERT 1 = 2.
endif.

COMMIT WORK.


write lv_bool.