‎2005 Dec 14 10:26 AM
I am looking for a way to put errors from custom program ( which would run as job) to system log, which should be visible via SM21. Can any of you help me with a function module with which I can achieve it ?
‎2005 Dec 14 10:35 AM
Hi Indrade,
Is it your first post in SDN ? Welcome!
for your problem try the following procedure:
1. Refresh memory
CALL FUNCTION 'BAL_GLB_MEMORY_REFRESH'
EXPORTING
* I_AUTHORIZATION =
i_refresh_all = 'X'
* I_T_LOGS_TO_BE_REFRESHED =
EXCEPTIONS
not_authorized = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
2. Create a Log
* define some header data of this log
l_s_log-extnumber = pu_ext_number.
l_s_log-aluser = sy-uname.
l_s_log-alprog = sy-repid.
l_s_log-object = pu_object.
l_s_log-subobject = pu_subobject.
* create a log
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = l_s_log
IMPORTING
e_log_handle = pc_log_handle
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
3. Add a message to the Log
DATA:
l_s_msg TYPE bal_s_msg,
l_log_handle TYPE balloghndl.
* define data of message for Application Log
l_s_msg-msgty = pu_msgty.
l_s_msg-msgid = pu_msgid.
l_s_msg-msgno = pu_msgno.
l_s_msg-msgv1 = pu_msgv1.
l_s_msg-msgv2 = pu_msgv2.
l_s_msg-msgv3 = pu_msgv3.
l_s_msg-msgv4 = pu_msgv4.
l_s_msg-probclass = pu_probclass.
l_s_msg-context-value = pu_context.
GET TIME STAMP FIELD l_s_msg-time_stmp.
* add this message to log file
* (I_LOG_HANDLE is not specified, we want to add to the default log.
* If it does not exist we do not care =>EXCEPTIONS log_not_found = 0)
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = l_log_handle
i_s_msg = l_s_msg
EXCEPTIONS
log_not_found = 0
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.
4. Save Log
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_t_log_handle = p_t_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.
I hope it will helps.
Please remember to reward points if the answer is useful, and to close the post when your problem is solved
Regards, Manuel
‎2005 Dec 14 10:35 AM
Hi Indrade,
Is it your first post in SDN ? Welcome!
for your problem try the following procedure:
1. Refresh memory
CALL FUNCTION 'BAL_GLB_MEMORY_REFRESH'
EXPORTING
* I_AUTHORIZATION =
i_refresh_all = 'X'
* I_T_LOGS_TO_BE_REFRESHED =
EXCEPTIONS
not_authorized = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
2. Create a Log
* define some header data of this log
l_s_log-extnumber = pu_ext_number.
l_s_log-aluser = sy-uname.
l_s_log-alprog = sy-repid.
l_s_log-object = pu_object.
l_s_log-subobject = pu_subobject.
* create a log
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = l_s_log
IMPORTING
e_log_handle = pc_log_handle
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
3. Add a message to the Log
DATA:
l_s_msg TYPE bal_s_msg,
l_log_handle TYPE balloghndl.
* define data of message for Application Log
l_s_msg-msgty = pu_msgty.
l_s_msg-msgid = pu_msgid.
l_s_msg-msgno = pu_msgno.
l_s_msg-msgv1 = pu_msgv1.
l_s_msg-msgv2 = pu_msgv2.
l_s_msg-msgv3 = pu_msgv3.
l_s_msg-msgv4 = pu_msgv4.
l_s_msg-probclass = pu_probclass.
l_s_msg-context-value = pu_context.
GET TIME STAMP FIELD l_s_msg-time_stmp.
* add this message to log file
* (I_LOG_HANDLE is not specified, we want to add to the default log.
* If it does not exist we do not care =>EXCEPTIONS log_not_found = 0)
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = l_log_handle
i_s_msg = l_s_msg
EXCEPTIONS
log_not_found = 0
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.
4. Save Log
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_t_log_handle = p_t_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.
I hope it will helps.
Please remember to reward points if the answer is useful, and to close the post when your problem is solved
Regards, Manuel
‎2005 Dec 14 10:40 AM
‎2005 Dec 20 9:31 AM
We have found the function module RSLG_WRITE_SYSLOG_ENTRY with which we can write SYSLOG entries. Thanks for your help