SAP的应用日志(Application Log)

SAP的应用日志(Application Log)是用于创建,保存和分析系统消息的工具.
相关TCODE:
    SLG0: Creation of Object and Sub object
    SLG1: Display Application Logs
相关创建应用日志函数
    BAL_LOG_CREATE --> Create log with header data
    BAL_LOG_MSG_ADD --> Put message in log
    BAL_DB_SAVE --> Save logs in the database
创建应用日志的处理步骤:
    1: 使用TCODE:SLG0创建对象和子对象.
    2: 创建对象,对象名以Z或Y开头.
    3:?创建对象后,你将创建子对象.
    4: 如果相应的子对象不存在,则创建子对象.
    5: 这样对象和子对象就可以在应用日志中使用了.
    6: 使用下面三个函数创建和保存应用日志
    7: 使用'BAL_LOG_CREATE'?创建日志句柄(log handle)
    8: 使用'BAL_LOG_MSG_ADD' 添加消息,
    9: 使用'BAL_DB_SAVE' 保存日志
如何查看应用日志?
    1.?输入TCODE: SLG1.系统将出现分析应用日志的屏幕.
    2. 输入对象,子对象和外部标示符.
    3. 输入时间.
    4. 规定日志的原因
    5. 选择日志类别和创建日志.
    6. 执行.
    系统将显示结果.
SAP的代码实例:
    SBAL_DEMO_06
==============================
form get_message tables t_msg type bapiret2_t using i_grid i_popup .
data: l_log_handle type balloghndl,
            it_applogs   type bal_t_msg,
            l_applogs    type bal_s_msg,
*      l_exlogs     type ZSOE_EXLOGS,
            l_s_fcat     type bal_s_fcat,
            l_s_log      type bal_s_log,
            l_s_msg      type bal_s_msg.
* convert bapiret2 message to bal_s_msg
loop at t_msg.
clear l_applogs.
    l_applogs-msgty  =  t_msg-type.
    l_applogs-msgid  =  t_msg-id.
    l_applogs-msgno  =  t_msg-number.
    l_applogs-msgv1  =  t_msg-message_v1.
    l_applogs-msgv2  =  t_msg-message_v2.
    l_applogs-msgv3  =  t_msg-message_v3.
    l_applogs-msgv4  =  t_msg-message_v4.
append l_applogs to it_applogs.
endloop.
data: l_exlogs_tabname like dfies-tabname.
data: lt_fieldtab like dfies occurs 0 with header line.
data:
    l_s_display_profile type bal_s_prof.
field-symbols: <fd1> type any.  "Structure field
* create an initial log file
  l_s_log-extnumber  = 'Application Log'(001).
call function 'BAL_LOG_CREATE'
exporting
      i_s_log      = l_s_log
importing
      e_log_handle = l_log_handle
exceptions
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.
* Message add
loop at it_applogs into l_applogs.
clear: l_s_msg. "l_exlogs.
move-corresponding l_applogs to : l_s_msg. " l_exlogs.
call function 'BAL_LOG_MSG_ADD'
exporting
        i_log_handle = l_log_handle
        i_s_msg      = l_s_msg
exceptions
others       = 1.
endloop.
if i_popup = 'X'.
call function 'BAL_DSP_PROFILE_POPUP_GET'
importing
        e_s_display_profile = l_s_display_profile
exceptions
others              = 1.
else.
call function 'BAL_DSP_PROFILE_NO_TREE_GET'
importing
        e_s_display_profile = l_s_display_profile
exceptions
others              = 1.
endif.
loop at l_s_display_profile-mess_fcat into l_s_fcat .
if l_s_fcat-ref_field = 'MSGNUMBER'.
      l_s_fcat-col_pos = 1.
      l_s_fcat-no_out = ''.
else.
      l_s_fcat-col_pos = 99.
endif.
modify l_s_display_profile-mess_fcat from l_s_fcat
transporting col_pos no_out.
endloop.
  l_s_display_profile-use_grid = i_grid.
  l_s_display_profile-cwidth_opt = 'X'.
call function 'BAL_DSP_LOG_DISPLAY'
exporting
      i_s_display_profile = l_s_display_profile
exceptions
others              = 1.
** refresh message
call function 'BAL_LOG_REFRESH'
exporting
      i_log_handle  = l_log_handle
exceptions
      log_not_found = 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.
endform.                    "GET_MESSAGE

你可能感兴趣的:(application)