09-15-2008 2:01 PM
Hi Experts,
pls define call by value and call by refarence
Thanks&Regards,
Naresh.
09-15-2008 2:17 PM
Hi,
Call by value : you call function and get just a result after call,
Call by ref : you pass your original variables' adresses and these variables' contents are changed.
Default is call by value.
Here this might be more helpful :
call by value is the default way to handle parameters in a function. Modifying the parameter won't change the original variable passed to the function.
call by reference alters the way parameters are handled. A reference is an alias for the passed variable so changing it will affect the original variable instead of a local copy. Instead of copying a whole lot of data, e.g. objects, call by reference safes a lot of storage due to not copying or, in other words, doubling the merory needed to store the object.
deniz.
Edited by: Deniz Toprak on Sep 15, 2008 4:21 PM
09-15-2008 2:17 PM
Hi,
Call by value : you call function and get just a result after call,
Call by ref : you pass your original variables' adresses and these variables' contents are changed.
Default is call by value.
Here this might be more helpful :
call by value is the default way to handle parameters in a function. Modifying the parameter won't change the original variable passed to the function.
call by reference alters the way parameters are handled. A reference is an alias for the passed variable so changing it will affect the original variable instead of a local copy. Instead of copying a whole lot of data, e.g. objects, call by reference safes a lot of storage due to not copying or, in other words, doubling the merory needed to store the object.
deniz.
Edited by: Deniz Toprak on Sep 15, 2008 4:21 PM
09-15-2008 2:20 PM
cal by value is with respect to content in the memory
cal by ref means w,r, to memory
ie if you change this value inside a form , the effect will be there
in overall program
09-15-2008 2:25 PM
Hi,
By Value
Data : a type I value 20.
Perform sub1 using a.
Write a.
FORM sub1 using value (p_a)
P u2013 a = 15
ENDORM.
In this case during subroutine call, the formal parameter are created as copies of actual parameter.
The formal parameters have the memory of their own. Changes made to formal parameter have no effect on the actual parameter.
Like in this case, though value of p_a is changed to 15, it has no effect on u2018au2019 which remains as 20.
By Reference
Data: a type I value 20.
Perform sub1 using a.
Write a.
FORM sub1 using value (p_a)
P u2013 a = 15.
ENDORM.
By default system calls all the forms by reference.
In this case, only the address of the actual parameter is transferred to the formal parameters. The formal parameter has no memory of its own. If you change the formal parameter, change is visible in actual parameter also.
Regards,
Bhaskar
09-15-2008 2:26 PM
Call by value : Passes a value ( No effect on the variable )
You can change the values of the subroutine and once it comes out the value will be the actual value.
A = 5.
write a.
Perform cal using A.
Form cal.
a = 6.
write a .
end form.
write a.
output : 5,6,5 .
Call by reference : Passes an address ( effect on the variable )
A = 5.
write a.
Perform cal changing A.
Form cal.
a = 6.
write a .
end form.
write a.
output : 5,6,6.