An EGL assignment can have any of these effects:
By default, a record is equivalent to an item of type CHAR, with the total number of bytes equal to the sum of bytes in the structure items. When the record is of type CHAR, the following exceptions apply:
Examples of assignments are as follows:
z = a + b + c; myDate = sysVar.currentShortDate; myUser = sysVar.userID; myRecord01 = myRecord02; myRecord02 = "USER";
The next table and the explanations that follow tell the compatibility rules.
Target primitive type | Source primitive (or loose) types that are valid for target |
---|---|
BIN | BIN, INT, BIGINT, SMALLINT, DECIMAL, NUM, NUMBER, NUMC, PACF |
CHAR | CHAR, HEX, MBCHAR, NUM, NUMBER |
DBCHAR | DBCHAR |
HEX | CHAR, HEX |
MBCHAR | CHAR, MBCHAR |
NUM | BIN, INT, BIGINT, SMALLINT, CHAR, NUM, NUMBER, NUMC, PACF, DECIMAL |
NUMC | BIN, INT, BIGINT, SMALLINT, DECIMAL, NUM, NUMBER, NUMC, PACF |
PACF | BIN, INT, BIGINT, SMALLINT, DECIMAL, NUM, NUMBER, NUMC, PACF |
DECIMAL | BIN, INT, BIGINT, SMALLINT, DECIMAL, NUM, NUMBER, NUMC, PACF |
UNICODE | UNICODE |
A special case is as follows: the numeric value returned from a mathematical system word can be assigned to an item of type HEX; for details, see Mathematical (system words). |
A value of any of the numeric types (BIN, DECIMAL, NUM, NUMBER, NUMC, PACF) can be assigned to an item of any numeric type and size, and EGL does the conversions necessary to retain the value in the target format. If necessary, non-significant zeros are added or truncated. (Initial zeros in the integer part of a value are non-significant, as are trailing zeros in the fraction part of a value.)
You can use the system variable sysVar.handleOverflow to test whether an assignment or arithmetic calculation resulted in an arithmetic overflow, and you can set the system variable sysVar.overflowIndicator to specify the consequence of such an overflow.
If an arithmetic overflow occurs, the value in the target item is unchanged. If an arithmetic overflow does not occur, the value assigned to the target item is aligned in accordance with the declaration of the target item.
Let's assume that you are copying an item of type NUM to another and that the run-time value of the source item is 108.314:
Details on other cross-type assignments are as follows:
If the source length is 4 and value is 21, for example, the content is equivalent to "0021", and a length mismatch does not cause an error condition:
If the value of type NUM is negative and assigned to a value of type CHAR, the last byte copied into the item is an unprintable character.
This operation is equivalent to a NUM-to-NUM assignment.
If the source length is 4 and value is "0021", for example, the content is equivalent to a numeric 21, and the effect of a length mismatch is shown in these examples:
If the value of the target of type NUMC is negative, the last byte copied into the target of type CHAR is an unprintable character.
If the target is of a character type (CHAR, DBCHAR, HEX, MBCHAR, UNICODE) and has more space than is required to store a source value, EGL pads data on the right:
EGL truncates values on the right if the target of a character type has insufficient space to store the source value. No error is signaled. A special case can occur in the following situation:
In this situation, EGL truncates characters as needed to ensure that the target item contains a valid string of type MBCHAR, then adds (if necessary) terminating single-byte blanks.
You can assign a substructured item to a non-substructured item or the reverse, and you can assign values between two substructured items. Assume, for example, that variables named myNum and myRecord are based on the following parts:
DataItem myNumPart NUM(12) end Record myRecordPart type basicRecord 10 topMost CHAR(4); 20 next01 HEX(4); 20 next02 HEX(4); end
The assignment of a value of type HEX to an item of type NUM is not valid outside of the mathematical system words; but an assignment of the form myNum = topMost is valid because topMost is of type CHAR. In general terms, the primitive types of the items in the assignment statement guide the assignment, and the primitive types of subordinate items are not taken into account.
The primitive type of a substructured item is CHAR by default. If you assign data to or from a substructured item and do not specify a different primitive type at declaration time, the rules described earlier for items of type CHAR are in effect during the assignment.
An assignment of one record to another is equivalent to assigning one substructured item of type CHAR to another. A mismatch in length adds single-byte blanks to the right of the received value or removes single-byte characters from the right of the received value. The assignment does not consider the primitive types of subordinate structure items.
As mentioned earlier, the following exceptions apply:
Finally, if you assign an SQL record to or from a record of a different type, you must ensure that the non-SQL record has space for the four-byte area that precedes each structure item.
Related concepts
Syntax diagram
Related reference
sysVar.handleOverflow
sysVar.overflowIndicator
Primitive types
EGL statements
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.