Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Move s9 to s9 usage comp

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sprikitik

New User


Joined: 29 Jan 2007
Posts: 59
Location: Makati City, Philippines

PostPosted: Sat Aug 20, 2011 11:01 pm    Post subject: Move s9 to s9 usage comp
Reply with quote

HEllo,

WS-TMP-YY-MM PIC S9(06).
WS-TMP-XX-XX PIC S9(04) USAGE COMP.


How do i move WS-TMP-YY-MM to WS-TMP-XX-XX correctly?

Im my program, if WS-TMP-YY-MM is +201103, when moved to WS-TMP-XX-XX, the value of WS-TMP-XX-XX is +4495.

thanks
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Sat Aug 20, 2011 11:08 pm    Post subject:
Reply with quote

How do you expect to move 6 digits to 4 digits??
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Sat Aug 20, 2011 11:25 pm    Post subject: Reply to: Move s9 to s9 usage comp
Reply with quote

Indeed, make the COMP field bigger.

You have defined it to hold four digits (maximum value 9999*). You are trying to move six digits to it. It is not going to work.

*You have TRUNC(BIN) as your compiler option. This will utilise all the bits irrespective of the PICTURE (the PICTURE determines the size of the storage, in this case a "half-word", then you have access to all the bits in the half-word, giving you, for a signed field, values in the range +32767 to -32768.

You then move 201103 to this field. This will cause truncation. 201103 in hex is 3118F. Drop the three (a half-word is two bytes, four hex digits). That gives you 118F. 118F in decimal is 4495.

Edit: I said "I suspect you have TRUNC(BIN). Pointless, since I know you have it.
Back to top
View user's profile Send private message
sprikitik

New User


Joined: 29 Jan 2007
Posts: 59
Location: Makati City, Philippines

PostPosted: Sat Aug 20, 2011 11:40 pm    Post subject: Re: Reply to: Move s9 to s9 usage comp
Reply with quote

Bill Woodger wrote:
Indeed, make the COMP field bigger.

You have defined it to hold four digits (maximum value 9999*). You are trying to move six digits to it. It is not going to work.

*I suspect you have TRUNC(BIN) as your compiler option. This will utilise all the bits irrespective of the PICTURE (the PICTURE determines the size of the storage, in this case a "half-word", then you have access to all the bits in the half-word, giving you, for a signed field, values in the range +32767 to -32768.

You then move 201103 to this field. This will cause truncation. 201103 in hex is 3118F. Drop the three (a half-word is two bytes, four hex digits). That gives you 118F. 118F in decimal is 4495.



Thanks for the explanation!
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Sun Aug 21, 2011 1:14 am    Post subject:
Reply with quote

No problem.

If you have a chance, compare it with the truncation without TRUNC(BIN).
You'll get a different answer. Scratch here XXXX to see what it is.

Your receiving field should always be at least as big (in digits) as your sending field, unless you deliberately want truncation.

Get used to the hex representation of binary values. Something you'll need for dump-solving, if nothing else.

If you want to see the hex without a dump, redefine your binary field

Code:
01  W-A-BINARY-VALUE-TWO-BYTES COMP PIC S9( 1-4 ) (one to four digits, will occupy the same space)
01  W-DISPLAY-CONTENTS-OF-TWO-BYTE-BINARY
       REDEFINES W-A-BINARY-VALUE-TWO-BYTES PIC XX.

01  W-A-BINARY-VALUE-FOUR-BYTES COMP PIC S9( 5-9 )
01  W-DISPLAY-CONTENTS-OF-FOUR-BYTE-BINARY
       REDEFINES W-A-BINARY-VALUE-FOUR-BYTES PIC X(4).

DISPLAY ">" W-DISPLAY-CONTENTS-OF-TWO-BYTE-BINARY "<"
DISPLAY ">" W-DISPLAY-CONTENTS-OF-FOUR-BYTE-BINARY "<"


Then, when looking at the output, put HEX on. You'll see the hex value in your binary field.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts RMM Cannot move a volume from SHELF l... tspr52 IBM Tools 0 Thu Mar 01, 2018 3:48 pm
No new posts COMP Variables Mismatch gayu7 COBOL Programming 5 Wed Dec 20, 2017 5:06 pm
No new posts Moving a COMP-3 Variable to a Numeric... ajayachander COBOL Programming 2 Thu Dec 14, 2017 5:46 pm
No new posts CONDITIONAL USING COMP-2 WITH PROBLEMS. JOSUEGENTIL COBOL Programming 7 Wed Nov 08, 2017 11:13 pm
No new posts how can i move s9(9) to s9(9) usage comp HARENDRA CHOUDHARY COBOL Programming 3 Mon Nov 06, 2017 12:10 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us