View previous topic :: View next topic
|
Author |
Message |
Mr.Niceguy
New User
Joined: 16 Jun 2005 Posts: 63
|
|
|
|
Hi all,
Can anybody explain "pass by reference and content"?
Thanks alot |
|
Back to top |
|
|
shell100
New User
Joined: 14 Apr 2006 Posts: 25 Location: Banglore,India
|
|
|
|
Hi,
In Pass by reference called program can modify the passed parameter & these changes will be reflected in calling program as well.
But in Pass by value , changes would not get reflect in calling program. Mainly used to pass read only parameter. |
|
Back to top |
|
|
ursprasanna Warnings : 2 New User
Joined: 15 May 2006 Posts: 20 Location: chennai
|
|
|
|
Hi,
Call by reference ---- here the address of the variable is passed from the called program to the calling program . to make it more clear ...if A, B , C are the values that are to be passed to the called program from the calling program . and consider that these variables are in the memory location 001A ,001B,001C respectively . in call by reference the the address are passed to the sub program . the sub -program also uses the same memory location on the main program . so the changes made in the sub program will be reflected in the main progarm .
call by content ---- here a copy of the data variables( A, B , C) is made and this is stored in a separte memory location and let this memeory location be ( 002A , 002B,002c) and the original memory location will be (001A,001B,001c) . Here ( call by content) the address of the copy of the variables willbe passes ie) ( 002A,002B,002C) .. so the values that are changed in the called program will not be reflected back in the main program. |
|
Back to top |
|
|
Mr.Niceguy
New User
Joined: 16 Jun 2005 Posts: 63
|
|
|
|
Hi,
Thanks Alot, Bust still need some more explanation for Call by content..
Just little bit confused.. can any body help me??
Bye |
|
Back to top |
|
|
gskulkarni
New User
Joined: 01 Mar 2006 Posts: 70
|
|
|
|
A simple way to understand this is,
Program A has a variable WS-MESSAGE-HEADER defined in its working storage. The memory address of this variable at run time is "001A".
Program A calls Program B
Program A wants to send some data to Program B to use. This is included in using clause of CALL statement
e.g.
Code: |
CALL 'program_name'
USING
WS-MESSAGE-HEADER |
Now, Program B has to refer the data passed in the variable WS-MESSAGE-HEADER.
There are two ways it can do it.
1) One way is to refer to memory address of that variable i.e. "001A" and pick up the content of the variable from there. In this case, if Program B makes any changes in the content, it will be at the same memory location. and so when Program B finishes after changing content of WS-MESSAGE-HEADER, those changes will be available to Program A. This is called, call by VALUE, which is default when not specified in CALL statement.
2) The other way is to avoid passing memory address of the working storage variable WS-MESSAGE-AREA. Instead, copy the content at memory address "001A" to a different memory address, say "00CA" and pass that memory address to Program B. This way, even if Program B changes the received data, when control goes back to Program A, the WS-MESSAGE-HEADER will contain the same data as it had before calling Program B.
sigh!!
This is what precisely was explained in ursprasanna's post. I have tried it in my way.
But more often than not you end up saying same things when answers are this simple. |
|
Back to top |
|
|
|