sap exceptions处理

Report Z_YY_TEST_03.

parameters number type i.
data result type p decimals 2.
data oref type ref to cx_root.
data text type string.

start-of-selection.
try.
if abs( number ) > 100.
raise exception type cx_demo_abs_too_large. "RAISE EXCEPTION手动触发异常
endif.
try.
result = 1 / number.
write: / ‘Result of division:’, result.

      result = sqrt( number ).
      write: / 'Result of square root:', result.
  •    catch cx_sy_zerodivide into oref."输出0时会在这里捕获
    

" catch cx_sy_arithmetic_error into oref."输出0时会在这里捕获
" text = oref->get_text( ).
" concatenate 'CATCH cx_sy_arithmetic_error : ’ text into text.

    cleanup."当内层TRY发生了异常,且没有被捕获到,抛到外层TRY前会被执行
      clear result.
      write: / 'cleanup'.
  endtry.
catch cx_sy_arithmetic_error into oref."输入负数会在这里捕获
  text = oref->get_text( ).
  concatenate 'CATCH cx_sy_arithmetic_error : ' text into text.
  • catch cx_root into oref."输入的数大于100时会在这里捕获
    catch cx_demo_abs_too_large into oref."输入的数大于100时会在这里捕获
    text = oref->get_text( ).
    concatenate 'CATCH cx_root : ’ text into text.
    endtry.

if not text is initial.
write / text.
endif.
write: / ‘Final result:’ NO-GAP, result NO-GAP.

CALL FUNCTION ‘READ_TEXT’
EXPORTING

  • CLIENT                        = SY-MANDT
    ID                            =
    LANGUAGE                      =
    NAME                          =
    OBJECT                        =
    
  • ARCHIVE_HANDLE                = 0
    
  • LOCAL_CAT                     = ' '
    
  • IMPORTING
  • HEADER                        =
    
  • OLD_LINE_COUNTER              =
    
    TABLES
    LINES =
  • EXCEPTIONS
  • ID                            = 1
    
  • LANGUAGE                      = 2
    
  • NAME                          = 3
    
  • NOT_FOUND                     = 4
    
  • OBJECT                        = 5
    
  • REFERENCE_CHECK               = 6
    
  • WRONG_ACCESS_TO_ARCHIVE       = 7
    
  • OTHERS                        = 8
          .
    
    IF SY-SUBRC <> 0.
  • Implement suitable error handling here
    ENDIF.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值