convert data from zoned decimal to packed decimal
-
- New Member
- Posts: 9
- Joined: Wed Feb 24, 2016 11:30 am
convert data from zoned decimal to packed decimal
Hi ,
Is it possible to convert data from zoned decimal like zzz,zzz,zz9.999 to packed decimal value or can we do able to total the value in this format?
Is it possible to convert data from zoned decimal like zzz,zzz,zz9.999 to packed decimal value or can we do able to total the value in this format?
Re: convert data from zoned decimal to packed decimal
Hello.
COBOL won't let you do arithmetic on a field formatted like that, but it will let you move it somewhere else. For example, this will work:
As long as your formatted field actually contains something that is in the format specified, it should be possible to move it back to a packed decimal field then add it to your total.
COBOL won't let you do arithmetic on a field formatted like that, but it will let you move it somewhere else. For example, this will work:
Code: Select all
01 WA-DECIMAL PIC S9(7) COMP-3 VALUE 100.
01 WA-FORMATTED PIC -ZZZ,ZZ9.
01 WA-BACK-TO-DECIMAL PIC S9(7) COMP-3.
.
.
.
MOVE WA-DECIMAL TO WA-FORMATTED
MOVE WA-FORMATTED TO WA-BACK-TO-DECIMAL
Re: convert data from zoned decimal to packed decimal
Yes, it’s possible! You can use a similar approach to what Zum mentioned. Move the zoned decimal value to a formatted field, then into a packed decimal field for calculations. Just ensure the format matches exactly when moving back and forth to avoid data truncation or errors.
-
- New Member
- Posts: 9
- Joined: Wed Feb 24, 2016 11:30 am
Re: convert data from zoned decimal to packed decimal
Thank you zum13 and florry372. What if the formats don't match? The move is not allowed?
Re: convert data from zoned decimal to packed decimal
If the formats don't match then the results can become unpredictable. This could be an abend as a result of, say, the sign being unacceptable, or the data being magnitudes out (e.g. 100 winds up as 100,000). It only becomes a concern if your data input is not consistent. The other alternative is to use something like the NUMVAL-C function instead: https://www.ibm.com/docs/en/cobol-zos/6 ... c-numval-f
-
- New Member
- Posts: 9
- Joined: Wed Feb 24, 2016 11:30 am
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute