MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

moving 9(10) to s9(9) comp

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
srikanth.bh
Beginner


Joined: 23 Jul 2004
Posts: 8
Topics: 4

PostPosted: Wed Aug 11, 2004 2:37 pm    Post subject: moving 9(10) to s9(9) comp Reply with quote

Hi all,
I am trying to move a variable of pic 9(10) to s9(9) comp. getting some junk values in output however i try. please suggest how to accomplish this.

thanks,
kanth
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Wed Aug 11, 2004 3:16 pm    Post subject: Reply with quote

Srikanth,

You need to tell us what you meant by junk value. The following program shows the move of 9(10) to s9(09) comp.

Code:

CBL TRUNC(BIN)                             
IDENTIFICATION DIVISION.                   
PROGRAM-ID.    SAMPLE                     
ENVIRONMENT DIVISION.                     
DATA DIVISION.                             
                                           
WORKING-STORAGE SECTION.                   
                                           
01 W-NUM   PIC 9(10).                     
01 W-COMP  PIC S9(9) COMP.                 
                                           
PROCEDURE DIVISION.                       
                                           
    MOVE 1234567890 TO W-NUM               
    MOVE W-NUM      TO W-COMP             
    DISPLAY 'NUM  VALUE IS : ' W-NUM       
    DISPLAY 'COMP VALUE IS : ' W-COMP     
    GOBACK.                               


The output from this job is :

Code:

NUM  VALUE IS : 1234567890
COMP VALUE IS : 1234567890


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
srikanth.bh
Beginner


Joined: 23 Jul 2004
Posts: 8
Topics: 4

PostPosted: Thu Aug 12, 2004 12:24 am    Post subject: Reply with quote

Kolusu, thanks for the response. Initially when i tried this direct move i got strange output.

01 A PIC 9(10) VALUE 3420009659
01 B PIC S9(9) COMP.

MOVE A TO B.

OUTPUT:
A = 3420009659
B = -874957637

i'm failing to understand how B had such a value.
Back to top
View user's profile Send private message
srikanth.bh
Beginner


Joined: 23 Jul 2004
Posts: 8
Topics: 4

PostPosted: Thu Aug 12, 2004 3:25 am    Post subject: Reply with quote

Actually, the MOVE statement in inside a loop. so i think each time the move is made the values are getting computed with the old value in comp. when i tried initializing the comp filed before each move i could get the result correctly.

sorry for taking your time, thanks.
Back to top
View user's profile Send private message
Mike Chantrey
Intermediate


Joined: 10 Sep 2003
Posts: 234
Topics: 1
Location: Wansford

PostPosted: Thu Aug 12, 2004 10:25 am    Post subject: Reply with quote

The maximum positive value you can store in an S9(9) COMP field is 2^31 which is 2147483648, i.e. the value you are trying to move is too big. So it wraps around into the negative range. Negative values are stored in 'twos complement' fashion so if you convert the value in B to its unsigned equivalent you will see that the unsigned value is actually correct, i.e. 2^32 - 874957637 = 3420009659

As far as I can see this explains you result rather than your loops...
Back to top
View user's profile Send private message
srikanth.bh
Beginner


Joined: 23 Jul 2004
Posts: 8
Topics: 4

PostPosted: Thu Aug 12, 2004 12:44 pm    Post subject: Reply with quote

that makes more sense mike. thanks for clarifying.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group