首页 > 其他分享 >SAP ABAP Application Log 的使用方法

SAP ABAP Application Log 的使用方法

时间:2023-01-16 10:08:59浏览次数:52  
标签:sy Log balmsg Application ABAP str message type log

​​SAP ABAP Application Log 的使用方法​​


SAP ABAP Application Log 的使用场景:

(1) 当你想记录应用程序的执行进度,以便以后在需要时重建它;
(2) 当开发人员不确定/无法调试代码(前台/后台)并且想深入了解错误原因时,可以通过检查应用程序日志来确定问题所在的确切位置。

使用事物码 SLG0 创建一个对象,该对象用于识别开发人员在 ABAP 代码里使用的 Application log.

这里创建一个名叫 ZHR_ENC 的应用程序日志对象。

SAP ABAP Application Log 的使用方法_应用程序

再创建一个子对象 ZHRENC_SUB。

这里的场景是,为 COUNTRY 管理创建一个应用程序日志。Country 可以包含不同的 State,这些 State 的执行情况,通过子对象 ZHRENC_SUB 来记录。

SAP ABAP Application Log 的使用方法_日志记录_02

测试代码:

type-pools: abap.

data: l_log_handle type balloghndl,
l_timestamp type tzntstmps,
l_timezone type timezone value ‘UTC’,
l_str_log type bal_s_log,
l_str_balmsg type bal_s_msg,
l_str_message type bapiret2,
l_msg_logged type boolean,
l_tab_messages type bapiret2_t.

*-Building messages
*–Use your own message which you want to Display in the log
do 1 times.
call function ‘BALW_BAPIRETURN_GET2’
exporting
type = ‘E’
cl = ‘BPFS’
number = ‘006’
importing
return = l_str_message.
append l_str_message to l_tab_messages.
clear l_str_message.
enddo.

*-Logging messages
convert date sy–datum time sy–uzeit
into time stamp l_timestamp time zone l_timezone.

l_str_log–extnumber = l_timestamp.
condense l_str_log–extnumber.
l_str_log–object = ‘ZHR_ENC’.
l_str_log–subobject = ‘ZHRENC_SUB’.
l_str_log–aldate_del = sy–datum + 5.

call function ‘BAL_LOG_CREATE’
exporting
i_s_log = l_str_log
importing
e_log_handle = l_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 into l_str_message–message.
write: ‘Type’,sy–msgty, ‘Message’,l_str_message–message.
else.
loop at l_tab_messages into l_str_message.
move: l_str_message–type to l_str_balmsg–msgty,
l_str_message–id to l_str_balmsg–msgid,
l_str_message–number to l_str_balmsg–msgno,
l_str_message–message_v1 to l_str_balmsg–msgv1,
l_str_message–message_v2 to l_str_balmsg–msgv2,
l_str_message–message_v3 to l_str_balmsg–msgv3,
l_str_message–message_v4 to l_str_balmsg–msgv4.

call function ‘BAL_LOG_MSG_ADD’
exporting
i_log_handle = l_log_handle
i_s_msg = l_str_balmsg
importing
e_msg_was_logged = l_msg_logged
exceptions
log_not_found = 1
msg_inconsistent = 2
log_is_full = 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 into l_str_message–message.
write: ‘Type’,sy–msgty, ‘Message’,l_str_message–message.
endif.
endloop.
if sy–subrc eq 0.
call function ‘BAL_DB_SAVE’
exporting
i_save_all = abap_true
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 into l_str_message–message.
write: ‘Type’,sy–msgty, ‘Message’,l_str_message–message.
else.
write: ‘Messages Saved in the log’.
endif.
endif.
endif.
write : ‘done with log number’,l_str_log–extnumber.

在上面的代码中:

  • BAL_LOG_CREATE:创建应用程序日志对象
  • BAL_LOG_MSG_ADD:它将消息添加到应用程序日志记录对象/子对象
  • BAL_DB_SAVE:将消息保存到数据库中。

可以使用事务代码 ​​SLG1​​ 来监视基于对象的应用程序日志记录。

SAP ABAP Application Log 的使用方法_日志记录_03




标签:sy,Log,balmsg,Application,ABAP,str,message,type,log
From: https://blog.51cto.com/jerrywangsap/6010039

相关文章

  • ABAP TEST-SEAM 的使用方法
    ​​ABAPTEST-SEAM的使用方法​​ 语句TEST-SEAM引入了一个称为seam的测试SEAM,它由END-TEST-SEAM关闭。当前程序的测试类(testclass)可以使用语句TEST-I......
  • 如何手动通过增强的方式,给 SAP ABAP 数据库表增添新的字段
    ​​如何手动通过增强的方式,给SAPABAP数据库表增添新的字段​​ 有个朋友向我咨询关于SAP产品增强字段扩展(FieldExtensibility)的问题:Jerry,你好。看过你写的......
  • 使用 SAP CRM Application Enhancement Tool(AET) 创建扩展字段
    ​​使用SAPCRMApplicationEnhancementTool(AET)创建扩展字段​​ 本文的英文版,发表在SAP社区wiki上,原文标题:​​StepbysteptocreatenewfieldsonU......
  • ABAP include structure 的一个具体用法
    ​​ABAPincludestructure的一个具体用法​​ 在客户系统中使用appendstructure增强SAP结构或SAP表,这种行为并不构成修改(modification)。这一点在SAP​......
  • Command line is too long. Shorten command line for TestMain or also for Applicat
       idea运行项目报错:Commandlineistoolong.ShortencommandlineforTestMainoralsoforApplicationdefault configuration.解决方法如下:   ......
  • Oracle Rman archivelog
    0x00Rman的归档日志管理   archivelog的相关信息是记录在controlfile中的,当物理删除后不会改变controlfile的设置。并且在查询相关的动态视图(例如v$archived_log)时......
  • binlog学习
    binlog中记载了数据库发生的变化,比方说新建了一个数据库或者表、表结构发生改变、表中的数据发生了变化时都会记录相应的binlog日志。binlog主要用在下边两个方面:用途一......
  • 使用Logstash工具导入sqlserver数据到elasticSearch及elk分布式日志中心
    首先记下这个笔记,Logstash工具导入sqlserver数据到elasticSearch。因为logstash使用java写的,我本地开发是win11,所以javadejdk必须要安装。具体安装不介绍了,就是网上下个j......
  • win32com操作word 第二集:Application&Documents接口
    本课程《win32com操作wordAPI精讲&项目实战》以视频为主,文字教程为辅,公众号ID:一灯编程。先回答一个网友私信问题:win32com和微软的word接口文档有什么关系win32com......
  • QT之对话框QDialog
    本文章目录​​系列文章目录​​​​一、基本概念​​​​1.1标准对话框​​​​1.2自定义消息框​​​​二、模态对话框​​​​三、非模态对话框​​​​四、消息对话......