abap TRY catch 抓不到消息
问题:今天写了个F.80的需求, 参考标准代码加了校验,发现了一个很奇怪的问题,那就是如果函数抛出的异常抓不到怎么办!(有关异常的相关知识可以参考异常处理),参考以下代码,会发现即使使用cx_root也抓不到message.(是带参数的message,不是直接raise exceptions,看下图)
DATA:X_DIALOG TYPE C." VALUE 'X'.
TRY .
CALL FUNCTION 'FI_ACCOUNT_CHECK'
EXPORTING
I_BUKRS = P_GS_OUTPUT-RBUKRS
I_KOART = P_GS_OUTPUT-KOART
I_ACCOUNT = P_GS_OUTPUT-RACCT
I_RECACCOUNT = P_GS_OUTPUT-RACCT "NOTE 323557
I_WAERS = P_GS_OUTPUT-RHCUR
I_TCODE = 'FB08'
X_DIALOG = X_DIALOG "WARNUNGEN IM DIALOG
EXCEPTIONS
ACCOUNT_LOCKED = 1
CURRENCY = 2
NO_RECONCILIATION_ACCOUNT = 3
RECONCILIATION_ACCOUNT = 4
RECONCILIATION_ACCOUNT_LOCKED = 5
.
CATCH CX_SY_DYN_CALL_ILLEGAL_FUNC INTO DATA(LT_CX_FOEV_ERROR_IN_FUNCTION).
* EXPORT
* EBUF0002 BUFFER_ID_DATE BUFFER_ID_TIME
* TO SHARED BUFFER CONTEXTB(EB) ID BUFFER_ID.
ENDTRY.
IF SY-SUBRC NE 0.
P_LV_ERROR = 'X'.
ENDIF.
解决:那么有没有什么好办法能抓到message呢?既然文章发出来,那当然是有了。其实很简单,再endtry后面加个判断就好了
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.