14.6.3 Locating Records
The FIND statement locates a specified record and makes
it the current record. Using the FIND statement to locate
records can be faster than using a GET statement because
the FIND statement does not transfer any data to the record
buffer; therefore, it executes faster than a GET statement.
However, if you are interested in the contents of a record, you
must retrieve it with a GET operation.
The FIND statement sets the current record pointer to the
record just found, making it the target for a GET, UPDATE,
or DELETE statement. (Note that you must have write ac-
cess to a record before issuing a PUT, UPDATE, or DELETE
operation.) A sequential FIND operation searches records in
the following order:
.
Sequential files from beginning to end
.
Relative files in ascending relative record or cell number
order
.
Indexed files in ascending or descending order, based
on the current key of reference and the key's collating
sequence
For sequential fixed-length and relative files, you can find
a particular record by specifying a RECORD clause. This is
called a random access FIND. You can also perform a ran-
dom access FIND for indexed files by specifying a key of
reference, a relational test, and a key value.
In the following example, the first FIND statement finds the
first record whose key value either equals or follows SMITH
in the key's collating sequence. The second FIND statement
finds the first record whose key value follows JONES in the
key's collating sequence. Each record found by the FIND
statement becomes the current record. (Note that you can
only have one current record at a time.)
MAP (Emp) STRING Emp_name, LONG Emp_number, SSN
OPEN "EMP.DAT" AS FILE #1%, INDEXED, &
ACCESS READ, &
MAP Emp, &
PRIMARY KEY Emp_name
FIND #1%, KEY #0% NXEQ "SMITH"
FIND #1%, KEY #0% NX "JONES"
The string expression can contain fewer characters than the
key of the record you want to find. However, if you want
to locate a record whose string key field exactly matches
the string expression you provide, you must pad the string
expression with spaces to the exact length of the key of
reference. For example:
FIND #5%, KEY #0% EQ "TOM "
FIND #5%, KEY #0% EQ "TOM"
The first FIND statement locates a record whose primary
key field equals " TOM " . The second FIND statement
locates the first record whose primary key field begins with
" TOM " .
Table 14-1 displays the status of the current record and next
record pointers after both a sequential and a random access
FIND.
Note that a random access FIND operation locates the spec-
ified record and makes it the current record, but the next
record pointer does not change.
You can specify an ALLOW clause to the FIND statement if
you have opened the file with ACCESS MODIFY or ACCESS
WRITE and have specified UNLOCK EXPLICIT. The
ALLOW clause lets you control the type of lock that RMS
puts on the records you access. ALLOW NONE specifies that
no other users can access this record (this is the default).
ALLOW READ lets other users read the record; however,
they cannot perform UPDATE or DELETE operations to this
record. ALLOW MODIFY specifies that other users can both
read and write to this record. This means that other access
streams can perform GET, DELETE, or UPDATE operations
to the specified record.
You can also specify a WAIT clause to the FIND state-
ment; this clause allows you to wait for a record to become
available in the event that it is currently locked by another
process. In addition, you can specify a REGARDLESS clause;
this clause allows you to read a locked record. For more in-
formation about the WAIT and REGARDLESS clauses, see
Section 14.6.9.