Previous Topic Next topic Print topic


List-Directed Stream I/O

Values transmitted by list-directed stream I/O are separated by blanks or commas on input and by blanks on output. Each value is transmitted in a readable format determined by the value's data type.

In a GET LIST operation, Open PL/I automatically converts ASCII input data to the data types of the variables specified in the GET LIST statement. In a PUT LIST operation, Open PL/I converts a computational expression to its ASCII equivalent for output.

The following example of simple terminal output demonstrates list-directed stream I/O:

PUT LIST(A,B);

In this example, if A is an integer declared fixed binary whose current value is -75, and B is a character-string declared character(5) whose current value is HATBoxes, the example produces:

Boxes

in the current output line of file F. The field boxes -75 is produced by converting the fixed binary(15) integer to a character-string. The many blanks allow for the maximum possible value, plus sign and decimal point and leading 0 for fractional values, as explained in the section Arithmetic to Character-String Conversion in the chapter Data Type Conversions. A single blank separates the value of A from the value of B. The last blank separates B from the next field.

For input, list-directed I/O considers each blank or comma as a field terminator. Excess commas are not allowed. Excess blanks within a field to be assigned to an arithmetic variable are ignored. Such fields must simply contain a valid constant, as could be written in the text of a program.

A field to be assigned to a character-string variable may contain a character-string constant, as written in the text of a program, or it may contain a sequence of any characters. In the latter case, the sequence begins with the first non-blank character in the field and ends with the character immediately preceding the next comma or blank, as shown in the following example of a GET LIST operation. Note that character sequences containing blanks or commas that are to be treated as a unit must be enclosed in single quotation marks ("). For example:

GET FILE(F) LIST(A,B);

In this example, if A is fixed binary(15) and B is character(5), the following lines have the indicated effect on the values of A and B.

Line A B
boxes 5 boxes
boxes      -4 5 boxes
boxes -4 5      abc-4
Previous Topic Next topic Print topic