View previous topic :: View next topic
|
Author |
Message |
pokhande
New User
Joined: 14 Apr 2010 Posts: 4 Location: Pune
|
|
|
|
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 |
|
|
gylbharat
Active Member
Joined: 31 Jul 2009 Posts: 565 Location: Bangalore
|
|
|
|
You can run and check this.... Right?? |
|
Back to top |
|
|
pokhande
New User
Joined: 14 Apr 2010 Posts: 4 Location: Pune
|
|
|
|
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 |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Download Z390, you can test it on your PC. |
|
Back to top |
|
|
rakesh1155
New User
Joined: 21 Jan 2009 Posts: 84 Location: India
|
|
|
|
What makes you think the value would be something other than 'ABC' ? |
|
Back to top |
|
|
pokhande
New User
Joined: 14 Apr 2010 Posts: 4 Location: Pune
|
|
|
|
How can a numeric data item have value as 'ABC' ? |
|
Back to top |
|
|
nigelosberry
New User
Joined: 06 Jan 2009 Posts: 88 Location: Ggn, IN
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
rakesh1155
New User
Joined: 21 Jan 2009 Posts: 84 Location: India
|
|
|
|
Very Nice Explanation Bill Woodger!!
Though I am NOT the original poster looking for the answer, But it definitely helps. |
|
Back to top |
|
|
pokhande
New User
Joined: 14 Apr 2010 Posts: 4 Location: Pune
|
|
|
|
Thanks Bill.. It is of great help to me |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|