View previous topic :: View next topic
|
Author |
Message |
Bharti P Manglani
New User
Joined: 13 Mar 2007 Posts: 16 Location: Pune
|
|
|
|
In the example below:
05 WS-VAR1 PIC X(5)
05 WS-VAR2 REDEFINES WA-VAR1 PIC 9(5)
In the PROCEDURE DIVISION MOVE 'ABCDE' TO WS-VAR1.What will be the value of WS-VAR1 and WS-VAR2 ? |
|
Back to top |
|
|
balakrishna reddy
Active User
Joined: 13 Jul 2007 Posts: 128 Location: Guntur
|
|
|
|
hi Bharti,
even though you give alphanumeric value to numeric variable which is a redefined variable,since it is sharing the same memory both will give the same output.
ws-var1 will have 'ABCDE'
ws-var2 will have 'ABCDE'
even though you declare that alphanumeric as alphabetic the result will be the same as above i said.
need any clarification feel free to ask |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
balakrishna reddy,
Code: |
MOVE 'ABCDE' TO WS-VAR1
|
that is an alpha literal being moved to an x-type (alphanumeric) field.
WS-VAR2 is defined as numeric. |
|
Back to top |
|
|
balakrishna reddy
Active User
Joined: 13 Jul 2007 Posts: 128 Location: Guntur
|
|
|
|
hi dbz,
In redefined clause the same memory is being accessed by two different variables irrespective of the type declaration, even though you move alphanumeric value to first variable,
when you print the second variable it points to the same memory area where we have moved previously the alphanumeric value.
in short we can say like its a type of saving memory. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Both variables occupy the same bytes of storage.
If the numeric definition is used and the content is not a valid numeric, an error will be raised. The most common is a s0c7. |
|
Back to top |
|
|
Bharti P Manglani
New User
Joined: 13 Mar 2007 Posts: 16 Location: Pune
|
|
|
|
dick scherrer wrote: |
Hello,
Both variables occupy the same bytes of storage.
If the numeric definition is used and the content is not a valid numeric, an error will be raised. The most common is a s0c7. |
But as the same memory space is occupied, will it lead to a S0C7 even in this case?
Thanks Balakrishna for your response, I think as same memory space is occupied both variables displayed will show ABCDE. |
|
Back to top |
|
|
balakrishna reddy
Active User
Joined: 13 Jul 2007 Posts: 128 Location: Guntur
|
|
|
|
Hi bharti,
Quote: |
But as the same memory space is occupied, will it lead to a S0C7 even in this case?
|
until and unless you use non valid numeric value in any arithmetic or logical operations you will not get soc7 abend.
we are on the safer side up to moves. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Bharti P Manglani wrote: |
Thanks Balakrishna for your response, I think as same memory space is occupied both variables displayed will show ABCDE. |
Did you try displaying numeric variable? it should show 12345 as far as know. (havent checked it so not sure) Contents will be 'C1C2C3C4C5'X in that memory space.
There will be no S0C7 in this case even if add operation is done on the number. Give it a try. |
|
Back to top |
|
|
balakrishna reddy
Active User
Joined: 13 Jul 2007 Posts: 128 Location: Guntur
|
|
|
|
hi agkshirsagar,
Quote: |
Did you try displaying numeric variable? it should show 12345 as far as know
|
i have tried it and when i displayed those two variables output is :
Code: |
ABCDE -------for alphanumeric variable
ABCDE -------for numeric variable.
|
|
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Bala,
I had answered a similar question before. After you add any value to 'ABCDE' for instance
Add 1 to ws-var2 you will get 12346. (In last post I clearly missed that )
See below thread for reference.
http://www.ibmmainframes.com/viewtopic.php?t=19789 |
|
Back to top |
|
|
balakrishna reddy
Active User
Joined: 13 Jul 2007 Posts: 128 Location: Guntur
|
|
|
|
hi agkshirsagar,
i have gone through that topic you have referenced,
i have tried it and same output is coming which you have said.
thanks agkshirsagar i have learned a new thing |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Now that you have learned this - i strongly recommend that you do not use it.
Instead of the letters A-I and J-R (+/- 1-9), try S-Z. The result will not be so friendly. |
|
Back to top |
|
|
|