CAN-FIND function
Returns a TRUE value if a record is found that meets the specified FIND criteria; otherwise it returns FALSE. CAN-FIND does not make the record available to the procedure. You typically use the CAN-FIND function within a VALIDATE option in a data handling statement, such as the UPDATE statement.
You can use CAN-FIND to see if a record exists with less system overhead than that of a FIND statement. The query capabilities are similar. CAN-FIND is also useful for implementing inner joins among database tables.
Syntax
You can specify the OF, WHERE, USE-INDEX, and USING options in any order.
FIRSTLASTrecord
The record buffer you are checking for existence.To use CAN-FIND to locate a record in a table defined for multiple databases, you might have to qualify the record’s table name with the database name. See the Record phrase reference entry for more information.constant
OFtable
WHEREexpression
USE-INDEXindex
USING [ FRAMEframe
]field
[ AND [ FRAMEframe
]field
]SHARE-LOCK
Specifies that CAN-FIND determines whether the record can be SHARE-LOCKed. If you use this option without the NO-WAIT option, and if the record is EXCLUSIVE-LOCKed, CAN-FIND waits until that lock is released before returning. If you use SHARE-LOCK with the NO-WAIT option, then CAN-FIND returns a FALSE value immediately if the record is EXCLUSIVE-LOCKed.NO-LOCKNO-WAITNO-PREFETCHExampleIn the following procedure, the UPDATE statement uses the VALIDATE option to make sure that the salesrep entered matches one of the salesreps in the database. The VALIDATE option uses the CAN-FIND function to find the record.
Notes
- Fields do not have to be indexed to use them in a CAN-FIND function. For example, you can use the following CAN-FIND function with the
sports2000
database, even though theState
field is not indexed:
However, when you use CAN-FIND on a non-indexed field, the response might be slow, as with a FIND.- You can name more than one field as part of the selection criteria. For example, the following CAN-FIND function works with the
sports2000
database:
- CAN-FIND supports selection criteria that uses inequality matches. Therefore, you can use Boolean operations in WHERE clauses.
- EXCLUSIVE lock is not allowed in a CAN-FIND because CAN-FIND does not return a record.
- If you use the CAN-FIND function to find a record in a work table, the AVM disregards the NO-WAIT, SHARE-LOCK, and NO-LOCK options.
- You can nest CAN-FIND functions. For example, you can use CAN-FIND(... WHERE CAN-FIND(...WHERE CAN-FIND, etc.
- The CAN-FIND function does not cause FIND triggers to execute; hence a procedure can use this function to bypass the FIND trigger and check for the existence of records. Anyone writing a FIND trigger for security reasons should be aware of this.
- You cannot use the CAN-FIND function in a query’s WHERE clause. Doing so generates a compiler error.
- Within a CAN-FIND function, if you compare tables or fields from multiple databases, you must explicitly specify the database name along with the table and field name.
See also
OpenEdge Release 10.2B
|