for each while

richhcir3

New Member
I was wondering if someone could explain how 'for each while' actually works.

I found some code written by Tom Bascon that suggested using for each _lock no-lock while _lock-usr <> ?:

how exactly does using while differ from using where?

I tried the following code for each _trans no-lock while _Trans-Usrnum <> ?: and it returned no results, however replacing while with where did produce results.

I'm planning on reading the _lock table so I'd like to do as Tom advises but I'd also like to be sure that I'm not missing some records.

Thanks,

Rich
 
_lock table actually is array. And it works very slow.

for each _lock no_lock:
if _lock-usr = ? then leave. /* this is just a method to make script work fast */
end.
 
so why would for each while be quicker than for each where?

And why do the two produce different results in my for each _trans example?

Cheers,

Rich
 
cause it fetch not all record, it fetch it until condition under while is true.
There is a big chance that there are "holes" in lock table where lock_usr = ? and after there are records with lock_usr <> ?
But while restrict to get them. It works until first "hole".
 
cause it fetch not all record, it fetch it until condition under while is true.
There is a big chance that there are "holes" in lock table where lock_usr = ? and after there are records with lock_usr <> ?
But while restrict to get them. It works until first "hole".

Actually I think it is a linked list. There are no holes. Once you hit a lock_usr of ? there will not be any more valid locks. And lock entries move as earlier locks are released...
 
Tom, we have almost the same code that monitors what documents are locked by different users. And I noticed that sometimes it didn't show all locking. Ordinarily it happens when users are locked a lot of records (let's say 5000+)
 
Back
Top