This post provides methods or macro for logging SLG1 message.
It is shortcuts for calling standard methods :
– BAL_LOG_CREATE
– BAL_LOG_MSG_ADD
– BAL_DB_SAVE
With Macro
Global data to be used in macro (to be set in the TOP include) :
DATA : gv_log_handle TYPE balloghndl,
gs_message TYPE bal_s_msg.
Macros (to be also set in TOP include to have a global scope in program) :
*----------------------------------------------------------------------*
* Init SLG1 Log *
*----------------------------------------------------------------------*
DEFINE slg1_init.
DATA(gs_log_infos) = VALUE bal_s_log( object = &1
subobject = &2
extnumber = &3
aluser = sy-uname
alprog = sy-repid ).
CLEAR gv_log_handle.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = gs_log_infos
IMPORTING
e_log_handle = gv_log_handle
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2.
END-OF-DEFINITION.
*----------------------------------------------------------------------*
* Add message in SLG1 Log *
*----------------------------------------------------------------------*
DEFINE slg1_add_message.
gs_message = VALUE #( msgty = &1
msgid = c_msgid_default " | Can be transformed in
msgno = c_msgno_default " | parameter if needed
msgv1 = &2
msgv2 = &3
msgv3 = &4 ).
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = gv_log_handle
i_s_msg = gs_message
EXCEPTIONS
log_not_found = 1
msg_inconsistent = 2
log_is_full = 3
OTHERS = 4.
END-OF-DEFINITION.
*----------------------------------------------------------------------*
* Save all messages logged *
*----------------------------------------------------------------------*
DEFINE slg1_save.
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_t_log_handle = VALUE bal_t_logh( ( gv_log_handle ) )
EXCEPTIONS
log_not_found = 1
save_not_allowed = 2
numbering_error = 3
OTHERS = 4.
END-OF-DEFINITION.
Example of use :
slg1_init 'ZOBJECT'
'ZSUB_OBJECT'
space.
slg1_add_message 'S' TEXT-001 space space.
slg1_add_message 'E' TEXT-003 TEXT-006 space.
slg1_save.
About the author