LOCATE
Locates a particular member of a result set and makes it the current member.
Syntax
LOCATE [num] [set] [WHERE clause]
Parameters
num | The number of records to be located. Num can be an integer constant (e.g., 15, 200); a variable, form field, menu item, or formal parameter that evaluates to an integer; the word ALL. The default value for num is 1. |
set | The name of a result set. If not specified, the current set (if it exists) is used. |
Comments
LOCATE starts searching at the current member of the set. The last member located becomes the current member of set. The system variable $Located is set to the number of members located, indicating the number of members in the result set.
The WHERE clause can be used to logically limit the members located.
Example
find all employees where location=”Detroit” -> DetroitSet
locate DetroitSet where FirstName=”John” and LastName=”Smith”
locate 2 DetroitSet where FirstName=”John” and LastName=”Smith”
Because LOCATE starts with the current member of any set it searches, the current member after the last LOCATE command is the third record containing the name John Smith.
find all Employees where LastName=”Smith” -> Smiths
locate all where FirstName=”John”
output $located
compute all Employees where LastName=”Smith” and FirstName=”John” valuate (“”)
output $membercount
find all Employees where LastName=”Smith” and FirstName=”John”
output $setcount
All three of the preceding examples determine how many employees have the name John Smith.
while
locate DetroitSet where LastName=”Smith” and FirstName=”John”
if $located = 0
return % checks if done
endif
ProcessEmp ( ) % program to process this John Smith
endwhile
Each John Smith record in the designated set is processed.