Db2 decoding for numeric data in edit and validation routines

Db2 stores numeric data in a specially encoded Db2-coded format.

Begin program-specific programming interface information.
To retrieve numeric data in its original form, you must Db2-decode it according to its data type.
Table 1. Db2 decoding procedure according to data type
Data type Db2 decoding procedure Decoding examples
SMALLINT Invert the sign bit (high-order bit).
  • Stored value: 8001
  • Decoded value: 0001 (+1 decimal)
  • Stored value: 7FF3
  • Decoded value: FFF3 (-13 decimal)
INTEGER Invert the sign bit (high-order bit).
  • Stored value: 800001F2
  • Decoded value: 000001F2 (+498 decimal)
  • Stored value: 7FFFFF85
  • Decoded value: FFFFFF85 (-123 decimal)
FLOAT If the sign bit (high-order bit) is 1, invert only that bit. Otherwise, invert all bits.
  • Stored value: C110000000000000
  • Decoded value: 4110000000000000 (+1.0 decimal)
  • Stored value: 3EEFFFFFFFFFFFFF
  • Decoded value: C110000000000000 (-1.0 decimal)
DECIMAL Save the high-order hexadecimal digit (sign digit). Shift the number to the left one hexadecimal digit. If the sign digit is X'F', put X'C' in the low-order position. Otherwise, invert all bits in the number and put X'D' in the low-order position.
  • Stored value: F001
  • Decoded value: 001C (+1)
  • Stored value: 0FFE
  • Decoded value: 001D (-1)
BIGINT Invert the sign bit (high order bit).
  • Stored value: 8000000000000854
  • Decoded value: 0000000000000854 (2132 decimal)
  • Stored value: 7FFFFFFFFFFFFFE0
  • Decoded value: FFFFFFFFFFFFFFE0 (-32 decimal)
DECFLOAT See the information on sortable decimal formats in Db2 12 for z/OS licensed diagnosis information.
  • Stored value: D8F77D00000000000C
  • Decoded value: 222C000000001E80 (+7.500 decimal floating-point)
  • Stored value: 270882FFFFFFFFFFF2
  • Decoded value: A2300000000003D0 (-7.50 decimal floating-point)
End program-specific programming interface information.