赶上 SAPSQL_DATA_LOSS
Catch SAPSQL_DATA_LOSS
我想在我的 ABAP 代码中捕获并处理 SAPSQL_DATA_LOSS
。
我试过这个:
try.
SELECT *
FROM (rtab_name) AS rtab
WHERE (sub_condition)
into table @<sub_result>
.
catch SAPSQL_DATA_LOSS into error.
...
endtry.
但是上面的代码是无效的。我收到此消息:
Type "SAPSQL_DATA_LOSS" is not valid
我试过这个:
catch SYSTEM-EXCEPTIONS SAPSQL_DATA_LOSS = 123.
SELECT *
...
.
endcatch.
if sy-subrc = 123.
...
endif.
但是上面的代码给了我:
Instead of "SAPSQL_DATA_LOSS" expected "system-exception" (translated from german to english by me)
如何捕捉SAPSQL_DATA_LOSS
?
此问题与 "why does this exception happen?" 无关。这已经解决了。我的代码应该处理异常。
SAPSQL_DATA_LOSS
是运行时错误。
由于 SAPSQL_DATA_LOSS
不是基于 class 的异常,因此无法使用 try catch
捕获它。
由于 SAPSQL_DATA_LOSS
不是可捕获的 运行时错误,因此无法使用 try catch SYSTEM-EXCEPTIONS
.
捕获它
查看以下可捕获的运行时错误。
https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenueb-abfb-sysexc.htm
经过一些尝试,我可以向您提出一个可能的解决方案。
这是一个解决方法:
不知道能不能适用于你的情况,因为需要把select语句封装成一个RFC函数模块!
要点是可以在 RFC 调用中处理短转储(消息类型 X)。
因此使用 RFC(例如 CALL FUNCTION 'xxxxx' destination 'NONE'
)并使用特殊异常 SYSTEM_FAILURE
,系统不会终止调用程序,而是 returns a SY-SUBRC > 0
与系统消息字段 (SY-MSGxx) 中的短转储信息。
步骤
创建函数模块(启用 RFC) 使用您的 select 语句输入 + 结果的行类型 table。 (所有参数按值传递)
您需要最后一个参数,因为通用 tables 不能在 RFC 中传递(不允许 "TYPE ANY TABLE")
FUNCTION Z_DYN_SEL .
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(RTAB_NAME) TYPE TABNAME16
*" VALUE(SUB_CONDITION) TYPE STRING
*" VALUE(RESULT_TYPE) TYPE STRING
*"----------------------------------------------------------------------
* RTAB_NAME: DB Table
* SUB_CONDITION: WHERE Condition
* RESULT_TYPE: The ROW type of the internal table
field-symbols <sub_result> type any table.
* DEFINE LOCAL DYNAMIC TABLE TO STORE THE RESULT
data: lr_res type ref to data.
create data lr_res type standard table of (result_type).
assign lr_res->* to <sub_result>.
* DYNAMIC SELECT
select *
from (rtab_name) as rtab
where (sub_condition)
into table @<sub_result>.
* EXPORT RESULT TO A MEMORY ID, SO IT CAN BE RETRIEVED BY CALLER
export res = <sub_result> to memory id 'RES'.
主程序:
在这个调用者示例中,一些参数被传递给 RFC。
KTOKD 字段(应为 4 个字符长)与 char10 值一起传递(生成短转储)。
如果函数内部触发了任何转储,我们现在可以处理它。
如果一切顺利,IMPORT
来自 RFC
中的 EXPORT
语句
field-symbols <sub_result> type any table.
data: lr_res type ref to data.
create data lr_res type standard table of KNA1.
assign lr_res->* to <sub_result>.
data lv_msg type char255.
call function 'Z_DYN_SEL' destination 'NONE'
exporting
rtab_name = 'KNA1'
sub_condition = `KTOKD = 'D001xxxxxx'`
result_type = 'KNA1'
exceptions
system_failure = 1 message lv_msg.
if sy-subrc = 0.
import res = <sub_result> from memory id 'RES'.
else.
write: / lv_msg.
write : / sy-msgid, sy-msgno, sy-msgty, sy-msgv1, sy-msgv2, sy-msgv3, sy-msgv4.
endif.
结果
在 select 语句中出现短转储的情况下进行 RFC 调用后,程序不会终止,并提供以下信息
SY-SUBRC = 1
lv_msg
是错误文本(复制值时数据丢失。)
Sy-msgid = 00
Sy-msgno = '341'
Sy-msgty = 'X'
Sy-msgv1 = 'SAPSQL_DATA_LOSS'
我想在我的 ABAP 代码中捕获并处理 SAPSQL_DATA_LOSS
。
我试过这个:
try.
SELECT *
FROM (rtab_name) AS rtab
WHERE (sub_condition)
into table @<sub_result>
.
catch SAPSQL_DATA_LOSS into error.
...
endtry.
但是上面的代码是无效的。我收到此消息:
Type "SAPSQL_DATA_LOSS" is not valid
我试过这个:
catch SYSTEM-EXCEPTIONS SAPSQL_DATA_LOSS = 123.
SELECT *
...
.
endcatch.
if sy-subrc = 123.
...
endif.
但是上面的代码给了我:
Instead of "SAPSQL_DATA_LOSS" expected "system-exception" (translated from german to english by me)
如何捕捉SAPSQL_DATA_LOSS
?
此问题与 "why does this exception happen?" 无关。这已经解决了。我的代码应该处理异常。
SAPSQL_DATA_LOSS
是运行时错误。
由于 SAPSQL_DATA_LOSS
不是基于 class 的异常,因此无法使用 try catch
捕获它。
由于 SAPSQL_DATA_LOSS
不是可捕获的 运行时错误,因此无法使用 try catch SYSTEM-EXCEPTIONS
.
查看以下可捕获的运行时错误。
https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenueb-abfb-sysexc.htm
经过一些尝试,我可以向您提出一个可能的解决方案。
这是一个解决方法:
不知道能不能适用于你的情况,因为需要把select语句封装成一个RFC函数模块!
要点是可以在 RFC 调用中处理短转储(消息类型 X)。
因此使用 RFC(例如 CALL FUNCTION 'xxxxx' destination 'NONE'
)并使用特殊异常 SYSTEM_FAILURE
,系统不会终止调用程序,而是 returns a SY-SUBRC > 0
与系统消息字段 (SY-MSGxx) 中的短转储信息。
步骤
创建函数模块(启用 RFC) 使用您的 select 语句输入 + 结果的行类型 table。 (所有参数按值传递)
您需要最后一个参数,因为通用 tables 不能在 RFC 中传递(不允许 "TYPE ANY TABLE")
FUNCTION Z_DYN_SEL .
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(RTAB_NAME) TYPE TABNAME16
*" VALUE(SUB_CONDITION) TYPE STRING
*" VALUE(RESULT_TYPE) TYPE STRING
*"----------------------------------------------------------------------
* RTAB_NAME: DB Table
* SUB_CONDITION: WHERE Condition
* RESULT_TYPE: The ROW type of the internal table
field-symbols <sub_result> type any table.
* DEFINE LOCAL DYNAMIC TABLE TO STORE THE RESULT
data: lr_res type ref to data.
create data lr_res type standard table of (result_type).
assign lr_res->* to <sub_result>.
* DYNAMIC SELECT
select *
from (rtab_name) as rtab
where (sub_condition)
into table @<sub_result>.
* EXPORT RESULT TO A MEMORY ID, SO IT CAN BE RETRIEVED BY CALLER
export res = <sub_result> to memory id 'RES'.
主程序: 在这个调用者示例中,一些参数被传递给 RFC。
KTOKD 字段(应为 4 个字符长)与 char10 值一起传递(生成短转储)。
如果函数内部触发了任何转储,我们现在可以处理它。
如果一切顺利,IMPORT
来自 RFC
EXPORT
语句
field-symbols <sub_result> type any table.
data: lr_res type ref to data.
create data lr_res type standard table of KNA1.
assign lr_res->* to <sub_result>.
data lv_msg type char255.
call function 'Z_DYN_SEL' destination 'NONE'
exporting
rtab_name = 'KNA1'
sub_condition = `KTOKD = 'D001xxxxxx'`
result_type = 'KNA1'
exceptions
system_failure = 1 message lv_msg.
if sy-subrc = 0.
import res = <sub_result> from memory id 'RES'.
else.
write: / lv_msg.
write : / sy-msgid, sy-msgno, sy-msgty, sy-msgv1, sy-msgv2, sy-msgv3, sy-msgv4.
endif.
结果
在 select 语句中出现短转储的情况下进行 RFC 调用后,程序不会终止,并提供以下信息
SY-SUBRC = 1
lv_msg
是错误文本(复制值时数据丢失。)
Sy-msgid = 00
Sy-msgno = '341'
Sy-msgty = 'X'
Sy-msgv1 = 'SAPSQL_DATA_LOSS'