Application Development 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: 

D/B call by value and call referens

Former Member
0 Kudos

HI,

can any one help me in finding D/B call by value and call by referens and call by value and return in <b>perform</b> statement .

Regards,

Mahendra.

4 REPLIES 4

Former Member
0 Kudos

<b>call by reference</b>

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.

<b>call by value</b>

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.

<b>call by value and result</b>

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..

Former Member
0 Kudos

Hi Mahendra,

Check this matter. This may be helpful to you.

There are three ways of passing parameters to a subroutine:

• Pass by reference

• Pass by value

• Pass by value and result

Table 1:

Addition Method

using v1 Pass by reference

changing v1 Pass by reference

using value(v1) Pass by value

changing value(v1) Pass by value and result

Table 2 :

Method Description Advantages

By reference Passes a pointer to the original memory location. Very efficient

By value Allocates a new memory location for use within the subroutine. The memory is freed when the subroutine ends. Prevents changes to passed variable

<b>Passing Parameters by Reference</b>

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. Changes to the variable within the subroutine update the original memory location immediately.

<b>Passing Parameters by Value</b>

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. Therefore, references to the parameter are thus references to a unique memory area that is known only within the subroutine; the original memory location is separate. The original is unchanged if you change the value of the parameter.

Hope this will resolve your query.

Reward all the helpful answers.

Regards

Former Member
0 Kudos

examples(try this one)

<b>call by reference </b>

data f1 value 'A'.

perform s1 using f1.

write / f1.

form s1 using p1.

p1 = 'X'.

endform.

<b>call by reference</b>

data: f1 value 'A'.

perform s1 using f1.

write / f1.

form s1 using value(p1).

p1 = 'X'.

write / p1.

endform.

<b>call by value and result</b>

data: f1 value 'A'.

perform: s1 changing f1,

s2 changing f1.

end-of-selection.

write: / 'Stopped. f1 =', f1.

form s1 changing <b>value(p1).</b>

p1 = 'B'.

endform.

form s2 changing <b>value(p1</b>).

p1 = 'X'.

stop.

endform.

rewards if its help u

Vijay Pawar

former_member533584
Contributor
0 Kudos

call by value :when we pass parammeters using call by value the formal parameter created in diff address with attributes of actual parameter so change in formal parameter does not reflcts in actual parameter.

call by reference : when we pass parammeters using call by reference the formal parameter created in same address so every change in formal parameter reflcts in actual parameter.