Previous Topic: Zoned and Packed Decimal Fields as IDMS KeysNext Topic: Signed Versus Unsigned Keys


Numeric Formats

To understand the various ramifications of using zoned or packed decimal fields as IDMS key fields, it is necessary to have an understanding of the internal structure of the various formats.

Zoned decimal fields use one byte of storage to represent each single digit within a value. The high-order nibble of the last byte is used to convey the sign of the number when the field is defined as 'signed'. When a value is moved into an unsigned field, the sign nibble always contains a hexadecimal 'F'. A field that is signed uses a 'C' for a positive value and a 'D' for a negative number. It should be noted that a signed field also interprets an 'F' as a positive sign and a 'B' to represent a negative number. The high-order nibbles of all other bytes will contain a hex 'F' and are ignored for determining the sign of the number. The values of +999 and -999 will have the following internal structures when zoned decimal format is used.

Signed:       PIC S9(4)     +999  =  x'F0F9F9C9'
                                  -999  =  x'F0F9F9D9'

Unsigned:  PIC  9(4)        +999  =  x'F0F9F9F9'
                                  -999  =  x'F0F9F9F9'

Packed decimal format uses a single nibble for each digit of the number and maintains the sign in the low-order nibble of the field's last byte. Unsigned fields always use an 'F' for the sign while signed fields use a 'C' for positive numbers and a 'D' for negative numbers. Signed fields interpret an 'F' as a positive sign and a 'B' as a negative sign. The following internal structures will result for values of +999 and -999 when packed decimal format is used.

Signed:       S9(5) COMP-3        +999  =  x'00999C'
                                           -999  =  x'00999D'

Unsigned:      9(5) COMP-3        +999  =  x'00999F'
                                           -999  =   x'00999F'

It is important to realize that the various sign nibble values are assigned in a language such as COBOL when a value is moved directly into a named field. Fields that are part of group moves will not have any conversion performed relative to the value in their sign nibble.

02   GROUP-A.
  04    FIELD-A        PIC  S9(5) COMP-3.
 
02   GROUP-B.
  04    FIELD-B        PIC    9(5) COMP-3.

A value of -999 will be moved into FIELD-A and FIELD-B with the following instructions resulting in the hex value to the right of the instruction.

  MOVE -999 TO FIELD-A.               FIELD-A = x'00999D'
  MOVE -999 TO FIELD-B.               FIELD-B = x'00999F'

Although functionally equivalent the following instructions will result in a different value to be moved into FIELD-B.

  MOVE -999 TO FIELD-A                FIELD-A = x'00999D'
  MOVE GROUP-A to GROUP-B.        FIELD-B = x'00999D'

Although the above example used packed decimal numbers, the same scenario is true for zone decimal fields. This programming difference may have an impact on your IDMS database depending on the type of key in which a field is used and whether a field's definition is signed or unsigned.