Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

subroitene

Former Member
0 Likes
576

hi ,

what is the diffence between call by value and call by reference,explaine me in brief.

thanks in advance.

hi ,

what is the diffence between call by value and call by reference,explaine me in brief.

thanks in advance.

4 REPLIES 4
Read only

Former Member
0 Likes
556

hi surendra

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.

Check the below link it clearly explains the concept

http://www.cs.princeton.edu/~lworthin/126/precepts/pass_val_ref.html

<u><i><b>example with code</b></i></u>

If you pass by value..Inside the subroutine if you change the value it will not have effect (means it will not change the value) in the calling place..

If you pass by reference...Inside the subroutine if you change the value it will change in the calling place..Means it will share the same memory..

EX.

data: v_char.

PERFORM FORM1 using v_char.

write: / 'Reference',v_char.

PERFORM FORM2 USING v_char.

write: / 'By value',v_char.

FORM FORM1 USING v_char.

v_char = 'A'.

ENDFORM.

FORM FORM2 USING value(v_char).

v_char = 'B'.

ENDFORM.

regards

navjot

reward if helpfull

Message was edited by:

navjot sharma

Read only

Former Member
0 Likes
556

Hi,

Call by reference:

When you pass a parameter by reference, new memory is not allocated for the value. Instead, a pointer to the original memory location is passed. All references to the parameter are references to the original memory location.

Call by value:

When you pass a parameter by value, new memory is allocated for the value. This memory is allocated when the subroutine is called and is freed when the subroutine returns.

Call by value and result:

Pass by value and result is very similar to pass by value. Like pass by value, a new memory area is allocated and it holds an independent copy of the variable. It is freed when the subroutine ends, and that is also when the difference occurs.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
556

Hi,

<b>Call by value</b> : If u change the values of formal parameters in the subroutine it won't affect the values of the actual parameters.

<b>Call by reference</b> : If u change the values of formal parameters in the subroutine it will affect the values of the actual parameters.

This difference u can see in Debug mode.

Regards,

Balavardhan.K

Read only

Former Member
0 Likes
556

Hi,

<b>CALL BY VALUE:</b>

HERE THE MAIN PROGRAM VALUES ARE NOT AFFECTED (GLOBLE VARIABLES). ONLY LOCAL VARIABLE VALUES ARE EFFECTED.

<b>CALL BY REFERENCE:</b>

BY DEFAULT ALL THE INTERNAL TABLES ARE CALL BY REFERENCE.

HERE GLOBLE VARIABLE VALUES ARE ALSO EFFECTED(IN MAIN PROGRAM).

Regards

Sudheer