Instruccion LOCK

Objetivo:

Restringir el acceso a todo o parte de un archivo que ha sido abierto por otro proceso. Este es usado en un ambiente de multidispositivo, a menudo referido como un ambiente de red o red.

Sintaxis:

LOCK [#]n [,[record number] [TO record number]]

Comentarios:

n es el n�mero que fue adjudicado al archivo cuando fue al principio numerado en el programa.

record number es el n�mero del registro individual que debe ser cerrado con llave. O, si una variedad de archivos debe ser cerrada con llave, record number designa el principio y final del registro de la variedad especificada.

La variedad de n�meros de registro legales es 1 a 2 32-1. El l�mite en el tama�o de registro es 32767 bytes.

La variedad de registro especificada debe ser de m�s abajo (al mismo o) n�meros m�s alto de registro.

Si un n�mero de registro inicial no es especificado, el registro el n�mero 1 es asumido.

Si un n�mero de registro que se termina no es especificado, entonces s�lo el registro especificado es cerrado con llave.

Lo siguiente es ejemplos de ins LOCK legales:

LOCK #n cierra con llave el archivo entero n
LOCK #n, X cierra registran X s�lo
LOCK #n TO Y cierra registran 1 por Y
LOCK #n, X TO Y cierra registran X por Y

Con un archivo de acceso aleatorio, el archivo abierto entero, o una variedad de archivos dentro de un archivo abierto, puede ser cerrado con llave, as� negando al acceso a aquellos archivos a cualquier otro proceso que tambi�n ha abierto el archivo.

Con un archivo de acceso secuencial que ha sido abierto para entrada o salida, el archivo entero es cerrado con llave, sin tener en cuenta cualquier variedad de registro especificada. Este no es considerado un error. La especificaci�n de una variedad en la declaraci�n LOCK en cuanto al archivo secuencial ser� simplemente desatendida.

La instruccion LOCK deber�a ser ejecutada en un archivo o variedad de registro dentro de un archivo antes de intentar leer o escribir a aquel archivo.

El archivo cerrado con llave o la variedad de registro deber�an ser abiertos antes de que el archivo est� cerrado. El fracaso de ejecutar la instruccion UNLOCK puede poner en peligro el futuro acceso a aquel archivo en un ambiente de red.

Es esperado que el tiempo en el cual los archivos o las regiones dentro de archivos son cerrados con llave ser� corto, y as� el uso sugerido de la instruccion LOCK es dentro de a corto plazo emparejado LOCK/UNLOCK instrucciones.

Ejemplos:

La secuencia siguiente se manifiesta como las instrucciones LOCK/UNLOCK deber�an ser usadas:

LOCK #1, 1 TO 4
LOCK #1, 5 TO 8
UNLOCK #1, 1 TO 4
UNLOCK #1, 5 TO 8

El ejemplo siguiente es ilegal:

LOCK #1, 1 TO 4
LOCK #1, 5 TO 8
UNLOCK #1, 1 TO 8
 

LOCK Statement

Purpose:

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.

Syntax:

LOCK [#]n [,[record number] [TO record number]]

Comments:

n is the number that was assigned to the file as it was originally numbered in the program.

record number is the number of the individual record that is to be locked. Or, if a range of records are to be locked, record number designates 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:

LOCK #n 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.

Examples:

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

The following example is illegal:

LOCK #1, 1 TO 4
LOCK #1, 5 TO 8
UNLOCK #1, 1 TO 8
1