1. 程式人生 > >ABAP自定義功能函數

ABAP自定義功能函數

bsp ndt 自定義 overflow exp export pre div cal

1、實現計算器中階乘函數

FUNCTION zfun_mm_001.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     REFERENCE(I_I) TYPE  I
*"  EXPORTING
*"     REFERENCE(O_I) TYPE  I
*"  EXCEPTIONS
*"      E_LARGE
*"----------------------------------------------------------------------
DATA t_o TYPE i. DATA t_i TYPE i. t_i = i_i. IF i_i GT 1. t_i = t_i - 1. CALL FUNCTION ZFUN_MM_001 EXPORTING i_i = t_i IMPORTING o_i = t_o . TRY. o_i = t_o * i_i. CATCH cx_sy_arithmetic_overflow. o_i
= 0. ENDTRY. ELSEIF i_i = 1. o_i = 1. ELSE. o_i = 0. ENDIF. ENDFUNCTION.

2、實現計算器中累加函數1+2+3+...+n

FUNCTION ZFUN_MM_002.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     REFERENCE(I_I) TYPE  I
*"  EXPORTING
*"     REFERENCE(O_I) TYPE  I
*
"---------------------------------------------------------------------- IF i_i GT 1. CALL FUNCTION ZFUN_MM_002 EXPORTING i_i = i_i - 1 IMPORTING o_i = o_i . TRY. o_i = o_i + i_i. CATCH cx_sy_arithmetic_overflow. o_i = 0. ENDTRY. ELSE. o_i = 1. ENDIF. ENDFUNCTION.

ABAP自定義功能函數