04-22-2008 1:39 PM
Hi all
can anyone gimme the answer for this program
REPORT demo_mod_tech_example_2.
DATA: num TYPE i VALUE 5,
fac TYPE i VALUE 0.
PERFORM fact USING num CHANGING fac.
WRITE: / 'Factorial of', num, 'is', fac.
FORM fact
USING value(f_num) TYPE i
CHANGING f_fact TYPE i.
f_fact = 1.
WHILE f_num GE 1.
f_fact = f_fact * f_num.
f_num = f_num - 1.
ENDWHILE.
ENDFORM.
04-22-2008 1:43 PM
04-22-2008 1:43 PM
04-22-2008 1:49 PM
Hi
can u please explain the how u got the right answer??
Coz i am bit confused.
Thanks and Regards
Arun
04-22-2008 1:52 PM
Hi Arun,
Just put a break point in the subroutine and check out what is happening
Check out the values of the variables in debugging
you will get to know
04-22-2008 1:59 PM
Hi chandrasekar,
I know that i can debug and found it out.
I dont have access to SAP System.. if i got system i would have never raised this query.
Hope u understand.
Thanks,
Arun
04-22-2008 2:00 PM
04-22-2008 2:25 PM
In your form the value of f_num is 5(ie, default value) at first time and value of f_fact = 1.
and inwhile loop.
1st iteration
f_fact = f_fact * f_num. ie, 1* 5 = 5.
f_num = f_num - 1. ie, 5 -1 =4
2nd iteration
f_fact = f_fact * f_num. ie, 5* 4 = 20.
f_num = f_num - 1. ie, 4 -1 =3
3rd iteration
f_fact = f_fact * f_num. ie, 20* 3 = 60.
f_num = f_num - 1. ie, 3 -1 =2
4thiteration
f_fact = f_fact * f_num. ie, 60* 2 = 20.
f_num = f_num - 1. ie, 2 -1 = 1
Now control control reaches Endwhile as f_num not greater than 1 and returns the value of f_num(ie,120) to fac.