SETCURRENTKEY causes exit from loop
Fommo
Member Posts: 138
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:
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
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
0
Answers
-
I can't see REPEAT in your code.
0 -
vijay_g wrote:I can't see REPEAT in your code.

True, of course there is a REPEAT.
The complete code here again:MySalesOrders.RESET; MySalesOrders.SETCURRENTKEY(Status); MySalesOrders.SETRANGE(Status,MySalesOrders.Status::OK); NoOfRecs := ROUND((MySalesOrders.COUNT/100),1,'>'); IF MySalesOrders.FINDSET THEN BEGIN // Doing some dialog updates that doesn't affect the dataset REPEAT .. UNTIL MySalesOrders.NEXT = 0; END;
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?0 -
Are you changing the value of "Status" for the current MySalesOrders record in your REPEAT-UNTIL loop?There are no bugs - only undocumented features.0
-
And if you are changing the Status in REPEAT UNTIL then do this.
NewSalesOrders.GET(MySalesOrders); NewSalesOrders.Status := NewStatus; NewSalesOrders.Modify;
You can also use FINDSET(FALSE,TRUE); to know more about parameter of FINDSET see the help(F1).0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions