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...
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!
Answers
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
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...
Dynamics NAV MVP (2005-2010)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Thanks for all the help!
No one loves you like the one who created you...
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. :-)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.