FORM fibo USING value(p_p_num)
CHANGING p_w_res.
DATA :
w_temp TYPE i, " Temporary Variable
w_no1 TYPE i, " Number Variable One
w_no2 TYPE i, " Number Variable TWO
w_add TYPE i. " Stores Sum Of Above 2 Variables
w_temp = p_p_num.
IF w_temp EQ 1 OR w_temp EQ 2.
p_w_res = 1.
ELSE.
w_add = 0.
w_no1 = w_temp - 1.
w_no2 = w_temp - 2.
PERFORM fibo USING w_no1 CHANGING p_w_res.
w_add = w_add + p_w_res.
PERFORM fibo USING w_no2 CHANGING p_w_res.
w_add = w_add + p_w_res.
p_w_res = w_add.
ENDIF.
ENDFORM.
class ZTRAININGC definition
public
final
create public .
public section.
interfaces IF_OO_ADT_CLASSRUN.
methods RECURSION
changing PREV type STRING
NEXT type STRING.
class-data: IT_FIBONACCI type table of STRING. "Global Table to Store Fibonacci Numbers
class-data: WA_FIBONACCI like line of IT_FIBONACCI. "Global Work Area for Internal Table
protected section.
private section.
endclass.
class ZTRAININGC implementation.
method IF_OO_ADT_CLASSRUN~MAIN. "Parent Method From Which Recurring Method is nitially Called
data:NEXT type STRING.
data:PREV type STRING.
PREV = 0.
NEXT = 1.
OUT->WRITE( PREV ).
OUT->WRITE( NEXT ).
call method RECURSION "Initial Call
changing
PREV = PREV
NEXT = NEXT.
OUT->WRITE( IT_FIBONACCI ).
endmethod.
method RECURSION. "Recursing Method
data:TEMP type STRING.
if NEXT < 100. "Condition for Recursion
TEMP = PREV.
PREV = NEXT.
NEXT = TEMP + PREV.
WA_FIBONACCI = NEXT.
append WA_FIBONACCI to IT_FIBONACCI.
call method RECURSION "Recurring Call
changing
PREV = PREV
NEXT = NEXT.
endif.
endmethod.
endclass.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
14 | |
10 | |
9 | |
7 | |
5 | |
4 | |
4 | |
4 | |
4 |