LRec

From BR Wiki
Revision as of 14:11, 15 January 2012 by Mikhail.zheleznov (talk | contribs) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

LRec(N)

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

When N is not an open internal file handle LRec will return 0 or -1. If N=0 then LRec(N) will return 0. If N is 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 from immediate mode (although this could also be a program).

 OPEN #1:"name=filename",I,I,S
 PRINT LREC(1)
 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.