Reread

From Br Wiki
Jump to: navigation, search

The ReRead (RER) statement assigns values from the last record read from an internal or external file.

Comments and Examples

An internal or external file must already be opened and assigned a file number before REREAD can be used. REREAD must follow a successful READ or REREAD. Although REREAD can be used with SEQUENTIAL, RELATIVE, or KEYED processing, it cannot have a REC= clause, POS= clause or a KEY= clause.

In the following example, K$ is a potential key field value entered from the keyboard for a file that allows duplicate keys. These lines of code are one possible way to mix READ and REREAD to be sure that all records are found which exactly match a certain key:

00540 RESTORE #2,KEY=K$: NOKEY 9000
00550 READ #2, USING F2KEYONLY: KY$
00560 IF KY$<>K$ THEN GOTO DONE
00570 REREAD #2, USING F2FULL: MAT A$, MAT AMTS
00580 GOTO 550

Line 550 reads the entire record, but the FORM statement with the label F2KEYONLY only assigns a value to KY$, the key field. If Line 560 finds a match, then the REREAD in line 570 assigns values to all fields in the arrays A$ and AMTS.

Syntax

REREAD #<file number> [, USING {<string expression>|<line ref>}] [, {RESERVE|RELEASE}] : [{Mat <array name>|<variable name>}][,...]  [<error condition> <line ref>][,...]

Reread.png

Defaults

  1. Unformatted.
  2. Hold all previous locks.
  3. Interrupt the program if an error occurs and "ON error" is not active.

Parameters

"File-num" is an integer or numeric expression which matches this REREAD statement to a file of the same number, already identified in an OPEN statement.

The "USING" keyword is part of a clause which specifies either the "line-ref" of a FORM statement or a "string-expr" containing a FORM statement.

The "RESERVE" and "RELEASE" parameters specify record locking rules for multi-user systems. "RESERVE" instructs the system to hold all previous record locks. "RELEASE" releases all previous record locks.

The "MAT array-name" and "var-name" parameters represent a list of variables to be assigned values. Multiple specifications must be separated by commas.

REREAD allows error processing with the optional "error-cond line-ref" parameter. See Error Conditions for more information.

Technical Considerations

  1. Relevant error conditions are: CONV, ERROR, EXIT, IOERR, and SOFLOW.
  2. If a string-expr is used with a USING clause, it must begin with "FORM ". This technique executes relatively slowly because the string is compiled on each execution of the REREAD statement.
  3. Omitting the USING clause allows unformatted file processing. See File I/O for more information.
  4. When OPTION INVP is in effect, the normal input of commas and periods is interchanged in PIC, N, NZ, G and GZ format specifications to produce European-style numbers. See the OPTION statement for details.