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

Redefine clause for a numeric to alphanumeric data item


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

New User


Joined: 14 Apr 2010
Posts: 4
Location: Pune

PostPosted: Tue May 24, 2011 2:30 pm
Reply with quote

01 A
05 B PIC X(3) value 'ABC'.
05 C redefines B PIC 9(3).

If I DISPLAY C,what would be the output?
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Tue May 24, 2011 2:35 pm
Reply with quote

You can run and check this.... Right??
Back to top
View user's profile Send private message
pokhande

New User


Joined: 14 Apr 2010
Posts: 4
Location: Pune

PostPosted: Tue May 24, 2011 2:43 pm
Reply with quote

At present I dont have access to Mainframe system.. Can you please let me know what would be the result of it
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Tue May 24, 2011 2:47 pm
Reply with quote

Download Z390, you can test it on your PC.
Back to top
View user's profile Send private message
rakesh1155

New User


Joined: 21 Jan 2009
Posts: 84
Location: India

PostPosted: Tue May 24, 2011 2:54 pm
Reply with quote

What makes you think the value would be something other than 'ABC' ?
Back to top
View user's profile Send private message
pokhande

New User


Joined: 14 Apr 2010
Posts: 4
Location: Pune

PostPosted: Tue May 24, 2011 2:55 pm
Reply with quote

How can a numeric data item have value as 'ABC' ?
Back to top
View user's profile Send private message
nigelosberry

New User


Joined: 06 Jan 2009
Posts: 88
Location: Ggn, IN

PostPosted: Tue May 24, 2011 3:03 pm
Reply with quote

pokhande wrote:
01 A
05 B PIC X(3) value 'ABC'.
05 C redefines B PIC 9(3).

If I DISPLAY C,what would be the output?



Yes, the best way as someone suggested is to test it yourself.
Anyways, here's a little hint.

Try to look at the ebcdic code(hex content) of 'ABC'. You may see a series of bytes that form a valid number.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue May 24, 2011 3:15 pm
Reply with quote

It depends.

There is no problem with any or all bytes of a numeric field simply containing any of the possible 256 values of an 8-bit byte. Problems can come when you start to use the data.

"ABC" looks like this in "hex": C1C2C3
"123" looks like this in "hex": F1F2F3

The leftmost "F"s are called Zones, and the rightmost "F" is the sign. When using for calculation, the Zones get thrown away (so can actually be anything) but the sign must be valid. Valid signs are mostly C (positive) D (negative) and F (unsigned).

So, "ABC", if you try to use it like a number, will "work". Ie it will not S0C7, and you'll have rubbish infiltrating your fine clean data. Which is why you have to validate every external source of numeric items.

What specifically do you see when you DISPLAY it? Either "ABC" or "AB3" depending on the setting of the compiler option NUMPROC would be my guess, though I'm unable to try it myself.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue May 24, 2011 4:02 pm
Reply with quote

Quote:
How can a numeric data item have value as 'ABC' ?
Because you are making one of the fundamental errors people new to COBOL make. Just because a variable is DEFINED as numeric does not mean it will always have numbers in it. A USAGE DISPLAY variable such as you have defined can have numbers, yes, but it is not required too -- it is perfectly valid to do the redefine as in the first post.
Back to top
View user's profile Send private message
rakesh1155

New User


Joined: 21 Jan 2009
Posts: 84
Location: India

PostPosted: Tue May 24, 2011 4:14 pm
Reply with quote

Very Nice Explanation Bill Woodger!!

Though I am NOT the original poster looking for the answer, But it definitely helps.
Back to top
View user's profile Send private message
pokhande

New User


Joined: 14 Apr 2010
Posts: 4
Location: Pune

PostPosted: Tue May 24, 2011 4:16 pm
Reply with quote

Thanks Bill.. It is of great help to me
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue May 24, 2011 4:26 pm
Reply with quote

rakesh1155 and pokhande,

Glad it helps.

As Robert is indicating, there is no problem with the redefines. There will be occasions where you have a file where sometimes a field on the file contains non-numeric data (text, for instance) and sometimes it contains numeric data. There will be something on the file which tells you which to use at the time. Just don't use them at the wrong field at the wrong time. This was a common way of "saving space" in file layouts. Maybe happens less these days, but you'll probably come across it. Just don't mix them up! I even think one of the examples in the Cobol manual is of this type, check it out.
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 Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Store the data for fixed length COBOL Programming 1
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top