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

What's the result of alphabetic when redefined as numeric


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

New User


Joined: 13 Jun 2005
Posts: 24

PostPosted: Tue Nov 15, 2005 12:27 am
Reply with quote

05 WS-VAR1 PIC X(5)

05 WS-VAR2 REDEFINES WA-VAR1 PIC 9(5).

PROCEDURE DIVISION

MOVE 'ABCDE' TO WS-VAR1.

now what is the value of WS-VAR1 and WS-VAR2 ?
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Nov 15, 2005 6:45 am
Reply with quote

ABCDE
Back to top
View user's profile Send private message
shammiullah

New User


Joined: 13 Jun 2005
Posts: 24

PostPosted: Tue Nov 15, 2005 10:59 pm
Reply with quote

hi,
do u mean to say that both variables will display ABCDE.being a variable declared as 9(5),how a varB can display ABCDE as varA. .
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Nov 16, 2005 6:52 am
Reply with quote

Hi,

No. I was answering the ques:
Quote:
now what is the value of WS-VAR1 and WS-VAR2 ?


DISPLAY will convert some numeric variables, so you can't determine what its value is.

But if you put the vaiable(s) in a data rec then use ispf edit to view it, you'll see "ABCDE".
Back to top
View user's profile Send private message
Hames

New User


Joined: 03 Oct 2005
Posts: 49

PostPosted: Mon Nov 21, 2005 12:45 pm
Reply with quote

Hi shammiullah,

MOVE statement will move the value from one variable to another irrespective of the data type.

So that is why if display the numeric value also it displays ABCDE.

But if you compare the value or do any numeric computation on that variable then it will give error.
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 677
Location: NJ

PostPosted: Mon Nov 21, 2005 3:51 pm
Reply with quote

hi frnd,
In the above case it wont give any error instead it will give the garbage value in WS-VAR2. As per hames once any computation is attempted then u will receive error.
Back to top
View user's profile Send private message
mijanurit
Currently Banned

New User


Joined: 26 Aug 2005
Posts: 33
Location: bangalore

PostPosted: Sun Nov 27, 2005 7:22 pm
Reply with quote

hi summy,

when we use "redefine"?
when we don't use two variable at same time. u initialized WS-VAR1(i.e alphanumeric), if u display it will show "ABCDE". but WS-VAR2 will contain garbage value. if u display WS-VAR2 it will show some garbage value.

try it in lab.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Nov 27, 2005 11:31 pm
Reply with quote

Hi Guys,

That "garbage value" you talk about is still "ABCD" in memory. The so called "garbage" is created by the DISPLAY verb when it attempts to display the contents of WS-VAR2 as it was defined.

I'm not so sure WS-VAR2 will display as "garbage" in this case. Has anybody actually tried to DISPLAY WS-VAR2 containing "ABCDE"?

And remember, there's a difference between a variable "containing" a value and that same variable DISPLAYing as a value. For e.g.:

var-x pix s9(001) comp-3 value 4 will CONTAIN X'4C'. It will DISPLAY D. That's because the code generated by the DISPLAY verb unpacks the field before diplaying it. The unpack changes the X'4C' to an X'C4', which DISPLAYs as a "D".
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 first column truncated in search result IBM Tools 13
No new posts SDSF like solution in EJES (store com... All Other Mainframe Topics 4
No new posts Convert HEX to Numeric DB2 3
No new posts executing XCTL command in COBOL witho... CICS 10
No new posts Find a record count/numeric is multip... COBOL Programming 1
Search our Forums:

Back to Top