Kbase 6186: How to use the CAN-FIND statement
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/10/1998 |
|
How to use the CAN-FIND statement
920217-cmb02
INTRODUCTION:
=============
This Progress Software Technical Support Knowledgebase entry explains
how the CAN-FIND function works.
PROCEDURAL APPROACH:
====================
The CAN-FIND function returns a value of TRUE if it finds a record
that meets the specified FIND criteria. This function does
NOT make the record available to the procedure. Typically,
the CAN-FIND function is used within a VALIDATE option in a
data handling statement such as UPDATE. The CAN-FIND function
ONLY returns TRUE if it finds ONE AND ONLY ONE record that
matches the criteria. If the solution were multiple records, you
would receive a compile-time error. Below are some examples of
CAN-FIND statements and their results.
1. CREATE order.
SET cust-num
VALIDATE(CAN-FIND(cust WHERE cust.cust-num = INPUT cust-num),
"This Customer Number does not exist in the customer file").
This procedure returns a TRUE statement and allows the
"cust-num" field in the order file to be accepted if there
exists ONLY ONE record in the customer file that has the same
value for "cust-num" that the user is trying to input. If the
CAN-FIND statement does not return a TRUE value (for one of
the reasons listed below) then the message within quotes
displays at the message line and the user is prompted
again to enter the "cust-num" field. The user cannot
continue on within the application without entering
a value for this field that is accepted by the
VALIDATE statement.
2. FIND FIRST customer.
UPDATE customer.st.
IF NOT(CAN-FIND state OF customer) then
DO:
MESSAGE "The state you entered was not valid".
UNDO, RETRY.
END.
This procedure returns a TRUE statement ONLY if PROGRESS
finds ONE record in in the state file that corresponds to
the customer record being updated. PROGRESS uses the
indexes in both files to find the match, therefore there MUST
be an index in both files on the field being matched (in this
example the "st" field).
The CAN-FIND statement works like a FIND statement, so you can use
the keywords "FIRST" and "LAST" in the CAN-FIND statement.
ONLINE PROCEDURES OR UTILITIES:
===============================
PROGRESS Help, Option 5. (Functions)
REFERENCES TO WRITTEN DOCUMENTATION:
====================================
PROGRESS Language Reference Guide, Page 68 (CAN-FIND Function)
PROGRESS Language Reference Guide, Page 546 (VALIDATE Statement)
Progress Software Technical Support Note # 6186