READSEQ statement

Syntax

READSEQ variable FROM file.variable [ON ERROR statements]
{THEN statements [ELSE statements] | ELSE statements}

Description

Use the READSEQ statement to read a line of data from a file opened for sequential processing. Sequential processing lets you process data one line at a time. InfoSphere® DataStage® keeps a pointer at the current position in the file. The OPENSEQ statement sets this pointer to the first byte of the file, and it is advanced by READSEQ, READBLK, WRITESEQ, and WRITEBLK statements.

Each READSEQ statement reads data from the current position in the file up to a newline and assigns it to variable. The pointer is then set to the position following the newline. The newline is discarded.

file.variable specifies a file previously opened for sequential processing. The FROM clause is required. If the file is neither accessible nor open, or if file.variable evaluates to the null value, the READSEQ statement fails and the program terminates with a run-time error message.

If data is read from the file, the THEN statements are executed, and the ELSE statements are ignored. If the file is not readable, or the end of file is encountered, the ELSE statements are executed; any THEN statements are ignored.

In the event of a timeout, READSEQ returns no bytes from the buffer, and the entire I/O operation must be retried.

READSEQ affects the STATUS function in the following way:

0
The read is successful.
1
The end of file is encountered.
2
A timeout ended the read.
-1
The file is not open for a read.

If NLS is enabled, the READSEQ 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.

The ON ERROR Clause

The ON ERROR clause is optional in the READSEQ statement. Its syntax is the same as that of the ELSE clause. The ON ERROR clause lets you specify an alternative for program termination when a fatal error is encountered during processing of the READSEQ statement.

If a fatal error occurs, and the ON ERROR clause was not specified, or was ignored (as in the case of an active transaction), the following occurs:

  • An error message appears.
  • Any uncommitted transactions begun within the current execution environment roll back.
  • The current program terminates.
  • Processing continues with the next statement of the previous execution environment, or the program returns to the command prompt.

A fatal error can occur if any of the following occur:

  • A file is not open.
  • file.variable is the null value.
  • A distributed file contains a part file that cannot be accessed.

If the ON ERROR clause is used, the value returned by the STATUS function is the error number.

Example

OPENSEQ 'FILE.E', 'RECORD4' TO FILE ELSE ABORT
FOR N=1 TO 3
   READSEQ A FROM FILE THEN PRINT A
NEXT N
CLOSESEQ FILE

This is the program output:

FIRST LINE
SECOND LINE
THIRD LINE