>>However, for a message thread, if you intend to become as popular as this place... you better go recursive and build these keys on your selected data, not on your underlying table, or don't build any keys, just copy records into an empty cursor one by one, going recursively over your original data.
>>
>>Or go recursively and assign them ordinal numbers as you go, then index by this ordinal number. That would be the simplest.
>
>Thanks for confirming my thoughts Dragan. After sleeping on the issue I came to the same conclusion while driving to work (I had not read UT at that time<s>).
>Again thank you for your analysis and advise.
This is roughly (I had to remove some special-case lines) the code I've found works the fastest so far for recursion. Order the table on nParent. Stek[] array and stekptr variable need to be private to the calling procedure - it keeps the record to return to. The skeleton for this was written in 1989, I'd probably do it much shorter now and use properties instead. Or probably I already did, but can't find the better version anymore :).
procedure scan_1(_key)
local _nkey
StekPtr=StekPtr+1
DIME stek(StekPtr)
=SEEK(_key)
SCAN WHILE nParent=_key
stek(StekPtr)=RECNO()
_nkey=nMessageId
this.scan_1 (_nkey)
GO stek(StekPtr)
ENDSCAN
StekPtr=StekPtr-1