使用ABAP内表作为数据结构实现非波拉契数列(fibonacci)的生成
发布日期:2021-06-30 14:06:05 浏览次数:3 分类:技术文章

本文共 1930 字,大约阅读时间需要 6 分钟。

*&---------------------------------------------------------------------**TODO: Jerry can send Xun about new implementation on 2016-12-4 21:17PM - aircraft from Germany to China*&---------------------------------------------------------------------*REPORT Z_FIBO.PARAMETERS: N type i,            v1 RADIOBUTTON GROUP v default 'X',            v2 RADIOBUTTON GROUP v.data: f type i,      t type i.data: product_guid type comm_product-product_guid.get run time field t.case 'X'.  when v1. perform fibonacci using n changing f.  when v2. perform fibonacci_2 using n changing f.endcase.write: / 'Fibonacci(', n, ') =', f.get run time field t.write: / 'Runtime', t, 'microseconds'.*&---------------------------------------------------------------------**&      Form  fibonacci*&---------------------------------------------------------------------*form fibonacci using in type i               changing fib type i.  data: f_1 type i, f_2 type i,        n_1 type i, n_2 type i.  case in.    when 0. fib = 1.    when 1. fib = 1.    when others.      n_1 = in - 1.      n_2 = in - 2.      perform fibonacci using n_1 changing f_1.      perform fibonacci using n_2 changing f_2.      fib = f_1 + f_2.  endcase.endform.                    "fibonacci*&---------------------------------------------------------------------**&      Form  fibonacci_2*&---------------------------------------------------------------------*form fibonacci_2 using in type i                 changing fib type i.  data: f_1 type i, f_2 type i,        n_1 type i, n_2 type i,        l type i.  data: fibo type table of i.  append 1 to fibo. " fibonacci(0)  append 1 to fibo. " fibonacci(1)    n_1 = 1.    n_2 = 2.  l = in - 1.  do l times.    read table fibo index n_1 into f_1.    read table fibo index n_2 into f_2.    fib = f_1 + f_2.    add 1 to n_1. add 1 to n_2.    append fib to fibo.  enddo.endform.                    "fibonacci_2

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

转载地址:https://jerry.blog.csdn.net/article/details/103967959 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:用ABAP代码调用Netweaver里的where used list功能
下一篇:使用ABAP操作XML DOM时,如何利用filter功能

发表评论

最新留言

很好
[***.229.124.182]2024年04月28日 06时16分34秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章