The following table lists the assignment types.
Table 1-22 Assignment types
Assignment type | Description | Source | Target |
---|---|---|---|
Retrieval assignment | Retrieves the value of a string. | String | Embedded variable, SQL variable, or SQL parameter |
Sets the output parameter value of a procedure into an argument of the CALL statement. | SQL parameter | Embedded variable, SQL variable, or SQL parameter | |
Retrieves the return value from the value expression specified in the RETURN statement of a function. | Value expression | Return value of a function | |
Storage assignment | Assigns a value to a string. | Embedded variable, SQL variable, or SQL parameter | String |
Assigns a value from a CALL statement argument to an input parameter of a procedure. | Value expression | SQL parameter | |
Assigns a value from a function call argument to the function parameter. | Value expression | SQL parameter | |
Assigns a value using an assignment (SET) statement. | SQL variable, SQL parameter, or embedded variable | SQL variable, SQL parameter, or embedded variable |
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. The following table indicates the assignment rules for fixed-length target data.
Table 1-23 Assignment rules for fixed-length target data
Assignment type | Data length | ||
---|---|---|---|
Source#1 > target | Source#1 = target | Source#1 < target | |
Retrieval assignment | --# 2 | Y | --#3 |
Storage assignment | N | Y | --#3 |
Y: Assigned as is
--: 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.
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 indicates assignment rules that are applicable when the target of an assignment is variable-length data.
Table 1-24 Assignment rules for variable-length target data
Assignment type | Data length | |
---|---|---|
Source#1 > target#2 | Source#1![]() | |
Retrieval assignment | --#3 | --#4 |
Storage assignment | N | --#4 |
--: 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.
In general, assignment between different character sets is not permitted. However, the following table indicates when such assignment is possible.
Table 1-25 When assignment between different character sets is possible.
Source character set | Target character set | ||
---|---|---|---|
Default character set | EBCDIK | UTF-16 | |
Default character set | Y | Y#1 | Y#2 |
EBCDIK | Y#3 | Y | N |
UTF-16 | Y#4 | N | Y |
Source value expression | Target value expression |
---|---|
Character string literal or embedded variable | Any |
Source value expression | Target value expression |
---|---|
Character string literal or embedded variable | Any |
Any other value expression | Embedded variable |
Source value expression | Target value expression |
---|---|
Value expression | Embedded variable |
Source value expression | Target value expression |
---|---|
Embedded variable | Any |
Value expression | Embedded variable |
When the source and target character sets are different, assignment proceeds as follows:
When the source and target have incompatible structures, an assignment may not work. The following table indicates the structure rules for the source and target of an assignment operation.
Table 1-26 Structure rules for the source and target of assignment operation
Source structure | Target structure | |
---|---|---|
Simple Structure | Repetition Structure | |
Simple structure | Y | N |
Repetition structure | N | Y |
Y: Assignment allowed
N: Error may result.
Note: Subscripted repetition columns are treated as simple structures.