一种是rase
FUNCTION ztest.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(NOB) TYPE I OPTIONAL
*" EXPORTING
*" VALUE(NAME) TYPE CHAR10
*" EXCEPTIONS
*" DEV_ZERO
*"----------------------------------------------------------------------
IF nob <> .
name = '张三'.
ELSE.
RAISE dev_zero .
ENDIF.
ENDFUNCTION.
程序中调用:在程序里自己处理异常
REPORT ZTEST_FC.
DATA : lv TYPE i,
lc TYPE char10.
lv = .
CALL FUNCTION 'ZTEST'
EXPORTING
NOB = LV
IMPORTING
NAME = LC
EXCEPTIONS
DEV_ZERO =
OTHERS =
.
IF sy-subrc = .
MESSAGE '我在处理异常DEV_ZERO' TYPE 'E'.
ENDIF.
另一种是不需要在程序中处理,自己要在函数中写好处理异常。message type rasing
FUNCTION ztest.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(NOB) TYPE I OPTIONAL
*" EXPORTING
*" VALUE(NAME) TYPE CHAR10
*" EXCEPTIONS
*" DEV_ZERO
*"----------------------------------------------------------------------
IF nob <> .
name = '张三'.
ELSE.
MESSAGE '处理异常' TYPE 'E' RAISING dev_zero .
ENDIF.
ENDFUNCTION.
REPORT ZTEST_FC.
DATA : lv TYPE i,
lc TYPE char10.
lv = .
CALL FUNCTION 'ZTEST'
EXPORTING
NOB = LV
IMPORTING
NAME = LC
EXCEPTIONS
DEV_ZERO =
OTHERS =
.
IF sy-subrc <> .
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO "函数ZTEST 里面的处理消息 赋在SY-MSGID SY-MSGTY SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
手机扫一扫
移动阅读更方便
你可能感兴趣的文章