How to print non-Polachi Fibonacci with functional programming idea in ABAP
Editor to share with you how to use functional programming ideas in ABAP to print out non-Polachi Fibonacci, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
There are also many ways to implement this requirement in ABAP.
The following report implements the printing of non-Polage series by recursion and ABAP internal table, respectively.
REPORT Z_FIBO.PARAMETERS: n type iMagic v1 RADIOBUTTON GROUP v default 'Xray Magazine v2 RADIOBUTTON GROUP v.data: F type iMagery 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 ichanging fib type i.data: Fair1 type I Fogg 2 type I type i.case in.when 1 type I 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 nasty 1 changing f_1.perform fibonacci using nasty 2 changing f_2.fib = feng1 + f_2.endcase.endform. "fibonacci*&----**& Form fibonacci_2*&-- -- * form fibonacci_2 using in type ichanging fib type i.data: Fair1 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) nude 1 = 1.n_2 = 2.1 = in-1.do l times.read table fibo index nasty 1 into f_1.read table fibo index nasty 2 into f_2.fib = fission 1 + f_2.add 1 to nasty 1\ .add 1 to n_2.append fib to fibo.enddo.endform." fibonacci_2
Both of the above solutions are relatively traditional, so let's take a look at non-Polachi sequence printing using the new keyword COND provided by ABAP 7.40:
REPORT z.CLASS lcl_fibonacci DEFINITION.PUBLIC SECTION.TYPES: zint_tab TYPE TABLE OF int4 WITH EMPTY KEY.METHODS fibonacciIMPORTING! n TYPE i RETURNING VALUE (fib_numbers) TYPE zint_tab.ENDCLASS.CLASS lcl_fibonacci IMPLEMENTATION.METHOD fibonacci.fib_numbers = COND # (WHEN n = 0THEN VALUE # ((| 0 |)) WHEN n = 1THEN VALUE # ((| 0 |) (| 1 |)) ELSEVALUE # (LET fn1 = fibonacci (n-1) x = fn1 [lines (fn1)] y = fn1 [lines (fn1) )-1] IN (LINES OF fn1) (x + y). ENDMETHOD.ENDCLASS.START-OF-SELECTION.cl_demo_output= > display (NEW lcl_fibonacci ()-> fibonacci (10).
Printout:
The above is all the contents of the article "how to print non-Polachi Fibonacci with functional programming in ABAP". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!