如何解决SAPGUI 不显示 long_text 或未处理的自定义异常的文本
在 SAP NetWeaver 7.52 中,我创建了一个基于 ABAP 分类的异常,该异常在报告/程序中的 try catch 子句中执行时运行良好。但是当异常不是由 try catch 子句处理时,自定义消息不会显示在 SAPGUI 中。
我正在寻找的是,当没有定义 try catch 时,在引发语句时使用的导出消息显示在“UNCAUGHT_EXCEPTION”中。我尝试重新定义 get_text( ) 和 get_longtext( ) 方法。但是 ABAP 运行时错误并没有向开发人员提供任何关于原因的有用信息(存储在异常的“attr_message”属性中)。
当使用“try catch”时,可以毫无问题地检索消息,但其想法是 SAPGUI 在“ABAP 运行时错误”报告中向开发人员显示正确的消息。
zcx_adk_exception.abap
"! Base exception for all ABAP Development Kit (ADK) exceptions
class zcx_adk_exception definition public create public inheriting from cx_dynamic_check.
public section.
"! Initializes the exception message
"! @parameter message | Message related to the reason of the exception
methods constructor
importing value(message) type zadk_str optional.
"! Returns the message associated to the exception
methods get_message
returning value(result) type zadk_str.
methods if_message~get_text redefinition.
methods if_message~get_longtext redefinition.
private section.
data attr_message type zadk_str value ''.
endclass.
class zcx_adk_exception implementation.
method constructor ##ADT_SUPPRESS_GENERATION.
super->constructor( ).
if message is not initial.
me->attr_message = message.
endif.
endmethod.
method get_message.
result = me->attr_message.
endmethod.
method if_message~get_text.
result = me->get_message( ).
endmethod.
method if_message~get_longtext.
result = me->get_message( ).
endmethod.
endclass.
什么工作正常:
try.
raise exception type zcx_adk_exception exporting message = 'Base_Exception_Error'.
catch zcx_adk_exception into data(ex).
write: / 'Example 1:',ex->get_message( ).
write: / 'Example 2:',ex->get_text( ).
write: / 'Example 2:',ex->get_longtext( ).
endtry.
输出是这样的:
什么不起作用:
" Not Catching the exception
raise exception type zcx_adk_exception exporting message = 'Base_Exception_Error'.
这会导致显示以下消息
解决方法
按照之前提出的使用消息的想法,我想出了以下代码,允许使用消息引发异常。这允许异常在“try catch”块中调用时显示正确的消息,并在 SAPGUI 生成的转储的“错误分析”部分显示有用的消息。
解决方案:
"! Program to test functionalities and utilities
REPORT zsandbox_tests.
" Exception Class
CLASS lcl_exception DEFINITION INHERITING FROM cx_dynamic_check.
PUBLIC SECTION.
INTERFACES if_t100_dyn_msg.
METHODS if_message~get_text REDEFINITION.
METHODS constructor
IMPORTING VALUE(message) TYPE string.
PRIVATE SECTION.
DATA attr_message TYPE string VALUE ''.
ENDCLASS.
CLASS lcl_exception IMPLEMENTATION.
METHOD if_message~get_text.
result = attr_message.
ENDMETHOD.
METHOD constructor.
super->constructor( ).
me->attr_message = message.
ENDMETHOD.
ENDCLASS.
" Class that raises the exception
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main RAISING lcl_exception.
ENDCLASS.
CLASS lcl_main IMPLEMENTATION.
METHOD main.
DATA raise_message TYPE string VALUE 'Custom Message for the Exception'.
RAISE EXCEPTION TYPE lcl_exception
MESSAGE e000(lcl_exception) WITH raise_message '' '' '' " The if_t100_dyn_msg supports 4 attributes: V1,V2,V3 and V4 but I only use the first one
EXPORTING message = raise_message.
ENDMETHOD.
ENDCLASS.
" Call to Main Method
START-OF-SELECTION.
TRY.
lcl_main=>main( ).
CATCH lcl_exception INTO DATA(ex).
WRITE ex->get_text( ).
ENDTRY.
未使用 try catch 时:
" Call to Main Method
start-of-selection.
lcl_main=>main( ).
,
TL;DR:SAP 不打算允许开发人员定制一个简短的转储。
“short dump”是ABAP程序中发生意外错误时由ABAP内核生成的报告,即由于程序中的错误(通常是未捕获的异常或不可捕获的错误)而导致的错误或系统故障(输入/输出资源、内存资源等)
旨在帮助开发人员分析错误原因并进行纠正。
它不是有意生成的,除非开发人员在理论上不可能,但实际上发生了,并且被认为需要很多信息来分析它是否发生,因此是一个简短的转储。
如果您真的打算生成带有消息的简短转储,出于某种目的,有两种方法:
-
MESSAGE 'message text' TYPE 'X'.
(常用于标准 SAP 程序,尤其是更新功能模块) -
RAISE SHORTDUMP ...
或... THEN THROW SHORTDUMP ...
在条件表达式中。两者自 ABAP 7.53 以来都存在。例如RAISE SHORTDUMP TYPE zcx_adk_exception EXPORTING message = 'Base_Exception_Error'.
简短转储将包含分析部分中的消息文本。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。