For details on those cases, see Reference compatibility in EGL.
A value of any of the numeric types (including NUMC and PACF) can be assigned to a field of any numeric type and size, and EGL does the conversions necessary to retain the value in the target format.
Non-significant zeros are added or truncated as needed. (Initial zeros in the integer part of a value are non-significant, as are trailing digits in the fraction part of a value.)
For any of the numeric types, you can use the system variable sysVar.overflowIndicator to test whether an assignment or arithmetic calculation resulted in an arithmetic overflow, and you can set the system variable VGVar.handleOverflow to specify the consequence of such an overflow.
If an arithmetic overflow occurs, the value in the target field is unchanged. If an arithmetic overflow does not occur, the value assigned to the target field is aligned in accordance with the declaration of the target field.
When you assign a floating-point value (type FLOAT or SMALLFLOAT) to a field of a fixed-point type, the target value is truncated if necessary. If a source value is 108.357 and the fixed-point target has one decimal place, for example, the target receives 108.3.
If the value of type NUM is negative and assigned to a value of type CHAR, the last byte copied into the field is an unprintable character.
This operation is equivalent to a NUM-to-NUM assignment.
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.
// NOT valid because February 30 is not a valid date myTS timestamp("yyyyMMdd"); myTS = "20050230";
// NOT valid if run in February myTS timestamp("dd"); myTS = "30";
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.
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.
sourceTimeStamp timestamp ("MMdd"); targetTimeStamp timestamp ("yyyyMMdd"); sourceTimeStamp = "1201"; // if this code runs in 2004, the next statement // assigns 20041201 to targetTimeStamp targetTimeStamp = sourceTimeStamp;
sourceTimeStamp02 timestamp ("ssff"); targetTimeStamp02 timestamp ("mmssff"); sourceTimeStamp02 = "3201"; // the next assignment includes the minute // that is current when the assignment statement runs targetTimeStamp02 = sourceTimeStamp02;
sourceTimeStamp timestamp ("yyyyMM"); targetTimeStamp timestamp ("yyyyMMdd"); sourceTimeStamp = "200412"; // regardless of the day, the next statement // assigns 20041201 to targetTimeStamp targetTimeStamp = sourceTimeStamp;
sourceTimeStamp02 timestamp ("hh"); targetTimeStamp02 timestamp ("hhmm"); sourceTimeStamp02 = "11"; // regardless of the minute, the next statement // assigns 1100 to targetTimeStamp02 targetTimeStamp02 = sourceTimeStamp02;
You can assign a substructured field to a non-substructured field or the reverse, and you can assign values between two substructured fields. 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 variables; but an assignment of the form myNum = topMost is valid because topMost is of type CHAR. In general terms, the primitive types of the fields 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 field and do not specify a different primitive type at declaration time, the rules described earlier for fields of type CHAR are in effect during the assignment.
An assignment of one fixed 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 fields.
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 field.
Related concepts
PageHandler