Hi
I have a strange problem. I'm trying to optimize some code for a customer. It's based on a table that has a field "Status" and I only want to process those with a certain status. So I added a key for Status and then I try to run this code:
MySalesOrders.RESET;
MySalesOrders.SETCURRENTKEY(Status);
MySalesOrders.SETRANGE(Status,MySalesOrders.Status::OK);
NoOfRecs := ROUND((MySalesOrders.COUNT/100),1,'>');
IF MySalesOrders.FINDSET THEN BEGIN
..
UNTIL MySalesOrders.NEXT = 0;
The problem is that when I run this it ends the loop after one iteration. NoOfRecs get a value of 66 so there are records to iterate.
If I remove SETCURRENTKEY it works, although bad performance.
I think the code is pretty simple. Do you have any ideas? What can make the key go crazy? Can it be fragmentation that gives the key wrong information about the dataset?
/Simon
Answers
True, of course there is a REPEAT.
The complete code here again:
The client is running NAV 2009 R2 (build 32012), that is NO application updates are implemented. I searched for some hotfixes that may affect SETCURRENTKEY or NEXT, but I didn't find any.
Does anyone know about such a hotfix?
You can also use FINDSET(FALSE,TRUE); to know more about parameter of FINDSET see the help(F1).
Thanks a lot for the suggestion, works like a charm now.