$PACK and field specifiers

These formats are used in defining fields, in $FORMAT, in the FLD elements of a DEFRECORD and as hex codes, directly in $PACK and $UNPACK.

Recommended formats for use in DEFRECORD fields

Format$PACK codeLegacyPurpose
BID KDB BLOB ID
BID6 KDB BLOB ID 6 byte version
BID8 KDB BLOB ID 8 byte version
BLOBSYM The SYM of a bound database BLOB
BLOBSYM6 The SYM of a bound database BLOB, 6 BYTE version
BLOBSYM8 The SYM of a bound database BLOB, 8 BYTE version
BOOL Numeric boolean with "1" for TRUE and "0" for FALSE
BOOL_FALSE Numeric boolean that is always FALSE. Othewise identical to BOOLEAN
BOOL_SPACE As Boolean but a space is treated as FALSE rather than error
CHAR( Character field (presumed to be UTF-8 encoded)
CURRENCY( Currency. For now, identical to NUM.
DATE F603Julian date
FP PACK_NUMERIC_VALUEInternal representation of a KCML number. Use this for SYM values.
HEX( Binary field
INT( Cd0yInteger (signed)
LANG( Multi-language string field
NUM( Numeric (signed)
TEXT( Multiline text field
TIME F703Time in seconds since midnight
TIMESTAMP Time stamp in milliseconds since 0000-00-00T00:00:00.000Z held in 6 bytes. Replaces TS6.
UINT( Bd0yInteger (unsigned)
UNUM( Numeric (unsigned)

Packing formats for numeric fields

Format$PACK codeLegacyPurpose
B Bd0yYUnsigned binary format
B+ Cd0yYSigned binary format
BLOBSYM The SYM of a bound database BLOB
BLOBSYM6 The SYM of a bound database BLOB, 6 BYTE version
BLOBSYM8 The SYM of a bound database BLOB, 8 BYTE version
BOOL Numeric boolean with "1" for TRUE and "0" for FALSE
BOOL_FALSE Numeric boolean that is always FALSE. Othewise identical to BOOLEAN
BOOL_SPACE As Boolean but a space is treated as FALSE rather than error
BR Dd0yByte swapped (little-endian) unsigned binary format
BR+ Ed0yByte swapped (little-endian) signed binary format
CURRENCY( Currency. For now, identical to NUM.
D 3dxxIBM display format
DATE F603Julian date
F 10xxASCII free format
FP PACK_NUMERIC_VALUEInternal representation of a KCML number. Use this for SYM values.
I 2dxxLegacy ASCII integer format
INT( Cd0yInteger (signed)
INTERNAL internal ptr
M8 F008BASIC-2 internal BCD format
MD3 FD03Three byte packed date of the form YYMMDD
MD4 FD04Four byte packed date of the form CCYYMMDD
METHOD vtable entry
MI4 F304IEEE floating point L-H little-endian format
MI8 F308IEEE floating point L-H little-endian format
MJ F603YJulian date (replaced by DATE)
MM4 F204IEEE floating point H-L big-endian format
MM8 F208IEEE floating point H-L big-endian format
MT F703YTime in seconds since midnight (replaced by TIME)
MW8 F008YBASIC-2 internal BCD format
NUM( Numeric (signed)
O+ 7d0yPacked decimal format with binary overflow
OBJECT_PTR OBJECT represented as a pool handle
P 6dxxUnsigned packed decimal format
P+ 5d0yIBM packed decimal format
POOL A pool allocating handle
SY8 PACK_NUMERIC_VALUEYInternal representation of a KCML number (replaced by FP)
TIME F703Time in seconds since midnight
TS4 Time stamp in seconds since 1970-01-01T0000Z held in 4 bytes
U 4dxxIBM USASCII-8 format
UINT( Bd0yInteger (unsigned)
UNUM( Numeric (unsigned)
VTABLE vtable entry
Vs Packed decimal format with binary overflow supporting size > 6 bytes
Vu Packed unsigned decimal format with binary overflow supporting size > 6 bytes
W 8d0yWang signed packed decimal format as in PACK
WE 9d0yWang signed packed decimal format with even number of digits
X Informix money format

Where:
d = number of implied decimal places
xx = field width in binary (xx > 0)
y = field width in binary (0 < y < +6)

Packing formats for string fields

Format$PACK codeLegacyPurpose
BID KDB BLOB ID
BID6 KDB BLOB ID 6 byte version
BID8 KDB BLOB ID 8 byte version
CHAR( Character field (presumed to be UTF-8 encoded)
HEX( Binary field
INIT_TYPED_PTR Record string represented as a pool handle allocated in initialisation
LANG( Multi-language string field
MB FA01YLegacy boolean with "Y" for TRUE and "N" for FALSE
PTR String represented as a pool handle
TEXT( Multiline text field
TIMESTAMP Time stamp in milliseconds since 0000-00-00T00:00:00.000Z held in 6 bytes. Replaces TS6.
TS6 YTime stamp in milliseconds since 0000-00-00T00:00:00.000Z held in 6 bytes. Replaced by TIMESTAMP.
TYPED_PTR Record string represented as a pool handle

Where:
d = number of implied decimal places
xx = field width in binary (xx > 0)
y = field width in binary (0 < y < +6)

Extended string $PACK(E) formats

These are not available for fields.

Format$PACK codeLegacyPurpose
int_tEquivalent to C type signed int
uint_tEquivalent to C type unsigned int
int8_tEquivalent to C type signed char
uint8_tEquivalent to C type unsigned char
int16_tEquivalent to C type signed short
uint16_tEquivalent to C type unsigned short
int32_tEquivalent to C type int
uint32_tEquivalent to C type unsigned
int64_tEquivalent to C type int64
uint64_tEquivalent to C type uint64
ptr_tEquivalent to C type PTRWORD
BASE64 BASE64 encoding
BID KDB BLOB ID
BID6 KDB BLOB ID 6 byte version
BID8 KDB BLOB ID 8 byte version
BITS( Count set bits in a string
BLOBSYM The SYM of a bound database BLOB
BLOBSYM6 The SYM of a bound database BLOB, 6 BYTE version
BLOBSYM8 The SYM of a bound database BLOB, 8 BYTE version
BOOL Numeric boolean with "1" for TRUE and "0" for FALSE
BOOL_FALSE Numeric boolean that is always FALSE. Othewise identical to BOOLEAN
BOOL_SPACE As Boolean but a space is treated as FALSE rather than error
CHAR( Character field (presumed to be UTF-8 encoded)
CURRENCY( Currency. For now, identical to NUM.
HEX( Binary field
INIT_TYPED_PTR Record string represented as a pool handle allocated in initialisation
INTERNAL internal ptr
LANG( Multi-language string field
META METAPHONE phoneme encoding
METHOD vtable entry
NUM( Numeric (signed)
OBJECT_PTR OBJECT represented as a pool handle
POOL A pool allocating handle
PTR String represented as a pool handle
SNDX SOUNDEX encoding
TEXT( Multiline text field
TIMESTAMP Time stamp in milliseconds since 0000-00-00T00:00:00.000Z held in 6 bytes. Replaces TS6.
TS4 Time stamp in seconds since 1970-01-01T0000Z held in 4 bytes
TS6 YTime stamp in milliseconds since 0000-00-00T00:00:00.000Z held in 6 bytes. Replaced by TIMESTAMP.
TYPED_PTR Record string represented as a pool handle
UNUM( Numeric (unsigned)
URL URL encoding
UTF-16 UTF-16, UCS-2 or Unicode encoding
UTF-16+ UTF-16, UCS-2 or Unicode encoding, with XML encoding
UTF-16BE UTF-16, UCS-2 or Unicode encoding, big-endian
UTF-16BE+ UTF-16, UCS-2 or Unicode encoding, big-endian, with XML encoding
UTF-16LE UTF-16, UCS-2 or Unicode encoding, little-endian
UTF-16LE+ UTF-16, UCS-2 or Unicode encoding, little-endian, with XML encoding
UTF-32 UTF-32 or UCS-4 encoding
UTF-32+ UTF-32 or UCS-4 encoding with XML encoding
UTF-32BE UTF-32 or UCS-4 encoding, big-endian
UTF-32BE+ UTF-32 or UCS-4 encoding, big-endian, with XML encoding
UTF-32LE UTF-32 or UCS-4 encoding, little-endian
UTF-32LE+ UTF-32 or UCS-4 encoding, little-endian, with XML encoding
UTF-8 UTF-8 encoding
UTF-8+ UTF-8 and XML encoding
VTABLE vtable entry
Vs Packed decimal format with binary overflow supporting size > 6 bytes
Vu Packed unsigned decimal format with binary overflow supporting size > 6 bytes
X Informix money format
XML XML entity encoding format

$PACK(F) formats

Format$PACK codeLegacyPurpose
A A000YAlphanumeric format
A( A000YAlphanumeric multi-language format
B Bd0yYUnsigned binary format
B+ Cd0yYSigned binary format
BR Dd0yByte swapped (little-endian) unsigned binary format
BR+ Ed0yByte swapped (little-endian) signed binary format
C A100Compressed alphanumeric format
D 3dxxIBM display format
DATE F603Julian date
F 10xxASCII free format
FP PACK_NUMERIC_VALUEInternal representation of a KCML number. Use this for SYM values.
I 2dxxLegacy ASCII integer format
INT( Cd0yInteger (signed)
M8 F008BASIC-2 internal BCD format
MB FA01YLegacy boolean with "Y" for TRUE and "N" for FALSE
MD3 FD03Three byte packed date of the form YYMMDD
MD4 FD04Four byte packed date of the form CCYYMMDD
MI4 F304IEEE floating point L-H little-endian format
MI8 F308IEEE floating point L-H little-endian format
MJ F603YJulian date (replaced by DATE)
MM4 F204IEEE floating point H-L big-endian format
MM8 F208IEEE floating point H-L big-endian format
MT F703YTime in seconds since midnight (replaced by TIME)
MW8 F008YBASIC-2 internal BCD format
O+ 7d0yPacked decimal format with binary overflow
P 6dxxUnsigned packed decimal format
P+ 5d0yIBM packed decimal format
SKIP 00xxSkip field
SY8 PACK_NUMERIC_VALUEYInternal representation of a KCML number (replaced by FP)
TIME F703Time in seconds since midnight
U 4dxxIBM USASCII-8 format
UINT( Bd0yInteger (unsigned)
W 8d0yWang signed packed decimal format as in PACK
WE 9d0yWang signed packed decimal format with even number of digits

Where:
d = number of implied decimal places
xx = field width in binary (xx > 0)
y = field width in binary (0 < y < +6)

$PACK(F) pack codes

$PACK specformatDeprecatedPurpose
00xxSKIP Skip field
10xxF ASCII free format
2dxxI Legacy ASCII integer format
3dxxD IBM display format
4dxxU IBM USASCII-8 format
5d0yP+ IBM packed decimal format
6dxxP Unsigned packed decimal format
7d0yO+ Packed decimal format with binary overflow
8d0yW Wang signed packed decimal format as in PACK
9d0yWE Wang signed packed decimal format with even number of digits
A000A YAlphanumeric format
A000A( YAlphanumeric multi-language format
A100C Compressed alphanumeric format
Bd0yB YUnsigned binary format
Bd0yUINT( Integer (unsigned)
Cd0yB+ YSigned binary format
Cd0yINT( Integer (signed)
Dd0yBR Byte swapped (little-endian) unsigned binary format
Ed0yBR+ Byte swapped (little-endian) signed binary format
F008M8 BASIC-2 internal BCD format
F008MW8 YBASIC-2 internal BCD format
F108MN BASIC-2C internal format
F204MM4 IEEE floating point H-L big-endian format
F208MM8 IEEE floating point H-L big-endian format
F304MI4 IEEE floating point L-H little-endian format
F308MI8 IEEE floating point L-H little-endian format
F603MJ YJulian date (replaced by DATE)
F603DATE Julian date
F703MT YTime in seconds since midnight (replaced by TIME)
F703TIME Time in seconds since midnight
FA01MB YLegacy boolean with "Y" for TRUE and "N" for FALSE
FD03MD3 Three byte packed date of the form YYMMDD
FD04MD4 Four byte packed date of the form CCYYMMDD
PACK_NUMERIC_VALUESY8 YInternal representation of a KCML number (replaced by FP)
PACK_NUMERIC_VALUEFP Internal representation of a KCML number. Use this for SYM values.