IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Regarding Redefines clause


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Bharti P Manglani

New User


Joined: 13 Mar 2007
Posts: 16
Location: Pune

PostPosted: Thu Aug 02, 2007 6:51 pm
Reply with quote

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
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Thu Aug 02, 2007 7:06 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Aug 02, 2007 7:15 pm
Reply with quote

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
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Thu Aug 02, 2007 7:38 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Aug 03, 2007 12:22 am
Reply with quote

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
View user's profile Send private message
Bharti P Manglani

New User


Joined: 13 Mar 2007
Posts: 16
Location: Pune

PostPosted: Fri Aug 03, 2007 11:36 am
Reply with quote

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
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Fri Aug 03, 2007 1:02 pm
Reply with quote

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
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Fri Aug 03, 2007 1:13 pm
Reply with quote

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
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Fri Aug 03, 2007 2:49 pm
Reply with quote

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
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Fri Aug 03, 2007 3:45 pm
Reply with quote

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 icon_redface.gif )
See below thread for reference.
http://www.ibmmainframes.com/viewtopic.php?t=19789
Back to top
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Fri Aug 03, 2007 6:29 pm
Reply with quote

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 icon_biggrin.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Aug 03, 2007 7:06 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts To search DB2 table based on Conditio... DB2 1
No new posts NOT IN clause in COBOL pgm COBOL Programming 8
No new posts SUSBSCRIPT WITH SIGN IN PIC CLAUSE COBOL Programming 3
No new posts usage of CASE in WHERE clause DB2 10
No new posts Cobol redefines for Signed pictured c... COBOL Programming 4
Search our Forums:

Back to Top