Table 1-21 shows types of assignments that are supported.
Table 1-21 Assignment types
Assignment type | Description | Source | Target |
---|---|---|---|
Retrieval assignment | Receives the value of a string. | String | Embedded variable, SQL variable, or SQL parameter |
Receives the value of a procedure parameter into an argument in the CALL statement. | Embedded variable | SQL parameter | |
Receives the value of a function parameter into the argument that calls the function. | Embedded variable | SQL parameter | |
Storage assignment | Assigns a value to a string. | Embedded variable, SQL variable, or SQL parameter | String |
Assigns the value from a CALL statement argument into a procedure parameter. | SQL parameter | Embedded variable | |
Assigns a value from a function call argument to the function parameter. | SQL parameter | Embedded variable | |
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. Table 1-22 shows assignment rules for fixed-length target data.
Table 1-22 Assignment rules for fixed-length target data
Assignment type | Data length | ||
---|---|---|---|
Source1 > target | Source1 = target | Source1 < target | |
Retrieval assignment | ![]() | Y | ![]() |
Storage assignment | N | Y | ![]() |
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 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 type | Data length | |
---|---|---|
Source1 > target2 | Source1![]() | |
Retrieval assignment | ![]() | ![]() |
Storage assignment | N | ![]() |
: 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.
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 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.