Primitive types
Each EGL primitive type characterizes an area of memory. There are three kinds of primitive types: character, numeric and datetime.
- The character types are as follows:
- CHAR refers to single-byte characters.
- DBCHAR refers to double-byte characters. dbchar replaces DBCS, which was a primitive type in EGL V5.
- MBCHAR refers to multibyte characters, which are a combination of single-byte and double-byte characters. mbchar replaces MIX, which was a primitive type in EGL V5.
- UNICODE refers to double-byte characters that conform to the UTF-16 encoding standards developed by the Unicode Consortium.
- HEX refers to hexadecimal characters.
- The datetime types are as follows:
- DATE refers to a specific calendar date that has a fixed length of eight single-byte digits.
- INTERVAL refers to a span of time that has a length ranging from two to twenty-seven single-byte digits.
- TIME refers to an instance in time that has a fixed length of six single-byte digits.
- TIMESTAMP refers to the current time and has a length ranging from two to twenty single-byte digits.
- The numeric types are as follows:
- BIGINT refers to an 8-byte area that stores an integer of as many as 18 digits. This type is equivalent to type BIN, length 8, no decimal places.
- BIN refers to a binary number.
- DECIMAL refers to packed decimal characters whose sign is represented by a hexadecimal C (for a positive number) or a hexadecimal D (for a negative number) in the right half of the rightmost byte. DECIMAL replaces PACK, which was a primitive type in EGL version 5.0.
- FLOAT refers to an 8-byte area that stores a double-precision floating-point numbers with up to 16 significant digits.
- INT refers to a 4-byte area that stores an integer of as many as 9 digits. This type is equivalent to type BIN, length 4, no decimal places.
- MONEY refers to currency amounts, which are stored as DECIMAL values.
- NUM refers to numeric characters whose sign is represented by a sign-specific hexadecimal value in the left half of the rightmost byte. For ASCII, that value is 3 (for a positive number) and 7 (for negative); for EBCDIC, that value is F (for a positive number) and D (for negative).
- NUMC refers to numeric characters whose sign is represented by a sign-specific hexadecimal value in the left half of the rightmost byte. For ASCII, that value is 3 (for a positive number) and 7 (for negative); for EBCDIC, that value is F (for a positive number) and C (for negative).
- PACF refers to packed decimal characters whose sign is represented by a hexadecimal F (for a positive number) or a hexadecimal D (for a negative number) in the right half of the rightmost byte.
- SMALLFLOAT refers to a 4-byte area that stores a single-precision floating-point number with up to 8 significant digits.
- SMALLINT refers to an 2-byte area that stores an integer of as many as 4 digits. This type is equivalent to type BIN, length 2, no decimal places.
The internal representation of an item of any of the fixed-point numeric types is the same as an integer representation, even when you specify a decimal point. The representation of 12.34 is the same as that of 1234, for example. Similarly, currency symbols are not stored with items of type MONEY.
When you interact with DB2 (directly or by way of JDBC) , the maximum number of digits in a fixed-point number is 31 at most.
At declaration time, you specify the primitive type that characterizes each of these values:
- The value returned by a function
- The value in an item, which is an area of memory that is referenced by name and contains a single value
Other entities also have a primitive type:
- A system item has a primitive type (usually NUM) that is specific to the item
- A character literal is of one of these types:
- CHAR if the literal includes only single-byte characters
- DBCHAR if the literal includes only double-byte characters from the double-byte character set
- MBCHAR if the literal includes a combination of single-byte and double-byte characters
- Character literals of type UNICODE are not supported.
Each primitive type is described on a separate page; and additional details are available on the pages that cover assignments, logical expressions, function invocations, and the call statement.
The sections that follow cover these subjects:
Primitive types at declaration time
Consider the following declarations:
DataItem myItem CHAR(4) end Record mySerialRecordPart type serialRecord { fileName="myFile" } 10 name CHAR(20); 10 address; 20 street01 CHAR(20); 20 street02 CHAR(20); endAs shown, specify a primitive type when you declare these entities:
- A data item
- A structure item that is not substructured
You may specify the primitive type of a substructured structure item like address. If you fail to specify the primitive type of such a structure item but you reference the structure item in your code, the product makes these assumptions:
- The primitive type is assumed to be CHAR, even if the subordinate structure items are of a different type
- The length is assumed to be the number of bytes in the subordinate structure items
Relative efficiency of different numeric types
EGL supports the types DECIMAL, NUM, NUMC, and PACF so you can work more easily with files and databases that are used by legacy applications. It is recommended that you use items of type BIN in new development or that you use an equivalent integer type (BIGINT, INT, or SMALLINT); calculations are most efficient with items of those types. You get the greatest efficiency by using items of type BIN, length 2, and no decimal places (the equivalent of type SMALLINT).
In calculations, assignments, and comparisons, items that are of type NUM and have no decimal places are more efficient than items that are of type NUM and have decimal places.
Calculations with items of types DECIMAL, NUM, NUMC, and PACF are equally efficient.
Related concepts
DataItem part
Record parts
References to variables and constants
Structure
Related reference
Assignments
BIN and the integer types
call
CHAR
DATE
DBCHAR
DECIMAL
Exception handling
FLOAT
Function invocations
HEX
INTERVAL
Items
Logical expressions
MBCHAR
MONEY
NUM
NUMC
Numeric expressions
Operators and precedence
PACF
SMALLFLOAT
SQL item properties
Text expressions
TIME
TIMESTAMP
UNICODE