IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Redefine a field in cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
saubhik

New User


Joined: 21 Sep 2007
Posts: 35
Location: kolkata

PostPosted: Wed Apr 23, 2008 10:48 am
Reply with quote

Can I redefine an X(200) field with a field of X(100) ?..plz explain with some example.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Apr 23, 2008 10:54 am
Reply with quote

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
View user's profile Send private message
shafeeqspi

New User


Joined: 01 Apr 2008
Posts: 4
Location: Mysore

PostPosted: Wed Apr 23, 2008 12:08 pm
Reply with quote

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
View user's profile Send private message
saubhik

New User


Joined: 21 Sep 2007
Posts: 35
Location: kolkata

PostPosted: Wed Apr 23, 2008 12:37 pm
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Wed Apr 23, 2008 12:52 pm
Reply with quote

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
View user's profile Send private message
vasanthkumarhb

Active User


Joined: 06 Sep 2007
Posts: 275
Location: Bang,iflex

PostPosted: Wed Apr 23, 2008 12:56 pm
Reply with quote

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

Code:

VAR1      22
VAR2      2

that is the difference. do it with simple examples.
Back to top
View user's profile Send private message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 206
Location: Globe, India

PostPosted: Wed Jan 19, 2011 6:13 pm
Reply with quote

thanks vasanth for explaining this very neatly... icon_smile.gif
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu Jan 20, 2011 3:23 pm
Reply with quote

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
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Thu Jan 20, 2011 8:30 pm
Reply with quote

@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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 20, 2011 8:42 pm
Reply with quote

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

Our customers normally use FLAG(I,I) to see all messages.

Bill
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Jan 21, 2011 3:02 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top