From BR Wiki
Jump to: navigation, search
LREC(<file handle>)

When the file referred to is an internal file, LRec internal function returns the number of the last record in the file. When it's an external file, LRec returns the last record or last byte (depending on whether REC= or POS= was used last). When it's a display file, LREC returns the byte size of the file.

When the file is not an open internal file handle LRec will return 0 or -1. If the file handle is equal to, then LRec will return 0. If it's greater than zero but is not an open file handle, LRec will return -1.

Comments and Examples

Here are three quick steps to determine how many records are in an internal file:

00010 OPEN #1:"name=filename",I,I,S
00020 PRINT LREC(1)
00030 CLOSE #1:

As long as there are no deleted records, the number printed by PRINT LREC(1) is the total number of records in file 1.

Related Functions

For additional information about files, see the following functions:

Technical Considerations

  1. If any space in the file is occupied by records marked for deletion by the DELETE statement, these records will still appear in the total from LREC(N) even though they will not be processed by reading the file sequentially.
  2. If file N is not open, LREC(N) will return -1.
  3. For external files, LREC(N) can return either a record number or a byte number, depending on whether the last I/O statement used a REC= clause (the default mode) or a POS= clause (to position to a specified byte number).
  4. The use of LREC within an I/O statement is strongly discouraged, especially on multi-user systems. See the Multi-user Programming chapter for additional information.