To restrict the access to all or part of a file that has been opened by another process. This is used in a multi-device environment, often referred to as a network or network environment.
LOCK [#]n [,[record number] [TO record number]]
nis the number that was assigned to the file as it was originally numbered in the program.
record numberis the number of the individual record that is to be locked. Or, if a range of records are to be locked, record numberdesignates the beginning and ending record of the specified range.
The range of legal record numbers is 1 to 232 -1. The limit on record size is 32767 bytes.
The record range specified must be from lower to (the same or) higher record numbers.
If a starting record number is not specified, the record number 1 is assumed.
If an ending record number is not specified, then only the specified record is locked.
The following are examples of legal LOCK statements:
locks the entire file n
LOCK #n, X
locks record X only
LOCK #n TO Y
locks records 1 through Y
LOCK #n, X TO Y
locks records X through Y
With a random-access file, the entire opened file, or a range of records within an opened file, may be locked, thus denying access to those records to any other process which has also opened the file.
With a sequential access file that has been opened for input or output, the entire file is locked, regardless of any record range specified. This is not considered an error. The specification of a range in the LOCK statement regarding the sequential file will simply be disregarded.
The LOCK statement should be executed on a file or record range within a file before attempting to read or write to that file.
The locked file or record range should be unlocked before the file is closed. Failure to execute the UNLOCK statement can jeopardize future access to that file in a network environment.
It is expected that the time in which files or regions within files are locked will be short, and thus the suggested usage of the LOCK statement is within short-term paired LOCK/UNLOCK statements.
The following sequence demonstrates how the LOCK/UNLOCK statements should be used:
LOCK #1, 1 TO 4
LOCK #1, 5 TO 8
UNLOCK #1, 1 TO 4
UNLOCK #1, 5 TO 8
All Frank Sinatra recordings, All Beatles albums, All solo albums from John Lennon, Paul McCartney, George Harrison and Ringo Starr, All Beatles songs, List of Platinum selling albums, Database with hits from 1950 to 1999.
Sought after DLL files, Nutworks magazine (retro), Worldwide ISO and TLD codes, File extensions database, The Hackers dictionary, Free software for the Atari, Amiga and Macintosh, Nokia smartphone, PocketPC, List of all BASIC programming language commands, List of all DOS commands, Free Advanced Bash-Scripting Guide (Linux-Unix)