EGL Reference Guide for iSeries

Assignments

An EGL assignment can have any of these effects:



Syntax diagram for the assignment statement

target
An item, record, or system variable

source
An expression or record. An expression may be composed of a complex series of symbols (for example, a + b + c) or may be one of these:

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).

Assignment across numeric types

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:

Other cross-type assignments

Details on other cross-type assignments are as follows:

Padding and truncation with character types

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.

Assignment to or from substructured items

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.

Assignment of a record

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


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]