1.5.7 Assignment rules

Table 1-21 shows types of assignments that are supported.

Table 1-21 Assignment types

Assignment typeDescriptionSourceTarget
Retrieval assignmentReceives the value of a string.StringEmbedded variable, SQL variable, or SQL parameter
Receives the value of a procedure parameter into an argument in the CALL statement.Embedded variableSQL parameter
Receives the value of a function parameter into the argument that calls the function.Embedded variableSQL parameter
Storage assignmentAssigns a value to a string.Embedded variable, SQL variable, or SQL parameterString
Assigns the value from a CALL statement argument into a procedure parameter.SQL parameterEmbedded variable
Assigns a value from a function call argument to the function parameter.SQL parameterEmbedded variable
Assigns a value using an assignment (SET) statement.SQL variable, SQL parameter, or embedded variableSQL variable, SQL parameter, or embedded variable
Organization of this subsection
(1) Fixed-length target
(2) If the target of assignment is variable-length data, large object data, or BINARY
(3) Rules on the structure of the source and target of an assignment

(1) Fixed-length target

If the target of an assignment is fixed-length character string data, mixed character string data, or national character string data, the applicable assignment rules vary with the length of the source data. Table 1-22 shows assignment rules for fixed-length target data.

Table 1-22 Assignment rules for fixed-length target data

Assignment typeData length
Source1 > targetSource1 = targetSource1 < target
Retrieval assignment[Figure]2Y[Figure]3
Storage assignmentNY[Figure]3

Y: Assigned as is

[Figure]: Assigned left-justified according to length of target data

N: An error occurs.

1 If the source is variable-length data, the length of the source data is its actual length.

2 If an overflow occurs, the excess portion of the data is truncated on the right, and warning information is set in the SQLWARN1 parameter for the SQL communication area. If an indicator variable is specified, the length of data before truncation is set in the indicator variable.

3 The trailing portion is space-filled on the right.

(2) If the target of assignment is variable-length data, large object data, or BINARY

If the target of an assignment is character string data, mixed character data, national character string data, large object data, or BINARY of variable length, the rules of assignment vary depending upon the length of the assignment source data. The following table shows assignment rules that are applicable when the target of an assignment is variable-length data.

Table 1-23 Assignment rules for variable-length target data

Assignment typeData length
Source1 > target2Source1[Figure] target2
Retrieval assignment[Figure]3[Figure]4
Storage assignmentN[Figure]4

[Figure]: Assigned left-justified according to length of source data2

N: An error occurs.

1 If the source is variable-length data, the length of the source data is its actual length.

If the source is the embedded variable for a locator, the data length of the source is the actual length of the data that is assigned to the locator.

2 The length of target data is equal to the maximum allowable length of variable-length data.

If the source is the embedded variable for a locator, the target data length takes one of the following lengths:

BLOB locator: 2147483647

BINARY locator: 2147483647

3 If an overflow occurs, the excess portion of the data is truncated on the right, and the actual length is equal to the maximum allowable length of the target string. When this occurs, warning information is set in the SQLWARN1 parameter for the SQL communication area. If an indicator variable is specified, the length of data before truncation is set in the indicator variable.

4 If the source is fixed-length data, the length of the source data is its actual length.

(3) Rules on the structure of the source and target of an assignment

When the source and target have incompatible structures, an assignment may not work. Table 1-24 shows the structure rules for the source and target of an assignment operation.

Table 1-24 Structure rules for the source and target of assignment operation

Source structureTarget structure
Simple StructureRepetition Structure
Simple structureYN
Repetition structureNY

Y: Assignment allowed

N: Error may result.

Note: Subscripted repetition columns are treated as simple structures.