| Lock Statement |
Syntax
Lock [#]filenumber[, recordrange]
filenumber
Use: Required
Data Type: Integer
Any valid file number.
recordrange
Use: Optional
Data Type: Long
A range of records.
The syntax for the recordrange argument is:
recnumber | [start] To end
recnumber
Use: Required
Data Type: Long
The record or byte number at which to commence the lock.
start
Use: Optional
Data Type: Long
The first record or byte number to lock.
end
Use: Required
Data Type: Long
The last record or byte number to lock.
Description
Use the Lock statement in situations where multiple programs or more than one instance of your program may need read and write access to the same data file. The Lock statement prevents another process from accessing a record, a section, or the whole file until it's unlocked by the Unlock statement.
Rules at a Glance
recnumber is interpreted as a record number in the case of random files and a byte number in the case of binary files. Records and bytes in a file are always numbered sequentially from 1 onward.
To lock a particular record, specify its record number, and only that record is locked.
Use the Lock statement, omitting recnumber, to lock the whole file.
The Lock statement locks an entire file opened in input or output (sequential) mode, regardless of the recordrangeargument.
If you omit the start argument in the recnumber syntax, Lock locks all records from the start of the file to record or byte number end.
Attempting to access a locked file or portion of a file ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access