Comparing 2 instances of a Table not working!

Saint-Sage
Member Posts: 92
Hello Everyone,
I usually work in 4.0, and in that version, if you want to compare entries from the same table, you can simply nest a second instance of the table within a loop and can reset, setfilters on the second instance without affecting the instance in the outter loop.
Unfortunatly I am having to write a codeunit for 2.6 to repair some entries to the Item Ledger Table and I am having a problem. Here a pseudo example of the code...
The problem I am having is that it enters an infinate loop. After some debugging, I realized that the Entry Number at the top of the outer loop is always the same each pass through.
This makes me think that when I setrange in the second instance to the single record in the outter loop, it is giving me a recordset that only has the single record in it, and navision is unable to determine NEXT = 0 for some reason.
If anyone can shed some light on why this is happening, or how you are supposed to compare nested instances of the same table in 2.6 please let me know.
Any help you can give will be greatly appriciated.
Have a great day!
I usually work in 4.0, and in that version, if you want to compare entries from the same table, you can simply nest a second instance of the table within a loop and can reset, setfilters on the second instance without affecting the instance in the outter loop.
Unfortunatly I am having to write a codeunit for 2.6 to repair some entries to the Item Ledger Table and I am having a problem. Here a pseudo example of the code...
ItemLedger.RESET; ItemLedger.SETRANGE(blah blah) IF ItemLedger.FIND('-') THEN BEGIN REPEAT ItemLedger2.RESET; ItemLedger2.SETRANGE("Item No.", ItemLedger."Item No."); IF ItemLedger2.FIND('-') THEN BEGIN REPEAT InvoiceBalance += ItemLedger2."Amount"; UNTIL ItemLedger2.NEXT = 0; // Terminate Inner Loop END; // End IF ItemLedger2.FIND //Increment some stuff... IF InvoiceBalance <> 0 THEN BEGIN // Do some stuff... END; UNTIL ItemLedger.NEXT = 0; // Terminate Outter Loop END; // End IF ItemLedger.FIND
The problem I am having is that it enters an infinate loop. After some debugging, I realized that the Entry Number at the top of the outer loop is always the same each pass through.
This makes me think that when I setrange in the second instance to the single record in the outter loop, it is giving me a recordset that only has the single record in it, and navision is unable to determine NEXT = 0 for some reason.
If anyone can shed some light on why this is happening, or how you are supposed to compare nested instances of the same table in 2.6 please let me know.
Any help you can give will be greatly appriciated.
Have a great day!
No one loves you like the one who created you...
0
Answers
-
Sorry, but I can see just one repeat but two until keywords in your code. And please, use the [ code ] tag to format the code in your posts.0
-
Sorry for the poor formatting.
The repeat is there in the original code, I must have left it off when typing out this algorithm, I figured it was pretty straight forward as to what I was doing.
Thanks for the reply!
No one loves you like the one who created you...0 -
Are you sure that while you are doing some stuff, you aren't altering the bla, bla filter?Anna Perotti
Dynamics NAV MVP (2005-2010)0 -
If this is not COPY&PASTE code, look into your original code if there is correct variable in the UNTIL line ( ItemLedger2. in first one and ItemLedger. in second one) - it is common mistake when the code is created by Copy&Paste.0
-
I was modifying a single field (Quantity) in the composite key I had selected. Evidently this behaves as if I was modifying the primary key inside the loop. When I modified the key to not include quantity, it slowed things down, but it works as expected now.
Thanks for all the help!
No one loves you like the one who created you...0 -
Saint-Sage wrote:I was modifying a single field (Quantity) in the composite key I had selected. Evidently this behaves as if I was modifying the primary key inside the loop. When I modified the key to not include quantity, it slowed things down, but it works as expected now.
Thanks for all the help!
Never modify the rec variable which is used in the loop as iterator. Use other rec variable for that. It is golden rule for NAV. :-)0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions