CAN-FIND function
- Last Updated: February 11, 2026
- 4 minute read
- OpenEdge
- Version 13.0
- Documentation
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.
- FIRST
- Returns TRUE if
CAN-FINDlocates a record that meets the specified criteria; otherwise returns FALSE. - LAST
- Returns TRUE if
CAN-FINDlocates a record that meets the specified criteria; otherwise returns FALSE. - record
- The record buffer you are checking for existence.
To use
CAN-FINDto 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 definition in the Record phrase reference entry for more information. - constant
- The table you want to use has a primary index; the constant is the value of the last component field of that index for the record you want.
- OF table
- Qualifies the records to use by relating the record to a record in another table.
- WHERE expression
- Qualifies the record that
CAN-FINDsearches for. The expression must return a TRUE or FALSE value. - USE-INDEX index
- Identifies the index you want
CAN-FINDto use to find a record. If you do not use this argument, the AVM selects an index to use based on the criteria specified with theWHERE,USING,OF, or constant arguments. - USING [ FRAME frame ] field [ AND [ FRAME frame ] field ]
- One or more names of fields you want to use to search for a record.
The field you name in this argument must have been previously entered into a screen
field, usually with a
PROMPT-FORstatement. The field must be viewed as a fill-in or text widget. - SHARE-LOCK
- Specifies that
CAN-FINDdetermines whether the record can beSHARE-LOCKed. If you use this option without theNO-WAIToption, and if the record isEXCLUSIVE-LOCKed,CAN-FINDwaits until that lock is released before returning. If you useSHARE-LOCKwith theNO-WAIToption, thenCAN-FINDreturns a FALSE value immediately if the record isEXCLUSIVE-LOCKed. - NO-LOCK
- Specifies that
CAN-FINDdetermines whether the record can be accessed with theNO-LOCKoption. This is the default forCAN-FIND. - NO-WAIT
- Causes
CAN-FINDto return immediately and return FALSE if the record is locked by another user.If you use
NO-WAITtogether with aSHARE-LOCKand the record found isEXCLUSIVE-LOCKed, theCAN-FINDfunction does not wait and returns FALSE. - NO-PREFETCH
- Specifies that only one record can be sent across the network at a time. If you do not specify this option, the AVM might send more than one record from the server to the client in each network packet.
Example
In 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.
r-canfnd.p
|
Notes
- Fields do not have to be indexed to use them in a
CAN-FINDfunction. For example, you can use the followingCAN-FINDfunction with theSports2020database, even though theStatefield is not indexed:CAN-FIND(FIRST Customer WHERE Customer.State = "NH")However, when you use
CAN-FINDon a non-indexed field, the response might be slow, as with aFIND. - You can name more than one field as part of the selection criteria. For
example, the following
CAN-FINDfunction works with theSports2020database:CAN-FIND(Customer WHERE Customer.CustNum = x AND Customer.Name = y) CAN-FINDsupports selection criteria that uses inequality matches. Therefore, you can use Boolean operations inWHEREclauses.EXCLUSIVE-LOCKis not allowed in aCAN-FINDbecauseCAN-FINDdoes not return a record.- If you use the
CAN-FINDfunction to find a record in a work table, the AVM disregards theNO-WAIT,SHARE-LOCK, andNO-LOCKoptions. - You can nest
CAN-FINDfunctions. For example, you can useCAN-FIND(... WHERE CAN-FIND(...WHERE CAN-FIND, etc. - The
CAN-FINDfunction does not causeFINDtriggers to execute; hence a procedure can use this function to bypass theFINDtrigger and check for the existence of records. Anyone writing aFINDtrigger for security reasons should be aware of this. - You cannot use the
CAN-FINDfunction in a query'sWHEREclause. Doing so generates a compiler error. - Within a
CAN-FINDfunction, if you compare tables or fields from multiple databases, you must explicitly specify the database name along with the table and field name. CAN-FINDdoes not raise a run-time error if the buffers in its predicate are unavailable. Developers should check for record availability when using outside buffers for comparison in aCAN-FINDstatement and ensure that the buffer contains the expected value prior to using it so that theCAN-FINDfunction correctly reports the record availability.CAN-FINDmay fail to find a newly created record. For example, in the following code,CAN-FINDreturns NO when you may have expected it to return YES:
In this example, the record is not written to the database and the index is not updated because the field value has not actually changed, and the ABL client delays the record write to the database. You can execute aDEF TEMP-TABLE tCustomer NO-UNDO FIELD CustCode AS CHAR INIT "A" INDEX iCustCode IS PRIMARY UNIQUE CustCode. CREATE tCustomer. ASSIGN tCustomer.CustCode = "A". MESSAGE "CAN-FIND: " CAN-FIND(FIRST tCustomer) VIEW-AS ALERT-BOX INFO BUTTONS OK.RELEASE,VALIDATE, orFINDon the buffer before usingCAN-FIND, which forces indexing and writing of the record to the database.