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

Redefines Clause not giving expected result


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

New User


Joined: 21 Nov 2006
Posts: 48
Location: mumbai

PostPosted: Thu Aug 23, 2007 6:30 pm
Reply with quote

Code:
IDENTIFICATION DIVISION.             
PROGRAM-ID. PGM.                     
DATA DIVISION.                       
WORKING-STORAGE SECTION.             
01  WS-RECORD.                       
    05 A   PIC X(5) VALUE ALL SPACES.
    05 B REDEFINES A                 
           PIC 9(5).                 
01  C  PIC 9(5) VALUE ALL ZEROS.     
                                     
PROCEDURE DIVISION.                 
    MOVE '231'  TO A.               
    DISPLAY 'A : ', A.               
    DISPLAY 'B : ', B.               
    STOP RUN.                       


Now when i execute this code
Code:

A : 231 
B : 231 

This means a and B both contains '231 '
Since B is PIC 9(5), it should show 00231

I am not getting why this is happening.

What should i do to get 00231?


Sudhakar.
Back to top
View user's profile Send private message
dr_te_z

New User


Joined: 08 Jun 2007
Posts: 71
Location: Zoetermeer, the Netherlands

PostPosted: Thu Aug 23, 2007 6:44 pm
Reply with quote

move 231 to B.
Back to top
View user's profile Send private message
sudhakar_lendave

New User


Joined: 21 Nov 2006
Posts: 48
Location: mumbai

PostPosted: Thu Aug 23, 2007 6:49 pm
Reply with quote

thanks dr_te_z,
but the thing is my variable A gets populated whenever i read a file.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Aug 23, 2007 6:58 pm
Reply with quote

Why should B display 00231?
Back to top
View user's profile Send private message
sudhakar_lendave

New User


Joined: 21 Nov 2006
Posts: 48
Location: mumbai

PostPosted: Thu Aug 23, 2007 7:03 pm
Reply with quote

Sorry steve i wasn't specific.

Actually whenever i read a file, A gets the data in it.

Now i wanted this A should be compared with C which is numeric.

So i think, redefining A with B will give me B as a numeric.
and now i can compare B and C.

But it's not working.
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 23, 2007 7:09 pm
Reply with quote

all you have when you redefine an alpha field as numeric is a numeric field that has been populated with alpha data.

you need to extract the numeric value (COBOL intrinsic function NUMVAL) from the alpha field, storing the results in a numeric field, then make your compare.
Back to top
View user's profile Send private message
sudhakar_lendave

New User


Joined: 21 Nov 2006
Posts: 48
Location: mumbai

PostPosted: Thu Aug 23, 2007 7:21 pm
Reply with quote

Thanks Dick.. it's working now.

________________
Sudhakar.
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 To search DB2 table based on Conditio... DB2 1
No new posts SDSF like solution in EJES (store com... All Other Mainframe Topics 4
No new posts executing XCTL command in COBOL witho... CICS 10
No new posts CSQBGET - Call giving completion code... COBOL Programming 3
Search our Forums:

Back to Top