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.
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/18049.html