首先创建日志对象
slg0:
创建主对象
创建子对象
调用函数添加维护日志
*1.变量定义
*----------------------------------------------------------------------*
DATA: l_mac_bal_log TYPE bal_s_log. "定义log
DATA: l_tab_loghndl TYPE bal_t_logh.
*----------------------------------------------------------------------*
*2.赋值
*----------------------------------------------------------------------*
l_mac_bal_log-extnumber = i_log_extnumber. "外部编号
l_mac_bal_log-object = i_log_object.
l_mac_bal_log-subobject = i_log_sub_object.
l_mac_bal_log-aldate = sy-datum.
l_mac_bal_log-altime = sy-uzeit.
l_mac_bal_log-aluser = sy-uname.
l_mac_bal_log-alprog = sy-repid. "sy-repid.
*----------------------------------------------------------------------*
*2.创建日志,得到句柄
*----------------------------------------------------------------------*
i_s_log = l_mac_bal_log
e_log_handle = e_mac_handle "句柄
OTHERS = 2.
*----------------------------------------------------------------------*
*2消息类型处理
*----------------------------------------------------------------------*
l_wa_bal_msg-msgty = sy-msgty. "消息类型
l_wa_bal_msg-msgno = sy-msgno. "消息号
l_wa_bal_msg-msgid = sy-msgid. "消息类
l_wa_bal_msg-msgv1 = sy-msgv1. "消息变量
l_wa_bal_msg-msgv2 = sy-msgv2. "消息变量
l_wa_bal_msg-msgv3 = sy-msgv3. "消息变量
l_wa_bal_msg-msgv4 = sy-msgv4. "消息变量
if l_wa_bal_msg-msgty ca 'EA'. "如果返回消息有错误
l_wa_bal_msg-probclass = '1'.
elseif l_wa_bal_msg-msgty ca 'S'.
l_wa_bal_msg-probclass = '2'.
l_wa_bal_msg-probclass = '3'.
*----------------------------------------------------------------------*
*3添加日志
*----------------------------------------------------------------------*
i_log_handle = l_mac_handle
i_s_msg = l_wa_bal_msg
E_S_MSG_HANDLE =
E_MSG_WAS_LOGGED =
E_MSG_WAS_DISPLAYED
exceptions
log_not_found
msg_inconsistent = 2
log_is_full
others = 4
……如果添加多次,多次调用add函数
*----------------------------------------------------------------------*
*4保存日志
*----------------------------------------------------------------------*
APPEND i_mac_handle TO l_tab_loghndl.
i_save_all
i_t_log_handle = l_tab_loghndl "句柄内表
log_not_found = 1
numbering_error = 3
OTHERS
REFRESH l_tab_loghndl. "清空
*-----------------------------------------------------------------------
*"调用标准关闭日志函数
*-----------------------------------------------------------------------
i_log_handle = i_mac_handle "句柄
OTHERS = 2.
*&---------------------------------------------------------------------*
*&"显示日志: 最简单的显示方式
*&---------------------------------------------------------------------*
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
* EXPORTING
I_S_DISPLAY_PROFILE =
I_T_LOG_HANDLE
I_T_MSG_HANDLE
I_S_LOG_FILTER
I_S_MSG_FILTER
I_T_LOG_CONTEXT_FILTER
I_T_MSG_CONTEXT_FILTER
I_AMODAL
I_SRT_BY_TIMSTMP
* IMPORTING
E_S_EXIT_COMMAND
* EXCEPTIONS
PROFILE_INCONSISTENT
INTERNAL_ERROR
NO_DATA_AVAILABLE = 3
NO_AUTHORITY
OTHERS
IF sy-subrc <> 0.
ENDIF.
*&---------------------------------------------------------------------*
no_tree display方法:
*&---------------------------------------------------------------------*
DATA:
l_s_display_profile TYPE bal_s_prof.
* get display profile
CALL FUNCTION 'BAL_DSP_PROFILE_NO_TREE_GET'
OTHERS = 1.
" 然后再调用
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
OTHERS = 1.
*&---------------------------------------------------------------------*
弹出窗口形式::
*&---------------------------------------------------------------------*
*DATA:
* get a prepared profile
CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'
OTHERS = 1.
*"然后再调用:
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
OTHERS = 1.
可以可以直接进入slg1,然后查看日志
具体参数意思,不解释了,都懂的
大概的记录log的方法就是这样子,因为有数据库操作,必然会耗时,什么时候考虑加日志,根据业务要求和具体重要程度去判断吧
标签:sy,log,wa,mac,msg,bal,SAP,SLG0 From: https://blog.51cto.com/u_15680210/5751433