View previous topic :: View next topic
|
Author |
Message |
ruodeer
New User
Joined: 06 Jul 2007 Posts: 58 Location: home
|
|
|
|
Hi everybody here,
I am confused about the usage of BASED, please consider the following code:
Code: |
DCL 1 DERIVED_AREA BASED(ADDR(DERIVED_STMT)) CHAR(4300); |
I know DERIVED_AREA and DERIVED_STMT use the same memeroy area,
but could some friends here tell me :
Now that there is DERIVED_STMT as variable to proceed,why there is DERIVED_AREA ,what is DERIVED_AREA used for?
could someone here give me a sample to explain the usage of BASED?
Many thanks... |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
Hi,
Consider a file read example.
A file can contain different record types. Based on certain indicator in the record, you will decide what record type it is.
DCL DERIVED_STMT CHAR(4300);
DCL 1 REC1 BASED(ADDR(DERIVED_STMT)),
record layout here.
DCL 1 REC2 BASED(ADDR(DERIVED_STMT)),
record layout here.
etc.
You will always read the file into DERIVED_STMT. But based on some particular field you will decide to which record type it belongs to and accordingly you will try to access the contents of the record.
Hope it helps. |
|
Back to top |
|
|
ruodeer
New User
Joined: 06 Jul 2007 Posts: 58 Location: home
|
|
|
|
Hi ,Srihari.
thanks for your reply. |
|
Back to top |
|
|
donateeye Warnings : 2 New User
Joined: 01 Jun 2007 Posts: 62 Location: chennai
|
|
|
|
Let me help you in a simpler way.
if I say :
DCL X
DCL A BASED B
here the B should be a pointer variable and should be assigned a value like : B = ADDR(X)
now A shares the same storage of X, no matter A and X are same or different base and scales... B is a pointer which relates both....
Just like using DEFINE, but the difference is that, when you use DEFINE, you can relate two variables only if they are of same base and scale. |
|
Back to top |
|
|
|