Codeunit 22 - ApplyItemLedgEntry() - error

DeSp
Member Posts: 105
We use Navision 3.70A SQL Server option.
Sometimes invoices we try to post give an error message: "Item Tracking Serial No. <...> Lot No. <...> for Item No. <...> Variant cannot be fully applied". I turned the debugger on and followed through the code in Codeunit 22 - ApplyItemLedgEntry(). There I saw a strange thing happend with a record variable ItemLedgEntry2. At the beginning we put some filters on it and make a FIND('-') - we get two records in the dataset and the variable points at the first record of it. Then we make a copy of ItemLedgEntry2 to OldItemLedgEntry.
Then we modify the "Open" field of OldItemLedgEntry which is a current key field of ItemLedgEntry2. As I get it, nothing should be changed within ItemLedgEntry2, despite on a new value of "Open" key field - we still must have two records in our dataset assosiated with ItemLedgEntry2. On the second step of the REPEAT/UNTIL loop we must step to the second record of ItemLedgEntry2 (I suppose it still must be there - dataset remains the same) but this
I try to simulate this issue but my code runs correctly:
I don't understand what is wrong in Codeunit 22 - ApplyItemLedgEntry().
Any suggestions will be very much appreciated.
Thanks in advance.
Sometimes invoices we try to post give an error message: "Item Tracking Serial No. <...> Lot No. <...> for Item No. <...> Variant cannot be fully applied". I turned the debugger on and followed through the code in Codeunit 22 - ApplyItemLedgEntry(). There I saw a strange thing happend with a record variable ItemLedgEntry2. At the beginning we put some filters on it and make a FIND('-') - we get two records in the dataset and the variable points at the first record of it. Then we make a copy of ItemLedgEntry2 to OldItemLedgEntry.
Then we modify the "Open" field of OldItemLedgEntry which is a current key field of ItemLedgEntry2. As I get it, nothing should be changed within ItemLedgEntry2, despite on a new value of "Open" key field - we still must have two records in our dataset assosiated with ItemLedgEntry2. On the second step of the REPEAT/UNTIL loop we must step to the second record of ItemLedgEntry2 (I suppose it still must be there - dataset remains the same) but this
IF ItemLedgEntry2.NEXT =0 THEN EXIT;line of code exits the codeunit somehow. So, as we don't process the second record of ItemLedgEntry2 we have an error described in the topic title.
I try to simulate this issue but my code runs correctly:
ItemLedgEntry2.RESET; ItemLedgEntry2.SETCURRENTKEY("Item No.","Variant Code",Open,Positive,"Location Code","Posting Date"); ItemLedgEntry2.SETRANGE("Item No.",'6946'); ItemLedgEntry2.SETRANGE("Variant Code",''); ItemLedgEntry2.SETRANGE(Open,TRUE); ItemLedgEntry2.SETRANGE(Positive,TRUE); ItemLedgEntry2.SETRANGE("Location Code",'CENTER'); ItemLedgEntry2.SETRANGE("Lot No.",'000907/1970905'); ItemLedgEntry2.SETFILTER("Entry No.",'<>%1',186145); IF ItemLedgEntry2.FIND('-') THEN BEGIN MESSAGE('%1',ItemLedgEntry2.COUNT); // =2 records OldItemLedgEntry.COPY(ItemLedgEntry2); OldItemLedgEntry.Open := FALSE; OldItemLedgEntry.MODIFY; REPEAT MESSAGE('Before=%1',ItemLedgEntry2."Entry No."); MESSAGE('STEP'); // = appears 2 times IF ItemLedgEntry2.NEXT=0 THEN BEGIN MESSAGE('NONE'); EXIT; END; MESSAGE('After=%1',ItemLedgEntry2."Entry No."); OldItemLedgEntry.COPY(ItemLedgEntry2); OldItemLedgEntry.Open := FALSE; OldItemLedgEntry.MODIFY; UNTIL FALSE; MESSAGE('%1',ItemLedgEntry2.COUNT); END;
I don't understand what is wrong in Codeunit 22 - ApplyItemLedgEntry().
Any suggestions will be very much appreciated.
Thanks in advance.
Nil desperandum
0
Comments
-
Maybe the recordset ItemLedgEntry2 is loosing its pointer, due to the MODIFY (is a known Navision-SQL bug).
The next solution is probably worth to try (where LastEntryNo is a new variable, type Integer):REPEAT MESSAGE('Before=%1',ItemLedgEntry2."Entry No."); MESSAGE('STEP'); // = appears 2 times ItemLedgEntry2.GET(LastEntryNo); //NEW IF ItemLedgEntry2.NEXT=0 THEN BEGIN MESSAGE('NONE'); EXIT; END; MESSAGE('After=%1',ItemLedgEntry2."Entry No."); OldItemLedgEntry.COPY(ItemLedgEntry2); OldItemLedgEntry.Open := FALSE; OldItemLedgEntry.MODIFY; LastEntryNo := ItemLedgEntry2."Entry No."; //NEW UNTIL FALSE;
A good programmer makes al the right mistakes
My blog0 -
Thanks for you answer, kauffmann.
What is a nature of this bug? Is there a detail description of it and some solution to fix it?Nil desperandum0 -
This is bug about MS SQl that sometime is not "seeing" some records. You can prevent this problem with hack I wrote in my last post in this thread:
http://www.mibuso.com/forum/viewtopic.php?t=6267
It is working, I spend few hours looking for source of same problem on site, after I used this hack, all was working correctly...0 -
Thanks a lot, kine!
Yep, it really worked. I had a value of 65535 in the "Diagnostics" field, I set it manually as I read about it from Navision KB at the partnersource once - it fixes BULK INSERT bug. But I don't know what things does this value affect. Does anyone know what is the purpose of this field and its different values in the "$ndo$property" table?Nil desperandum0 -
If you had 65535 there, try to set it to 196607 (65535 bit or 131072). It is some Magic value for internal work of Navision. What does it mean knows only the one who programmed Navision client... :-)0
-
Thanks, I'll try itNil desperandum0
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