The Question is:
Using DCL or perhaps TPU commands, I am trying to determine the number of
records in a text file.
I have been reading the file from beginning to end while incrementing a
counter. I figured that there has to be a better way. This seems very
inefficient. Especially if the text file contains thousands of records.
Can you help me out or at least point me in the right direction?
Thank you, Mr. Wizard!
The Answer is :
OpenVMS does not maintain a count of the total records within a file.
Accordingly, you will have to open the file and count the records,
either explicitly -- via a loop containing explicit record access
operations, or implicitly -- via the record operations that occur
within DCL commands such as CONVERT/SHARE/STATISTICS or
Starting with OpenVMS Alpha V7.2 and only with the ODS-5 volume
structure, RMS will maintain a FILE_LENGHT_HINT attribute. This
length hint includes the number of records and the number of bytes
written to the file.
The hint is available via f$file(filename,"file_length_hint") from
DCL, and via the XABITM structure and the XAB$_FILE_LENGTH_HINT
attribute from a program. Details on this are in the Record
Management Reference Manual.
From DCL, the output of f$file(filename,"file_length_hint") is a
comma-separated pair of numbers enclosed in paratheses, the first
number is the record count and the second is the data byte count.
A value of -1 indicates an invalid or unknown value.