READ

Top  Previous  Next

 

The READ statement reads a record from a previously opened file.

 

 

Format

 

READ var FROM file.var, record.id {ON ERROR statement(s)}

{THEN statement(s)}

{ELSE statement(s)}

 

where

 

varis the name of a variable to receive the dynamic array read from the file.

 

file.varis the file variable associated with the file.

 

record.idevaluates to the id of the record to be read.

 

statement(s)are statements to be executed depending on the outcome of the READ operation.

 

At least one of the THEN and ELSE clauses must be present.

 

The specified record is read into the named variable.

 

The THEN clause is executed if the READ is successful.

 

The ELSE clause is executed if the READ fails because no record with the given id is present on the file. If the PICK.READ mode of the $MODE directive is used var will be left unchanged, otherwise it will be set to a null string. The STATUS() function will indicate the cause of the error.

 

The ON ERROR clause is executed for serious fault conditions such as errors in a file's internal control structures. The STATUS() function will return an error number. If no ON ERROR clause is present, an abort would occur.

 

 

Example

 

READ ITEM FROM STOCK, ITEM.ID THEN

  ...processing statements...

END ELSE

  DISPLAY "Record " : ITEM.ID : " not found"

END

 

This program fragment reads a record from the a file previously opened to file variable STOCK into variable ITEM. If successful, the processing statements are executed. If the record is not found, a message is displayed.