Serial Files |
|
Serial files are native OS flat files containing one or more records of variable length. Normal uses for serial files include holding print images or reports, or for interchange with other operating system applications. READ, WRITE, PRINT and INPUT directives may be used on a serial file. See File Processing Directives.
The SERIAL directive is used to create a serial file:
SERIAL filename$ [, max_recs [, rec_size ]]
Where:
filename$ |
String variable that defines the name of the serial (sequential) file to create. |
max_recs |
Estimated number of records the file is to contain. The default is no initial allocation of file space, with no limit as to final size. (Not used in most operating system implementations.) Numeric expression. |
rec_size |
Maximum size of the data portion of the record. (Optional on most operating systems.) Numeric expression. |
Example:
SERIAL "filename"
On a serial file, the READ directive reads the file one record at a time, from beginning to end. WRITE appends data to the end of the file. Any attempt to READ after a WRITE without having either closed the file or repositioned the pointer via the IND= option will result in an Error #2: END-OF-FILE on read or File full on write. A serial file must be locked in order to WRITE. The 'LU' parameter can be used to eliminate the need to lock a serial file before writing to it.
Example:
0010 OPEN (2) "SERFIL" ! Open SERFIL as 2
0020 READ (2,END=1000) NAM$, ADR$ ! Read next
0030 PRINT NAM$, ADR$
0040 GOTO 20
1000 CLOSE (2)
1010 END
The system provides an internal key for a serial file that may be used to reference records. This internal key is 4 characters long and contains the actual address of the record in binary.
When issuing a WRITE to a serial file, it must first be locked. The position of the last write prior to the file being closed marks the End-of-File.
In addition, when processing a typical serial file, a WRITE directive will append a Hex $8A$ field separator to each record, while the PRINT directive will not.