Format and List Part

<format and list part>

── , ─┬─<format designator>─┬─────────────────────────────────┬────────┤
      │                     └─ , ──<list>─────────────────────┤
      ├─ < ──<editing specifications>── > ─┬──────────────────┤
      │                                    └─ , ──<list>──────┤
      ├─ * ───────────────┬─ , ──<list>───────────────────────┤
      ├─<free-field part>─┘                                   │
      └─<arithmetic expression>── , ─┬─<array row>────────────┤
                                     ├─<subscripted variable>─┤
                                     ├─<pointer expression>───┤
                                     ├─<string variable>──────┤
                                     └─<string expression>────┘

<list>

    ┌◄────── , ──────┐
──┬─┴─<list element>─┴─┬───────────────────────────────────────────────┤
  └─<list designator>──┘

<free-field part>

──┬─────┬─┬─────────────────────┬─ / ─┬─────┬─┬────────────────┬───────┤
  └─ * ─┘ └─<number of columns>─┘     └─ / ─┘ └─<column width>─┘

<number of columns>

── [ ──<arithmetic expression>── ] ────────────────────────────────────┤

<column width>

── [ ──<arithmetic expression>── ] ────────────────────────────────────┤

The format and list part element indicates the interpretation of the data in the file and the variables to which the data is assigned.

If the format and list part element does not appear, the input record is skipped.

Formatted Read

A READ statement that contains a format designator, editing specifications, or a free-field part is called a formatted read.

A format designator without a list indicates that the referenced format contains a string literal into which corresponding characters of the input data are to be placed. The string literal in the FORMAT declaration is replaced by the string literal in the input data.

A format designator with a list indicates that the input data is to be edited according to the specifications of the format and assigned to the variables of the list.

Editing specifications can appear in place of a format designator and have the same effect as if they had been declared in a FORMAT declaration and had been referenced through a format designator. For more information, refer to FORMAT Declaration.

On any formatted I/O statement (excluding core-to-core I/O), the number of characters allowed in the record is determined solely by the value of the file attribute MAXRECSIZE of the file. If the format requires more characters than are contained in the record, a format error occurs at run time.

The free-field part is discussed under Data Format for Free-Field Input later in this section.

Binary Read

A READ statement of the following form is called a binary read:

READ(<file part>,*,<list>)

An asterisk (*) followed by a list specifies that the input data is to be processed as full words and assigned to the elements of the list without being edited. The number of words read is determined by the number of elements in the list or the maximum record size, whichever is smaller.

When data is read into character arrays, only full words are read. If there is a partial word left at the end of the data, it is ignored. For example, if A is an EBCDIC array and FILEID contains the string 12345678, the following statement reads only the characters 123456:

READ(FILEID,*,A)

When a string is read into a string variable using a binary READ statement, the first word read from the record is assumed to specify the length of the string. This word is evaluated, and the resulting value is the number of characters read beginning with the next word of the record. The binary WRITE statement automatically writes a word of length information before the text of each string variable; therefore, the following WRITE statement can later be read by the following READ statement:

WRITE(F,*,STR,STRARRAY[5],STR !! "ABC")

READ(F,*,STR1,STR2,STRARRAY[0])

For more information, see “Binary Write” under WRITE Statement.

The results are undefined for binary READ statements that attempt to read data not containing length information into string variables.

Array Row Read

A READ statement of any of the following forms is called an array row read:

READ(<file part>,<arithmetic expression>,<array row>)
READ(<file part>,<arithmetic expression>,<subscripted variable>)
READ(<file part>,<arithmetic expression>,<pointer expression>)
READ(<file part>,<arithmetic expression>,<string variable>)

The first three forms of the array row read specify that input data is to be read without editing and assigned left-justified to the array specified by the array row, subscripted variable, or pointer expression. The arithmetic expression specifies the number of words or the number of characters, depending on the value of the FRAMESIZE attribute for the file, to be read. Refer to the File Attributes Programming Reference Manual for information on the FRAMESIZE attribute. The number of words or characters actually read equals whichever of the following values is smallest:

  • The MAXRECSIZE attribute of the file being read

  • The length of the array row (or portion of the array to the right of where the pointer expression points or to the right of the element specified by the subscripted variable)

  • The absolute value of the arithmetic expression

A READ statement of the following form specifies that input data is to be read without editing and assigned to the string variable:

READ (<file part>,<arithmetic expression>,<string variable>)

The number of characters read is the smaller of the value of the MAXRECSIZE attribute of the file being read or of the absolute value of the arithmetic expression. The value of the arithmetic expression always specifies the number of characters (not words) to be read.

The following is an example of an array row read:

BEGIN
   FILE IN(TITLE="TEST.", UNITS=CHARACTERS, MAXRECSIZE=20);
   STRING S1,S2;
   READ(IN,15,S1); % READS 15 CHARACTERS INTO S1
   READ(IN,50,S2); % READS 20 CHARACTERS INTO S2
END.