Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COMP-3 TO NORMAL THEN BACK COMP-3 1

Status
Not open for further replies.

claudeb

Programmer
Nov 23, 2000
140
CA
HI,
I have a a variable WS-ONE that is a pic S9(07) comp-3 that can't be changed but would like to insert zeros in the first 2 positions.
i declared a variable WS-TWO.
05 WS-TWO.
10 WS-TWO-ZEROS pic 9(02).
10 WS-TWO-REST pic 9(05).
Moved zeros to WS-TWO-ZEROS.
then moved WS-TWO to WS-ONE.
it is not working. what's wrong ?
thanks for the help.
 
ClaudeB,

if you're moving WS-ONE to WS-TWO, i can imagine why it goes wrong. WS-TWO is a group field and therefore implicitly PIC X. What you want is a numeric move to a zoned numeric field: that way, the numeric value of WS-ONE is correctly converted.
Try something like this:

05 WS-TWO pic 9(07).
05 WS-TWO-RD REDEFINES WS-TWO.
10 WS-TWO-ZEROS pic 9(02).
10 WS-TWO-REST pic 9(05).

Now, move your WS-ONE to WS-TWO, move zeroes to WS-TWO-ZEROS and move WS-TWO back to WS-ONE. Hey presto !

Good luck !
 
ClaudeB,

looking back, this question was horribly similar to one you've just posted a little while ago. I don't want to hassle you, but it seems you don't fully understand the concept of how the memory is used to store values in COMP-3 fields. You might wanna look in on this; it'll help you understand why your earlier attempt went wrong, and prevent you from falling into the same traps again.

Good luck !
 
Hi,
You could also code this as:
ws-5 pic s9(5)
move ws-one to ws-5
move ws-5 to ws-one
 
ClaudeB,

Probably the easiest way would be to multiple WS-ONE by 100 which will cause high order truncation, then divide by 100 which will shift back to the right. This works and is very easy.


RobertM
Brainbench MVP for COBOL II
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top