View previous topic :: View next topic
|
Author |
Message |
saubhik
New User
Joined: 21 Sep 2007 Posts: 35 Location: kolkata
|
|
|
|
Can I redefine an X(200) field with a field of X(100) ?..plz explain with some example. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello Saubhik and welcome to the forums,
Quote: |
Can I redefine an X(200) field with a field of X(100) ?.. |
Yes, just the way you asked the question. . .
Code: |
01 THE-200-BYTES PIC X(200).
01 THE-100-BYTES REDEFINES THE-200-BYTES PIC X(100). |
A good habit to get into is to try this sort of thing on your own and post a question when you do not understand what happened. Usually, that will be much faster than asking and waiting for a response. |
|
Back to top |
|
|
shafeeqspi
New User
Joined: 01 Apr 2008 Posts: 4 Location: Mysore
|
|
|
|
Yes, we can do like that. Dick has explained it very well..
It just uses the same memory area..
It takes the first 100 bytes only, not bothering of the remaining 100...
Regards,
Shaffu |
|
Back to top |
|
|
saubhik
New User
Joined: 21 Sep 2007 Posts: 35 Location: kolkata
|
|
|
|
my questions was that whether we can redefine a 100 byte variable in to a 200 byte variable.
like let me know whether the below code is correct or Not -
01 THE-100-BYTES PIC X(100).
01 THE-200-BYTES REDEFINES THE-100-BYTES PIC X(200). |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
saubhik wrote: |
my questions was that whether we can redefine a 100 byte variable in to a 200 byte variable.
like let me know whether the below code is correct or Not - |
Buzz, wrong,,,,That was not your original question....
Quote: |
01 THE-100-BYTES PIC X(100).
01 THE-200-BYTES REDEFINES THE-100-BYTES PIC X(200). |
It depends, most current compilers will allow this, maybe with a warning..... |
|
Back to top |
|
|
vasanthkumarhb
Active User
Joined: 06 Sep 2007 Posts: 275 Location: Bang,iflex
|
|
|
|
Hi,
What Dick trying to explain is also same!!!!!
saubhik wrote: |
my questions was that whether we can redefine a 100 byte variable in to a 200 byte variable.
like let me know whether the below code is correct or Not -
01 THE-100-BYTES PIC X(100).
01 THE-200-BYTES REDEFINES THE-100-BYTES PIC X(200). |
Why can't you read the answer properly!!!!!!!!!
in your post you are redeffinig PIC X(100) with a new variable of size PIC X(200), that is fine.
only thing you have to understand is both the variables start with the same memory means same place but the size can be changed in redefines in anyway either u can increase or decrease or else u can change the picture clause too,
the theme of REDEFINES is both the variables shares the same memory and start at the same position, also u can divde the REDEFINED variable in to elementary itms.
for example
Code: |
WORKING-STORAGE SECTION
01 VAR1 PIC X (02).
01 var2 REDEFINES var1 PIC X(01).
.............
..........
.........
PROCEDURE DIVISION.
MOVE '22' TO VAR1.
DISPLAY 'VAR1', VAR1.
DISPLAY 'VAR2', VAR2.
.....................
.....................
.....................
......................
STOP RUN |
OUTPUT
that is the difference. do it with simple examples. |
|
Back to top |
|
|
rohanthengal
Active User
Joined: 19 Mar 2009 Posts: 206 Location: Globe, India
|
|
|
|
thanks vasanth for explaining this very neatly... |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
vasanthkumarhb wrote: |
....snip...
only thing you have to understand is both the variables start with the same memory means same place but the size can be changed in redefines in anyway either u can increase or decrease or else u can change the picture clause too,
the theme of REDEFINES is both the variables shares the same memory and start at the same position, also u can divde the REDEFINED variable in to elementary itms.
|
It is bad programming practice to redefine a smaller storage area with a larger definition. You will definitely get warnings from the compiler if you try to do that. |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
@Kjeld, I totally agree! And, IMO, IBM made the situation worse by demoting this situation to a Warning when it used to be an Error.
We used to rely on this error to tell us when an IO area ran out of space.
Code: |
05 WS-IOAREA PIC X(500).
05 FILLER REDEFINES WS-IOAREA.
10 WS-FIELD-1 PIC X(40).
10 WS-FIELD-2 . . . e t c. . .
|
We would add fields to the FILLER area until the compiler complained; then we would know that it was time to increase the size of WS-IOAREA (which would probably affect the LRECL of the associated file).
Now all you get is a Warning, which is easy to overlook. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Don is more than correct.
Some shops specify compile option FLAG(E) which then only displays errors of an 'E' level and greater.
Dangerous, especially when 'W' messages can be related to (for example) ADDRESSABILITY ERRORS (or lack thereof) in LINKAGE.
Our customers normally use FLAG(I,I) to see all messages.
Bill |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
I checked our default options for the Endevor Cobol processor. It sets FLAG(I,I).
But in my Cobol editor, the syntax checker was set to 'E'. I have changed that to 'W' immediately. And now it flags redefines extending beyond the redefinded storage area, as it should. |
|
Back to top |
|
|
|