FIND: Verifying the Existence of a Value in a Data Source
Available Languages: MODIFY, Maintain
The FIND function determines if a data value is in a data source field being searched. The function sets a temporary field to 1 (a non-zero value for MODIFY) if the data value is found in the data source field, and to 0 if it is not. FIND does not change the searched file's current database position. A value greater than zero confirms the presence of the data value, not the number of instances in the data source field.
The FIND function determines if an incoming data value is in an indexed FOCUS data source field. The function sets a temporary field to a non-zero value if the incoming value is in the data source field, and to 0 if it is not. A value greater than zero confirms the presence of the data value, not the number of instances in the data source field.
You can also use FIND in a VALIDATE command to determine if a transaction field value exists in another FOCUS data source. If the field value is not in that data source, the function returns a value of 0, causing the validation test to fail and the request to reject the transaction.
You can use any number of FINDs in a COMPUTE or VALIDATE command. However, more FINDs increase processing time and require more buffer space in memory.
Limit: FIND does not work on files with different DBA passwords.
The opposite of FIND is NOT FIND. The NOT FIND function sets a temporary field to 1 if the incoming value is not in the data source and to 0 if the incoming value is in the data source.
Verify the Existence of a Value in a Data Source
FIND(fieldname [AS dbfield] IN file);
Is the name of the field that contains the incoming data value.
Is the name of the data source field whose values are compared to the incoming field values.
This field must be indexed. If the incoming field and the data source field have the same name, omit this phrase.
For Maintain - the AS field is required and the name must be qualified.
Is the name of the indexed FOCUS data source.
For Maintain - the IN file is unnecessary since the AS field name is required and must be qualified.
- FIND does not use an output argument.
- Do not include a space between FIND and the left parenthesis.
Verifying the Existence of a Value in Another Data Source (Maintain)
In the following example, FIND determines if a data value is found in another data source.
MAINTAIN FILE MOVIES AND VIDEOTRK FOR ALL NEXT MOVIES.MOVIECODE INTO FILMSTK TYPE "RC SHOULD BE 1 WHERE MOVIECODE EXISTS IN BOTH FILES"; TYPE " " COMPUTE RC/I1; COMPUTE I/I1=1; REPEAT FILMSTK.FOCCOUNT COMPUTE RC= FIND(FILMSTK(I).MOVIECODE AS VIDEOTRK.MOVIECODE) TYPE "FOR MOVIECODE = <<FILMSTK(I).MOVIECODE , RC = <<RC" COMPUTE I=I+1; ENDREPEAT END
The output is:
RC SHOULD BE 1 WHERE MOVIECODE EXISTS IN BOTH FILES FOR MOVIECODE = 001MCA, RC = 1 . . . FOR MOVIECODE = 387PLA, RC = 0 . . . FOR MOVIECODE = 963CBS, RC = 1 TRANSACTIONS: COMMITS = 1 ROLLBACKS = 0 SEGMENTS : INCLUDED = 0 UPDATED = 0 DELETED = 0
Verifying the Existence of a Value in the Same Data Source (Maintain)
In the following example, FIND determines if a data value is found in the same data source.
MAINTAIN FILE CAR
COMPUTE RETAIL_COST=31500;
COMPUTE CHECK/I1;
COMPUTE CHECK= FIND (RETAIL_COST);
IF CHECK = 1 THEN GOTO FOUND1
ELSE GOTO NOT1;
CASE FOUND1
TYPE "THERE IS A CAR WITH A RETAIL_COST OF <<RETAIL_COST"
-* ....
ENDCASE
CASE NOT1
TYPE "THERE IS NO CAR WITH A RETAIL_COST OF <<RETAIL_COST"
-*....
ENDCASE
-*....
END
The output is:
THERE IS A CAR WITH A RETAIL_COST OF 31,500 TRANSACTIONS: COMMITS = 1 ROLLBACKS = 0 SEGMENTS : INCLUDED = 0 UPDATED = 0 DELETED = 0