Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Redefine a field in cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Redefine a field in cobol
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

Site Director


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

PostPosted: Wed Apr 23, 2008 10:54 am    Post subject:
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    Post subject: Can I redefine an X(200) field with a field of X(100) ?..
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    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Wed Apr 23, 2008 12:52 pm    Post subject:
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: 276
Location: Bang,iflex

PostPosted: Wed Apr 23, 2008 12:56 pm    Post subject:
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: 179
Location: Globe, India

PostPosted: Wed Jan 19, 2011 6:13 pm    Post subject: perfect example
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    Post subject:
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: 647
Location: Whitby, ON, Canada

PostPosted: Thu Jan 20, 2011 8:30 pm    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 20, 2011 8:42 pm    Post subject: Reply to: Redefine in cobol.
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORT VSAM file with each field one by... maxsubrat DFSORT/ICETOOL 6 Tue Mar 14, 2017 1:07 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts outrec field outside range Danielle.Filteau SYNCSORT 10 Sat Mar 04, 2017 2:37 am
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Execute TSO ACF commands from COBOL-I... supreethi.srid TSO/ISPF 0 Tue Feb 21, 2017 5:19 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us