2006 Dec 13 4:25 AM
hi,
Can anyone let me know the Difference between PASS by VALUE and PASS by REFERNCE Probabaly with and Example.
Thanks & Regards
Avi
2006 Dec 13 4:28 AM
hi
in pass by value only a copy of the parameter is passed so whtever change you have made in the FORM for that parameter does not reflect in the main program.
but in pass by reference you are passing the original parameter that means the memory of that parameter so whateverchanges you have made in the FORM it will reflect in the main program.
regards
shiba dutta
hi
in pass by value only a copy of the parameter is passed so whtever change you have made in the FORM for that parameter does not reflect in the main program.
but in pass by reference you are passing the original parameter that means the memory of that parameter so whateverchanges you have made in the FORM it will reflect in the main program.
regards
shiba dutta
2006 Dec 13 4:27 AM
Hi,
Pass by reference:
A way of passing data from actual parameters to formal parameters. When you pass by reference, no local data object is specified for the actual parameter, but the procedure receives a reference to the actual parameter during call and works with the actual parameter itself. A change to the formal parameter in the subroutine also changes the value of the actual parameter.
Pass by value:
a local object with the same data type as the corresponding actual parameter is created in the subroutine and filled with its values. A change to the formal parameter in the subroutine does not change the value of the actual parameter. The actual parameter also retains its original value even after the subroutine has ended.
Example to make you understand better.
REPORT ztest.
PARAMETER: test(2) TYPE c.
PERFORM change_test1 USING test.
WRITE:/ test.
PERFORM change_test2 USING test.
WRITE:/ test.
&----
*& Form change_test1
&----
Value of test will change here. Pass by REFERENCE
----
-->P_TEST text
----
FORM change_test1 USING p_test.
p_test = p_test + 2.
WRITE:/ p_test.
ENDFORM. "change_test1
&----
*& Form change_test2
&----
Value of test will change here but only in the subroutine. Pass by VALUE
----
-->VALUE(P_TEST) text
----
FORM change_test2 USING value(p_test).
p_test = p_test + 2.
WRITE:/ p_test.
ENDFORM. "change_test2
Also check this links.
http://help.sap.com/saphelp_47x200/helpdata/en/9f/db979d35c111d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_47x200/helpdata/en/9f/db979035c111d1829f0000e829fbfe/frameset.htm
Regards,
Ferry Lianto
2006 Dec 13 4:28 AM
hi
in pass by value only a copy of the parameter is passed so whtever change you have made in the FORM for that parameter does not reflect in the main program.
but in pass by reference you are passing the original parameter that means the memory of that parameter so whateverchanges you have made in the FORM it will reflect in the main program.
regards
shiba dutta
2006 Dec 13 4:32 AM
<b>Pass by value:</b>
In pass by vlaue you are passing the value of actual parameter to formal parameter. so changes made in formal parameters<b> will not reflect</b> in actual parameters.
1200 2340 Memory address
formal actual
parameter parameter
<b>formal and actual parameter will point different memory address
</b>
<b>Pass by refference:</b>
in pass by reference the memory address of acutal parameter is passed to formal parameter . due to this both formal parameter and actual parameter will point same memory address and hence changes made to the value of formal parameter <b>will reflect</b> in actual paramete also.
1200 1200 Memory address
formal actual
parameter parameter
<b>formal and actual parameter will point same memory address
</b>
i think this will help u.
2006 Dec 13 4:33 AM
2020 Nov 27 12:47 PM
Hi,
1. Pass by Reference:
Both Formal and actual parameters share same memory. Hence if formal parameter changes, actual parameter will also change.
Ex. PERFORM <PERFORM_NAME > USING <A>.
FORM <PERFORM_NAME> USING <F>.
……………………..
ENDFORM.
2. Pass by Value:
Both Formal and Actual Parameters shares different memory. Hence if Formal parameter changes, actual parameter will not change.
The key word VALUE () will identify that it is a pass by value else is a pass by reference.
Ex. PERFORM <PERFORM_NAME> USING VALUE <A>.
FORM <PERFORM_NAME> USING <F>.
………………
ENDFORM.
Regards,
Nasreen.
2020 Dec 04 12:29 PM
pass by reference - Both actual and formal parameters referring to same memory location, so if any changes made to formal parameter the actual parameter will also get affected
pass by reference - Both actual and formal parameters refers to separate memory location, so if any changes made to formal parameter the actual parameter will not get affected.
Regards
Udaya bhanu
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |