What is the difference between zoned and packed decimal?

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Shriram
Registered Member
Posts: 21
Joined: Fri Aug 16, 2013 3:13 pm

What is the difference between zoned and packed decimal?

Post by Shriram »

Hi,

What is the difference between zoned and packed decimal in terms of COBOL usage. I don't seetheir usage in langiages like C, C++ etc. so are they just limited to Cobol?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: What is the difference between zoned and packed decimal?

Post by Robert Sample »

A z/OS system uses 8-bit bytes. A zoned decimal value allocates the first four bits to a zone (X'C' for positive, X'D' for negative, X'F' for unsigned) and the last four bits to the value. A zoned decimal value will have the positive / negative zone ONLY in the last byte of the value. Hence a zoned decimal value of X'F1F2F3D4' is -1234. A packed decimal value uses the first four bits of each byte to hold a numeric digit, and the last four bits to hold another digit. The sign is indicated by the last four bits of the last byte. So -1234 In packed decimal is X'01234D'.

Their use is typically oriented to the mainframe with its 8-bit bytes. PL/1, Assembler, and COBOL all support zoned decimal and packed decimal variables.
Shriram
Registered Member
Posts: 21
Joined: Fri Aug 16, 2013 3:13 pm

Re: What is the difference between zoned and packed decimal?

Post by Shriram »

Thanks Robert. I also get intrigued by the fact that COBOL being one of the early languages then it should have influenced other languages. So, how come there are no direct equivalents of these variables in any other language apart from what you've mentioned and they all are on mainframes. I think there is no one-to-one mapping of some variable from character-set of C, JAVA etc. to the zone or packed decimal of COBOL?
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 826
Joined: Wed Sep 11, 2013 3:57 pm

Re: What is the difference between zoned and packed decimal?

Post by enrico-sorichetti »

C and JAVA come from a different background(*), where ZONED/PACKED have no meaning

(*) were designed for different hardware architectures
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
Shriram
Registered Member
Posts: 21
Joined: Fri Aug 16, 2013 3:13 pm

Re: What is the difference between zoned and packed decimal?

Post by Shriram »

Thanks enrico.
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.”