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: 2434
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: 7315

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: 8088
Location: East Dubuque, Illinois, USA

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: 7315

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 SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 am
No new posts Validate if a Value from the file is ... balacsv2 COBOL Programming 8 Mon Jun 19, 2017 11:52 pm
No new posts Easytrive Redefine vidyaa CA Products 4 Mon Jun 19, 2017 6:01 pm
No new posts NDM syntax checking without actually ... GAPX1 All Other Mainframe Topics 0 Wed Jun 07, 2017 2:36 am
No new posts Redefine SYS1.PROCLIB farhad_evan JCL & VSAM 12 Mon May 22, 2017 10:54 pm


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