Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
3.3 Working with COBOL packed decimal numbers COBOL programs store numbers internally in several different ways. One of these internal representations is called COBOL packed decimal numbers . It stores numbers in a calculation-friendly format and uses the minimum storage depending on how many digits are required to store the number for an application. Packed decimal numbers occupy one byte of storage for every two decimal digits, except that the rightmost byte contains only one digit and the sign. That is, it uses 4 bits to represent either a digit or sign. A variable of such type is declared in a COBOL program as follows: MYVAR1 PIC S999 USAGE COMP-3. MYVAR2 PIC 999 USAGE COMP-3. The first variable, MYVAR1, is a signed COBOL packed decimal number that uses 3 bytes to store numbers (that is, up to five digits of signed numbers). The second variable, MYVAR2, is an unsigned COBOL packed decimal number that uses 3 bytes to store numbers (that is, up to five digits of unsigned numbers). Unlike many other numerical representations of programming languages, including Java, it uses the last 4 bits to represent sign. Therefore the first variable is able to store values from -99999 to 99999, and the second variable is able to store values from 0 to 99999. When such values are read from a data set using the JRIO library, they are