OPEN for random access

There are two variations of the OPEN statement for random-access files. This one is used for standard RANDOM and ISAM files: 

OPEN #ch, fspec, mode, recsiz, recnovar {,WAIT'FILE}{,WAIT'RECORD}{,READ'ONLY}{,SPAN'BLOCKS}

And this one is used only for ISAM-A files.

OPEN #ch, fspec, mode, recsiz, recnovar, fstatvar {,END'FILE}{,WAIT'RECORD}{,WAIT'FILE}{,READ'ONLY}

Parameters

ch is an integer expression (>0) specifying the file channel which will be needed for subsequent I/O operations on the file.

fspec is a string expression specifying the file to open, using native or AMOS syntax.

mode may be one of the following:

 

 

RANDOM

when LOKSER enabled, requests exclusive access

RANDOM'FORCED

shared access

INDEXED or ISAM'INDEXED

ISAM shared access

INDEXED'EXCLUSIVE or ISAM'INDEXED'EXCLUSIVE

ISAM exclusive access

ISAMP'INDEXED

ISAM-A shared access; must use second form of OPEN statement above

ISAMP'INDEXED'EXCLUSIVE

ISAM-A exclusive access ("       "         "      "  )

 

recsiz is an integer expression specifying the record size—i.e. the number of bytes transferred in each subsequent READ and WRITE operations.

recnovar must be an F,6 variable which is used to specify the record number for READ and WRITE operations. For ISAM lookup operations, this variable will be automatically updated in preparation for the next READ. Also see MX_FLSET for details on handling this parameter within SBX routines, and XREAD, XWRITE for an alternative method of specifying the record number.

fstatvar must be an F,6 variable; it returns a status code after each ISAM-A operation.

WAIT'FILE, WAIT'RECORD and READ'ONLY have meaning only when LOKSER is enabled; otherwise they are ignored. WAIT'FILE causes the statement to wait until access can be granted. If requesting exclusive access, no other process may have the file open except for READ'ONLY. If requesting shared access, no other process can have the file open exclusively. Otherwise, if access cannot be granted, error 37 will be returned. WAIT'RECORD causes READ operations to wait if the requested record is locked, otherwise error 38 is returned. READ'ONLY disables LOKSER—and WRITE operations—for this file access session, and is useful when you're just going to be reading from the file and it isn't critical that the file isn't modified during the read operations. Also see ASFLAG.SBR for a way to achieve this effect without using the BASIC Plus compiler extensions.

SPAN'BLOCKS disables 512-byte blocking. This is a historical hold-over from AMOS, which performed random file access in 512 byte blocks and did not allow logical records to be split between two blocks. If the record size didn't divide evenly into 512, the remaining number of bytes would simply be unused at the end of each 512 byte block. In the worst case, a record size of 257 bytes would result in 255 out of every 512 bytes wasted. In SPAN'BLOCKS mode, records are adjacent with no wasted space between then and no consideration for how they map onto physical disk "blocks". 512-byte blocking remains the default, for compatibility with existing files, but serves no useful purpose in the modern world and is therefore deprecated. SPAN'BLOCKS is always recommended, except when compatibility with older file layouts is required. SPAN'BLOCKS is automatic when the record size is greater than 512.

END'FILE applies only to ISAM-A and causes the file "cursor" to start at the end of the index rather than at the start, so a subsequent GET'PREV operation will retrieve the last indexed record.