select a_alias * Things will be faster if you do not set the order, * unless of course you need to index for something set order to tagname * Find your first match locate for field1 = variable and field2 = variable2 DO while FOUND() &&This loop will continue until the LOCATE fails do some stuff CONTINUE && This is the command to find the next record that matches your locate condition ENDDO && this is the correct command to close a DO WHILE loopNow the SCAN/ENDSCAN suggestion is a better way to do what you want. The reason your code failed is that each time you looped back and executed the LOCATE it started from the top of the file again.