Page 1 of 1

What is the difference between zoned and packed decimal?

Posted: Mon Jun 16, 2014 1:57 pm
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?

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

Posted: Mon Jun 16, 2014 6:44 pm
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.

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

Posted: Tue Jun 17, 2014 12:41 pm
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?

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

Posted: Tue Jun 17, 2014 5:26 pm
by enrico-sorichetti
C and JAVA come from a different background(*), where ZONED/PACKED have no meaning

(*) were designed for different hardware architectures

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

Posted: Thu Jun 19, 2014 2:59 pm
by Shriram
Thanks enrico.