2007 Jul 19 3:57 PM
Hi,
data : num1 type i ,
num2 type i.
num1 = 7.
num2 = 10.
perform find_sum using num1 num2.
write / : num1 , 'out put will be 7 itself'.
*********changing**********
perform find_sum1 changing num1 num2.
write / : num1 , 'out put will be 17 '.
&----
*& Form find_sum1
&----
text
----
<--P_NUM1 text
<--P_NUM2 text
----
form find_sum1 changing p_num1 type i
p_num2 type i.
num1 = num1 + num2.
endform. " find_sum1
&----
*& Form find_sum
&----
text
----
-->P_NUM1 text
-->P_NUM2 text
----
form find_sum using p_num1 type i
p_num2 type i.
num1 = num1 + num2.
endform. " find_sum
This is what i see an output,
17 out put will be 7 itself
27 out put will be 17
ACTUAL IT SHOULD BE LIKE THIS RIGHT
7 out put will be 7 itself
17 out put will be 17
lET ME KNOW WHERE IAM GOING WRONG
2007 Jul 19 4:03 PM
Hi,
You have to use local variable only to do operation inside the subroutine.
data : num1 type i ,
num2 type i.
num1 = 7.
num2 = 10.
perform find_sum using num1 num2.
write / : num1 , 'out put will be 7 itself'.
*********changing**********
perform find_sum1 changing num1 num2.
write / : num1 , 'out put will be 17 '.
form find_sum using p_num1 type i
p_num2 type i.
p_num1 = p_num1 + p_num2.
endform. " find_sum
form find_sum1 changing p_num1 type i
p_num2 type i.
p_num1 = p_num1 + p_num2.
endform. " find_sum
then it will give u the value u want.<i></i>
Message was edited by:
Vigneswaran S
2007 Jul 19 4:01 PM
Change the code like this.
num1 = 7.
num2 = 10.
<b>write / : num1 , 'out put will be 7 itself'.</b>
perform find_sum using num1 num2.
<b>write / : num1 , 'out put will be 17 '.</b>
*********changing**********
perform find_sum1 changing num1 num2.
Reward if helpful.
2007 Jul 19 4:03 PM
Hi,
You have to use local variable only to do operation inside the subroutine.
data : num1 type i ,
num2 type i.
num1 = 7.
num2 = 10.
perform find_sum using num1 num2.
write / : num1 , 'out put will be 7 itself'.
*********changing**********
perform find_sum1 changing num1 num2.
write / : num1 , 'out put will be 17 '.
form find_sum using p_num1 type i
p_num2 type i.
p_num1 = p_num1 + p_num2.
endform. " find_sum
form find_sum1 changing p_num1 type i
p_num2 type i.
p_num1 = p_num1 + p_num2.
endform. " find_sum
then it will give u the value u want.<i></i>
Message was edited by:
Vigneswaran S
2007 Jul 19 4:03 PM
Even though you are specifying the parameters as USING, you are passing them by reference, so the original value will get change. You need to use USING .. VALUE(p).
USING ... p ...
The parameters are passed by reference. The field passed can be changed within the subroutine. The changes are kept beyond the subroutine.
USING ... VALUE(p) ...
The VALUE(...) addition passes the parameter by copying the field contents to a corresponding local field. VALUE parameters behave in the same way as local fields.
2007 Jul 19 4:15 PM
Hi Kajol,
I have corrected ur code check it out.
REPORT ztestprg.
DATA : num1 TYPE i ,
num2 TYPE i.
num1 = 7.
num2 = 10.
PERFORM find_sum USING num1 num2 .
WRITE / : num1 , 'out put will be 7 itself'.
*********changing**********
PERFORM find_sum1 CHANGING num1 num2.
WRITE / : num1 , 'out put will be 17 '.
&----
*& Form find_sum1
&----
text
----
<--P_NUM1 text
<--P_NUM2 text
----
FORM find_sum1 CHANGING p_num1 TYPE i
p_num2 TYPE i.
p_num1 = p_num1 + p_num2.
ENDFORM. " find_sum1
<b>&----
*& Form find_sum
&----
text
----
-->P_NUM1 text
-->P_NUM2 text
----
FORM find_sum using value(p_num1) p_num2 .
p_num1 = p_num1 + p_num2.
ENDFORM. " find_sum</b>
Thanks
mahesh
2007 Jul 19 4:20 PM