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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

moving COMP value to numeric value

Status
Not open for further replies.

shaily123

Programmer
Feb 5, 2005
17
0
0
US
Hi, I am doing

01 val1 pic 99v99999 comp.
01 val2 pic 9(7).
01 val3 pic 9(7).

Move val1 to val2.
divide val2 by 100 giving val3.

Question:

When i do this i an not getting right values.

Value for val1 is 0.324
value of val2 i am getting is 03452345 it is garbage...

please help what happen when we move comp values.
 
And what about replacing this:
Move val1 to val2
with this ?
ADD ZERO TO val1 GIVING val2

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
If [tt]val1[/tt] really contains 0.324 before this sequence of instructions then after
Code:
Move val1 to val2
val2 should contain zero. The move should truncate the fractional part.

Is this still VAX/VMS COBOL?

Tom Morrison
 
Might try compute instead of move.

If val1 really contains 0.324 before this sequence of instructions then after

val1 might contain 00.32400 but not 0.324

Are you rounding it on the display or what?

How do you know what the packed number contains? How are you determining it?
When unpacking, I would move 99v99999 comp 3 to
99v99999 dicimal and then dislplay that to see what it is.

You can do mathematical operations on the comp-3 field if the resulting field is set up right. The resulting field determines the rounding and the truncation.
Compute val3 = (val1 * 100) Try that.

If you do not like my post feel free to point out your opinion or my errors.
 
NO! How can "val1" contain 0,324 when it is defined as a whole number? k5tm is right, the casus does not make sence.
 
I believe we are all confused.

01 val1 pic 99v99999 comp.
01 val2 pic 9(7).
01 val3 pic 9(7).

Move val1 to val2.
divide val2 by 100 giving val3.

val1 is defined as 7 digits binary with an assumed decimal point. Value "0000324" would be considered 00.00324. First question! What 7 digits are stored in val1?????

Next, when you move val1 to val2, assuming no rounding is specified you will truncate the last 5 digits of your number. Is that really what you want to do??

Give specific examples:

What is the 7 digits inputed.
What is the desired resulting number.
Can you display val2 after you move val1 into it. What is there?

etom
 
01 val1 pic 99v99999 comp

This definition has precision to the 5th decimal place. Val1 is not a whole number. The "v" indicates a percieved logical decimal location. The data may actually be all numbers with no decimal but it is probably packed or binary. There are other types of comp data, but I have never used them. They are all dependent on how the compiler implements their storage.

It is comp of some kind. comp has different types of ways of storing the in my computer, IBM MAINFRAME, comp is binary and comp3 is packed decimal. comp is sumtimes used as a general term.

I took assembly and I think all numbers are whole numbers when they are packed the "V" is telling the compiler how to handle the number. Packing is an old method for handling numbers that takes up less space. Space use to cost more so they did not mind executing 5 commands to get at one number.

If you do not like my post feel free to point out your opinion or my errors.
 
please help what happen when we move comp values.

The result is aligned on the decimal point.

(val1 contains a virtual decimal point after the 1st 2 digits)
:. val1 --> val2 should result in val2=0000000
The decimal places are truncated (chopped off) of course,
because val2 has no decimal places. It is a whole number.

Try defining a new field
Code:
01  val1-display               PIC 99.99999.

Very Important!
I am presuming that you have remembered to initialize
the val1 by coding :-

Code:
MOVE 0.324 TO VAL1.

So now, add
Code:
MOVE VAL1 TO VAL1-DISPLAY.
DISPLAY 'VAL1-DISPLAY=>' VAL1-DISPLAY.

Let us know how you go.
If it still doesn't work, cut/paste your entire program into a response so we can all see exactly what you have actually written.



 
Shaily123 has not been on since 16 Feb, and I think we need some clarification before we can continue.

Shaily???????
 
Isn't the simple solution to make val2 pic 99v99999and then val3 and the divide become unnecessary - obviously this is just a guess as the end requirement is not clear.

brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top