Codeunit 22 - ApplyItemLedgEntry() - error

DeSpDeSp 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
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

Comments

  • kauffmannkauffmann Member Posts: 56
    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 blog
  • DeSpDeSp Member Posts: 105
    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 desperandum
  • kinekine Member Posts: 12,562
    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...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DeSpDeSp Member Posts: 105
    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 desperandum
  • kinekine Member Posts: 12,562
    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... :-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DeSpDeSp Member Posts: 105
    Thanks, I'll try it :)
    Nil desperandum
Sign In or Register to comment.