您好,欢迎来到小侦探旅游网。
搜索
您的当前位置:首页ABAP 函数的异常使用

ABAP 函数的异常使用

来源:小侦探旅游网


1,函数异常

报异常的方法:

(1)raise no_num_1.直接报,不会产生系统消息,但是SY-SUBRC 会不为0。 (2)报消息文本。

message e398(00) with 'Number 1 has not been supplied' raising no_num_1.

另外:可以根据异常的短文本描述来返回异常。

函数:SWO_TEXT_FUNCTION_EXCEPTION可以返回函数的参数的文本描述。

function ztest.

*\"----------------------------------------------------------------------

*\"*\"Local interface: *\" IMPORTING

*\" VALUE(IF_NUM1) TYPE I OPTIONAL *\" VALUE(IF_NUM2) TYPE I OPTIONAL *\" EXPORTING

*\" VALUE(EF_SUM) TYPE I *\" EXCEPTIONS *\" NO_NUM_1

*\"----------------------------------------------------------------------

if if_num1 is initial.

data: l_fun type funct-funcname, l_exc type funct-parameter, l_txt type swotlq-shorttext. *

l_fun = 'ZTEST'. l_exc = 'NO_NUM_1'. *

* text of the Exception

call function 'SWO_TEXT_FUNCTION_EXCEPTION' exporting

language = sy-langu function = l_fun exception = l_exc importing

shorttext = l_txt.

message e398(00) with 'Number 1 has not been supplied' raising no_num_1. * raise no_num_1. exit. endif. * ef_sum = if_num1 + if_num2. endfunction.

调用:

*&---------------------------------------------------------------------*

*& Report ZTEST09 *&

*&---------------------------------------------------------------------* *& *&

*&---------------------------------------------------------------------*

report ztest09.

data: lf_num1 type i, lf_num2 type i, lf_sum type i. lf_num2 = 10.

call function 'ZTEST' exporting

if_num1 = lf_num1 if_num2 = lf_num2 importing

ef_sum = lf_sum exceptions no_num_1 = 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.

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- xiaozhentang.com 版权所有 湘ICP备2023022495号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务