We can create the log of customized message in the T.code SLG1 by creating your own Function module.
Function Module: Create a Custom FM consisting the parameters as follows :-
Import parameters
- Object name
- Subobject
- Customized message (itab)
- External ID
Export parameters
- Application log number
Note: Please refer the screenshots for further details of import & export parameters.
Source Code:
DATA:
ls_header TYPE bal_s_log,
lv_log_handle TYPE balloghndl,
lt_log_handle TYPE bal_t_logh,
lv_log_number TYPE balognr,
lt_msg TYPE balmi_tab,
ls_msg TYPE balmi,
lt_lognum TYPE TABLE OF balnri,
ls_lognum TYPE balnri,
lt_log_nums TYPE BAL_T_LGNM,
ls_log LIKE LINE OF lt_log_nums.
FIELD-SYMBOLS:
<fs_mesg> TYPE bal_s_msg.
* Header information for the log
ls_header-object = iv_obj.
ls_header-subobject = iv_subobj.
ls_header-extnumber = iv_extnumber.
ls_header-aldate = sy-datum.
ls_header-altime = sy-uzeit.
ls_header-aluser = sy-uname.
ls_header-aldate_del = sy-datum + 30.
ls_header-del_before = 'X'.
* create a log
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = ls_header
IMPORTING
e_log_handle = lv_log_handle
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
sy-subrc = 1.
ENDIF.
LOOP AT it_mesg ASSIGNING <fs_mesg>.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = lv_log_handle
i_s_msg = <fs_mesg>
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
ENDIF.
ENDLOOP.
* save the log
APPEND lv_log_handle TO lt_log_handle.
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_save_all = 'X'
i_t_log_handle = lt_log_handle
IMPORTING
E_NEW_LOGNUMBERS = lt_log_nums
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
ENDIF.
LOOP AT lt_log_nums INTO ls_log.
appl_log = ls_log-lognumber.
EXIT.
ENDLOOP.
COMMIT WORK.
ENDFUNCTION.
- After Executing the above FM, you can find the log of custom message in SLG1 as provided in the screenshot