Your example shows this code to read all the records in the Customer file in KeyCusNumber sequence:

The SET() statement has 7 ways to read a File, so it can be confusing. One (File,Key) should never used, it often ends up in code when GET(File,Key) changes to SET() without making it SET(Key,Key).
Your code is using SET(Key,Key)
which will Seek (read index pages) in Key order the Record that matches the Key’s component field “current values” or is greater than. You did a ClearKey() so the “current values” in the key fields will be set to Low (or High for descending -fields).
There is a simpler way of using SET( Key )
note the (Key) only appears once. This always starts with the First record in Key order. It does not do the work of Seeking a matching record, no index pages are read. There is no need to ClearKey() or Clear(Record) because those field values are not used.
In summary SET( Key )
is a simpler faster way to start with the First record than using SET(Key,Key)
which does a seek reading the index and comparing.
The revised code to read all would be:
Access:Customer.Open()
!no need -->Access:Customer.ClearKey(CUS:KEYCUSTNUMBER)
SET( CUS:KEYCUSTNUMBER ) !<-- note just (Key) ... sets the order
i = 0 ! Record counter
LOOP UNTIL Access:Customer.Next() <> Level:Benign ! CUS loop
!// Process each customer record
i += 1 ! Count the records
ud.Debug('Customer: ' & CUS:CustNumber & ' Company: ' & clip(CUS:Company))
END ! CUS loop
The simplest is SET( File )
which processes in file record order, so nothing meaningful. I think of this as the most efficient way to read all the records, but I have no knowledge that IS the most efficient. You would have to understand how the specific DB stores records.
I would guess most SQL store records by Primary Key so SET( File:PrimaryKey ) may be most efficient. Would be interesting if anyone knows? FYI the question moved to this New Topic on MSSQL.
One other thing to look at is File Manager .UseFile().