• se37 函数中的异常使用


    一种是rase <exceptions>

    FUNCTION ztest.
    *"----------------------------------------------------------------------
    *"*"Local interface:
    *"  IMPORTING
    *"     VALUE(NOB) TYPE  I OPTIONAL
    *"  EXPORTING
    *"     VALUE(NAME) TYPE  CHAR10
    *"  EXCEPTIONS
    *"      DEV_ZERO
    *"----------------------------------------------------------------------
    IF nob <> 0.
    name = '张三'.
    ELSE.
    RAISE dev_zero .
    ENDIF.
    ENDFUNCTION.

    程序中调用:在程序里自己处理异常

    REPORT  ZTEST_FC.
    
    DATA : lv  TYPE i,
          lc TYPE char10.
    lv = 0.
    
    CALL FUNCTION 'ZTEST'
     EXPORTING
       NOB            = LV
     IMPORTING
       NAME           = LC
     EXCEPTIONS
       DEV_ZERO       = 1
       OTHERS         = 2
              .
    IF sy-subrc = 1.
     MESSAGE '我在处理异常DEV_ZERO' TYPE 'E'.
    ENDIF.

    另一种是不需要在程序中处理,自己要在函数中写好处理异常。message type rasing <exceptions>

    FUNCTION ztest.
    *"----------------------------------------------------------------------
    *"*"Local interface:
    *"  IMPORTING
    *"     VALUE(NOB) TYPE  I OPTIONAL
    *"  EXPORTING
    *"     VALUE(NAME) TYPE  CHAR10
    *"  EXCEPTIONS
    *"      DEV_ZERO
    *"----------------------------------------------------------------------
    IF nob <> 0.
    name = '张三'.
    ELSE.
      MESSAGE '处理异常' TYPE 'E' RAISING dev_zero .
    ENDIF.
    
    ENDFUNCTION.
    REPORT  ZTEST_FC.
    
    DATA : lv  TYPE i,
          lc TYPE char10.
    lv = 0.
    
    CALL FUNCTION 'ZTEST'
     EXPORTING
       NOB            = LV
     IMPORTING
       NAME           = LC
     EXCEPTIONS
       DEV_ZERO       = 1
       OTHERS         = 2
              .
    IF sy-subrc <> 0.
     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.
  • 相关阅读:
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    National Treasures HDU
    Matrix HDU
    过山车 HDU
    Jimmy’s Assignment HDU
    Card Game Cheater HDU
    Uncle Tom's Inherited Land* HDU
    50 years, 50 colors HDU
  • 原文地址:https://www.cnblogs.com/caizjian/p/8138171.html
Copyright © 2020-2023  润新知