READT statement
Syntax
READT [UNIT (mtu)] variable
{THEN statements [ELSE statements] | ELSE statements}
Description
Use the READT statement to read the next tape record from a magnetic tape unit and assign its contents to a variable.
The UNIT clause specifies the number of the tape drive unit. Tape unit 0 is used if no unit is specified.
mtu is an expression that evaluates to a code made up of three decimal digits, as shown in the following table:
| Code | Available Options |
|---|---|
| m (mode) | 0 = No conversion 1 = EBCDIC conversion 2 = Invert high bit 3 = Invert high bit and EBCDIC conversion |
| t (tracks) | 0 = 9 tracks. Only 9-track tapes are supported. |
| u (unit number) | 0 through 7 |
The mtu expression is read from right to left. Therefore, if mtu evaluates to a one-digit code, it represents the tape unit number. If mtu evaluates to a two-digit code, the rightmost digit represents the unit number and the digit to its left is the track number; and so on.
If either mtu or variable evaluates to the null value, the READT statement fails and the program terminates with a run-time error message.
Each tape record is read and processed completely before the next record is read. The program waits for the completion of data transfer from the tape before continuing.
If the next tape record exists, variable is set to the contents of the record, and the THEN statements are executed. If no THEN statements are specified, program execution continues with the next statement.
Before a READT statement is executed, a tape drive unit must be attached (assigned) to the user. Use the ASSIGN command to assign a tape unit to a user. If no tape unit is attached or if the unit specification is incorrect, the ELSE statements are executed and the value assigned to variable is empty. Any THEN statements are ignored.
The largest tape record that the READT statement can read is system-dependent. If a tape record is larger than the system maximum, only the bytes up to the maximum are assigned to variable.
The STATUS function returns 1 if READT takes the ELSE clause, otherwise it returns 0.
If NLS is enabled, the READT and other BASIC statements that perform I/O operations always map external data to the internal character set using the appropriate map for the input file if the file has a map associated with it.
PIOPEN Flavor
If you have a program that specifies the syntax UNIT ndmtu, the nd elements are ignored by the compiler and no errors are reported.
Examples
The following example reads a tape record from tape drive 0:
READT RECORD ELSE PRINT "COULD NOT READ FROM TAPE"
The next example reads a record from tape drive 3, doing an EBCDIC conversion in the process:
READT UNIT(103) RECORD ELSE PRINT "COULD NOT READ"