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 clause for a numeric to alphanumeric data item

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Redefine clause for a numeric to alphanumeric data item
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    Post subject:
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    Post subject: Reply to: Redefine clause for a numeric to alphanumeric data
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue May 24, 2011 2:47 pm    Post subject:
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    Post subject:
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    Post subject: Reply to: Redefine clause for a numeric to alphanumeric data
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    Post subject: Re: Redefine clause for a numeric to alphanumeric data item
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Tue May 24, 2011 3:15 pm    Post subject: Reply to: Redefine clause for a numeric to alphanumeric data
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: 7905
Location: Bellevue, IA

PostPosted: Tue May 24, 2011 4:02 pm    Post subject:
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    Post subject:
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    Post subject: Reply to: Redefine clause for a numeric to alphanumeric data
Reply with quote

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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Tue May 24, 2011 4:26 pm    Post subject: Reply to: Redefine clause for a numeric to alphanumeric data
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    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 ODPP(Optim Data privacy Provider) Iss... Rama kishore IBM Tools 1 Mon Nov 07, 2016 5:46 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm
No new posts output data in CSV Format janmejay COBOL Programming 8 Sat Oct 15, 2016 2:20 pm
This topic is locked: you cannot edit posts or make replies. output data in CSV Format janmejay DFSORT/ICETOOL 3 Sat Oct 15, 2016 2:16 pm


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