xHarbour Reference Documentation > Command Reference |
Scans the current work area for a record matching a condition.
LOCATE [<Scope>] FOR <lForCondition> ; [WHILE <lWhileCondition>] ;
The LOCATE command sequentially scans the records in current work area and stops if a record matching the FOR condition is found. In this case, function Found() returns .T. (true). When no match is found, or when the WHILE condition yields .F. (false), or when the record pointer gets out of scope, Found() return .F. (false), and the scan stops.
If a record matching the FOR condition is found, it becomes the current one. The search can then be continued using the CONTINUE command to find the next matching record. Hence, the FOR condition of the LOCATE command remains active for subsequent CONTINUE commands. Each work area may have its own LOCATE condition, which is persistent until a new LOCATE command is issued or the work area is closed. Note, however, that scope and WHILE condition are not available for a subsequent CONTINUE command.
Both commands, LOCATE and CONTINUE, can be used very flexible for performing complex searches that do not rely on an indexed database. Since the records in the current database are scanned sequentially, a search with LOCATE/CONTINUE can be time consuming. A search on an indexed database with SEEK is much faster but has the drawback of a less flexible search condition.
See also: | CONTINUE, DbSeek(), Eof(), Found(), SEEK, SET FILTER, SET SCOPE |
Category: | Database commands |
Source: | rdd\dbcmd.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example uses LOCATE and CONTINUE to list customers // living in the city of New York. PROCEDURE MAIN LOCAL cCity := "New York" FIELD FirstName, LastName USE Customer NEW LOCATE FOR Upper(FIELD->City) = Upper(cCity) DO WHILE Found() ? LastName, FirstName CONTINUE ENDDO CLOSE Customer RETURN
http://www.xHarbour.com