This chapter discusses data conversions for computational data. PL/I converts data when a data item with a set of attributes is assigned to another data item with a different set of attributes. In this chapter, source refers to the data item to be converted, and target refers to the attributes to which the source is converted. Topics discussed for these data conversions include:
Examples of data conversion are included at the end of the chapter.
Data conversion for locator data is discussed in Locator conversion.
Conversion of the value of a computational data item can change its internal representation, precision or mode (for arithmetic values), or length (for string values). The tables that follow summarize the circumstances that can cause conversion to other attributes.
| Case | Target Attributes |
|---|---|
| Assignment | Attributes of variable on left of assignment symbol |
| Operand in an expression | Determined by rules for evaluation of expressions |
| Stream input (GET statement) | Attributes of receiving field |
| Stream output (PUT statement) | As determined by format list if stream is edit-directed, otherwise character-string |
| Argument to PROCEDURE or ENTRY | Attributes of corresponding parameter |
| Argument to built-in function or pseudovariable | Depends on the function or pseudovariable |
| INITIAL attribute | Other attributes of variable being initialized |
| RETURN statement expression | Attributes specified in PROCEDURE statement |
| DO statement, BY, TO, or REPEAT option | Attributes of control variable |
The following can cause conversion to character values:
| Statement | Option |
|---|---|
| DISPLAY | |
| Record I/O | KEYFROMKEY |
| OPEN | TITLE |
The following can cause conversion to a BINARY value:
| Statement | Option/Attribute/Reference |
|---|---|
| DECLARE, ALLOCATE, DEFAULT | length, size, dimension, bound, repetition factor |
| DELAY | milliseconds |
| FORMAT (and format items in GET and PUT) | iteration factorw, d, s, p |
| OPEN | LINESIZE, PAGESIZE |
| I/O | SKIP, LINE, IGNORE |
| Most statements | subscript |
All attributes for source and target data items (except string length) must be specified at compile time. Conversion can raise one of the following conditions: CONVERSION, OVERFLOW, SIZE, or STRINGSIZE. (Refer to Conditions.)
Constants can be converted at compile time as well as at run time. In all cases, the conversions are as described here.
In the discussions of conversions that follow:
More than one conversion might be required for a particular operation. The implementation does not necessarily go through more than one. To understand the conversion rules, it is convenient to consider them separately, for example:
dcl A fixed dec(3,2) init(1.23); dcl B fixed bin(15,5); B = A;
In this example, the decimal representation of 1.23 is first converted to binary (11,7), as 1.0011101B. Then precision conversion is performed, resulting in a binary (15,5) value of 1.00111B.
Additional examples of conversion are provided at the end of this chapter.