Page 1 of 1
convert data from zoned decimal to packed decimal
Posted: Thu Dec 26, 2024 12:57 pm
by Trupti Pawar
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?
Re: convert data from zoned decimal to packed decimal
Posted: Thu Dec 26, 2024 9:20 pm
by zum13
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:
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
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.
Re: convert data from zoned decimal to packed decimal
Posted: Fri Dec 27, 2024 11:34 am
by florry372
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.
Re: convert data from zoned decimal to packed decimal
Posted: Thu Jan 02, 2025 12:58 pm
by Trupti Pawar
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
Posted: Thu Jan 02, 2025 9:45 pm
by zum13
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
Re: convert data from zoned decimal to packed decimal
Posted: Mon Jan 06, 2025 12:32 pm
by Trupti Pawar
Thank you zum13. This is really helpful.