Monday, August 29, 2005

Using the SAP logging features

Very quick instructions:

1) create a log object and subobject in SLG0
2) initialize the log object/subobject (g_loghandle is a global variable)


DATA: l_loghead TYPE bal_s_log.

IF w_loghandle IS INITIAL.
l_loghead-object = 'ZMYOBJ'.
l_loghead-subobject = 'MYSUBOBJ'.
l_loghead-aldate_del = sy-datum + 90. "expires in 90 days

CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = l_loghead
IMPORTING
e_log_handle = g_loghandle
EXCEPTIONS
OTHERS = 1.
ENDIF.


3) add the messages to the log


DATA: ls_logmsg TYPE bal_s_msg.

ls_logmsg-msgty = msg_type.
ls_logmsg-msgid = msg_id.
ls_logmsg-msgno = msg_number.
ls_logmsg-msgv1 = msg_v1.
ls_logmsg-msgv2 = msg_v2.
ls_logmsg-msgv3 = msg_v3.
ls_logmsg-msgv4 = msg_v4.


CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = g_loghandle
i_s_msg = ls_logmsg
EXCEPTIONS
OTHERS = 1.



4) save the log

DATA: lt_log_handle TYPE bal_t_logh,
ls_log_handle LIKE LINE OF lt_log_handle.

ls_log_handle = w_loghandle.
APPEND ls_log_handle TO lt_log_handle.

CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_t_log_handle = lt_log_handle
EXCEPTIONS
OTHERS = 1.

COMMIT WORK.


5) see the results with SLG1

Labels:

0 Comments:

Post a Comment

<< Home