READ

The READ statement allows a program to read a record from a previously opened file into a variable.

 

COMMAND SYNTAX

READ variable1 FROM { variable2,} expression {SETTING setvar} {ON ERROR statements} THEN|ELSE statements

 

SYNTAX ELEMENTS

variable1 is the identifier into which the record will be read.

variable2, if specified, should be a jBC variable that has previously been opened to a file using the OPEN statement. If variable2 is not specified then the default file is assumed.

The expression should evaluate to a valid record key for the file.

If the SETTING clause is specified and the read fails, setvar will be set to one of the following values:

Incremental File Errors

128 No such file or directory
4096 Network error
24576 Permission denied
32768 Physical I/O error or unknown error

If ON ERROR is specified, the statements following the ON ERROR clause will be executed for any of the above Incremental File Errors except error 128.

 

NOTES

If you wish to set a lock on a record you should do so explicitly with the READU statement.

An attempt to access a 'null' item-id in a directory will take the ELSE clause, i.e. treated as 'item does not exist'.

 

EXAMPLE 1

OPEN "Customers" ELSE ABORT 201, "Customers"
OPEN "DICT Customers" TO DCusts ELSE
    ABORT 201, "DICT Customers"
END
READ Rec FROM DCusts, "Xref" THEN
    READ DataRec FROM Rec<7> ELSE
        ABORT 202, Rec<7>
    END
END ELSE
    ABORT 202, "Xref"
END

EXAMPLE 2

READ record FROM filevar, id SETTING errorNumber ON ERROR
    PRINT errorNumber
END THEN
    PRINT 'Record read successfully'
END ELSE
    PRINT 'Record not on file'
END


jBC