convert data from zoned decimal to packed decimal

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Trupti Pawar
New Member
Posts: 9
Joined: Wed Feb 24, 2016 11:30 am
India

convert data from zoned decimal to packed decimal

Post 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?
User avatar
zum13
Active Member
Posts: 127
Joined: Thu May 04, 2023 12:58 am

Re: convert data from zoned decimal to packed decimal

Post 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.
User avatar
florry372
New Member
Posts: 7
Joined: Wed Jun 12, 2024 8:36 pm
United States of America

Re: convert data from zoned decimal to packed decimal

Post 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.
Trupti Pawar
New Member
Posts: 9
Joined: Wed Feb 24, 2016 11:30 am
India

Re: convert data from zoned decimal to packed decimal

Post by Trupti Pawar »

Thank you zum13 and florry372. What if the formats don't match? The move is not allowed?
User avatar
zum13
Active Member
Posts: 127
Joined: Thu May 04, 2023 12:58 am

Re: convert data from zoned decimal to packed decimal

Post 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
Trupti Pawar
New Member
Posts: 9
Joined: Wed Feb 24, 2016 11:30 am
India

Re: convert data from zoned decimal to packed decimal

Post by Trupti Pawar »

Thank you zum13. This is really helpful.

 
Post Reply

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

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”