View previous topic :: View next topic
|
Author |
Message |
kshirabdhi
New User
Joined: 22 Nov 2007 Posts: 13 Location: Noida
|
|
|
|
I have the following varibles in the working storage.
01 WS-A PIC X(30) VALUE 'ABCDEFGHIJKLMNOPQRESTUVWXYZ ' .
01 WS-B REDEFINES WS-A.
10 WS-B1 PIC X(10).
10 WS-B2 PIC 9(10).
10 WS-B3 PIC X(10).
If I display B1, B2 and B3 respectively, what is the value displayed in B2? Will it throw any error as WS-B2 is a numeric field? |
|
Back to top |
|
|
Bharath Bhat
Active User
Joined: 20 Mar 2008 Posts: 283 Location: chennai
|
|
|
|
Quote: |
What is the output of this code? |
I don't know.... You tell us.
It would be a very simple test and you'll see the results in seconds.... |
|
Back to top |
|
|
kshirabdhi
New User
Joined: 22 Nov 2007 Posts: 13 Location: Noida
|
|
|
|
If I had mainframe connection, I would have seen the results in seconds and would not have posted it here.
I can not test as I have no resource |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
It will not through any error if you just display it. Numeric variable will get populated with character value (KLMNOPQRSH). |
|
Back to top |
|
|
kshirabdhi
New User
Joined: 22 Nov 2007 Posts: 13 Location: Noida
|
|
|
|
Thank you Sambhaji.
One more query ... If we move alphabets to numberic field, it throws error; but in this case wile displaying characters through a numeric field it works fine. How? |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
kshirabdhi, there is a link to manuals at the top of the page. Click on it, find the COBOL Language Reference and Programming Guide manuals, and read them -- cover to cover. You will learn much from doing this and be able to answer many questions on your own.
While you cannot move 'ABC' to a numeric DISPLAY variable, if you set up a PIC X variable and move 'ABC' to it, you can then move that variable to the numeric DISPLAY variable with no problems.
Quote: |
If we move alphabets to numberic field, it throws error |
No, it does not. JAVA throws errors, COBOL does not. COBOL abends but it does not "throw" things -- ever. Getting the terminology right is a repeated request by the moderators on this forum since if you cannot get the terminology right you cannot get the concepts right. And so far your terminology is not right. |
|
Back to top |
|
|
l.nethaji
New User
Joined: 16 Mar 2008 Posts: 90 Location: tamil nadu
|
|
|
|
The main use of redefines is like it can be used for avoiding SOC7 error.
Only when we do arithmatic operation i.e moving X(3) to 9(3) soc7 occurs.
But in redefines we just override it on the same memory location.
Thats y we wont face error in redefines.
Hope this helps |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
The main use of redefines is like it can be used for avoiding SOC7 error. |
not true.
main use of redefines is to have different definitions of same area.
Quote: |
Only when we do arithmatic operation i.e moving X(3) to 9(3) soc7 occurs. |
not true
1. a move is not an arithmetic operation.
2. you won't get a SOC7 because of receiving field. it is due to bad data in sending field.
actually, nothing you said helps, other than as a good example of a bad example. |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
l.nethaji wrote: |
Only when we do arithmatic operation i.e moving X(3) to 9(3) soc7 occurs. |
Not exactly correct.
According to the COBOL Language Reference Manual:
When the category of the sending item is alphanumeric, alphanumeric-edited, national, or national-edited, the data is moved as if the sending item were described as an unsigned integer."
So... Moving a field defined as PIC X(3) to one defined as PIC 9(3) won't result in a S0C7 if the value of the X(3) field is, for example, '123', or '987'. It will only result in a S0C7 if the value of the X(3) field does not qualify as a valid unsigned integer - e.g. 'XYZ'. |
|
Back to top |
|
|
l.nethaji
New User
Joined: 16 Mar 2008 Posts: 90 Location: tamil nadu
|
|
|
|
Hi,
Its true
" a good example of a bad example."
_________________
I learnt a lot from mine .
thanks |
|
Back to top |
|
|
|