KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using Sets instead of GOTO RECORD with record numbers
PRODUCT: 4D | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: August 24, 2001

If you have a record number and want to retrieve the current record from this record number, you can use the GOTO RECORD command.

About Record Numbers
https://ftp.4d.com/aci_Technical_notes/ACIDOC/CMU/CMU10061.HTM

However, an error will be returned if you provide a non-valid record number. This can happen if you request record 5000 when your table does not contain any record with record number = 5000. The unique way to catch this error is to use an ON ERR CALL system. In this system, you can catch this error and set up some variables before resuming your code.

However, you may already have an existing ON ERR CALL system and might not want to modify it in order to handle this situation. In that case, there is another elegant way to do this by using a BOOLEAN ARRAY, and the commands CREATE SET FROM ARRAY and USE SET. Instead of using GOTO RECORD, you can create and use sets. If you test the set with RECORDS IN SET, you will notice that the created set is not empty. However, if you use the set, you may retrieve an empty selection if the record numbers are not valid.

$RecNumToTest:=5000
ARRAY BOOLEAN($Array;$RecNumToTest)
Array{$RecNumToTest}:=True
CREATE SET FROM ARRAY([MyTable];$Array;"Myset")
USE SET("MySet")
If (Records in selection([MyTable])=0)
   ` The record number does not exist
Else
   ` The records number is valid. The record has been retrieved
End if