Adjust Cost Item Entries in NAV 4.0 SP3 - Endless Loop

mel_sadekmel_sadek Member Posts: 23
Hi all,

I have a client that is running into an endless loop when running Adjust Cost Item Entries on a few specific items. As is the case with these endless loop, the costing method is Average. And yes, I have read all of the relevant material here on MIBUSO and Microsoft's Hotfix in KB978605. I applied the recommended hotfix, but surprisingly, it didn't solve the problem. I also realized that the code Microsoft recommends to delete doesn't exist in the 5895 codeunit, even though the database and client are 4.3, so I did my best to apply the patch. Obviously, it's not working. I would like to get your opinion and advice on what may have went wrong in the hotfix patching. I enclosed the code that I patched below. Kindly please review the code and let me know if and where it went all wrong.

I sincerely appreciate all your efforts and help. This won't be forgotten.

AvgValueEntriesToAdjustExist:
...
  IF FIND('-') THEN BEGIN
    FindNextRange := TRUE;
    SETRANGE("Valuation Date","Valuation Date");
    REPEAT
      IF "Item Charge No." = '' THEN BEGIN
        IF "Valued By Average Cost" AND NOT Adjustment AND ("Valued Quantity" < 0) THEN BEGIN
          OutbndValueEntry := ValueEntry;
          OutbndValueEntry.INSERT;
          FindNextRange := FALSE;
        END;

// GRA1.01 - Add Start
// Add the following lines.
        IF ("Entry Type" = "Entry Type"::Revaluation) OR
        NOT (("Item Ledger Entry Type" = "Item Ledger Entry Type"::Transfer) AND
        InvtSetup.IsAvgCostCalcTypeItem)
        THEN BEGIN
          ExcludedValueEntry := ValueEntry;
          ExcludedValueEntry.INSERT;
        END;
// End of the added lines.
// GRA1.01 - Add End

// GRA1.01 - Delete Start
{
        IF "Partial Revaluation" OR "Valued By Average Cost" THEN BEGIN
          ExcludedValueEntry := ValueEntry;
          ExcludedValueEntry.INSERT;
        END;
}
// GRA1.01 - Delete End

      END;
    UNTIL NEXT = 0;
  END;

  IF FindNextRange THEN BEGIN
    AvgCostAdjmtEntryPoint."Valuation Date" := GetNextDate("Valuation Date");
    AvgValueEntriesToAdjustExist(OutbndValueEntry,ExcludedValueEntry,AvgCostAdjmtEntryPoint);
  END;
...

IsExcludeEntryFromAvgCostCalc:
...
WITH ValueEntry DO BEGIN
  IF "Partial Revaluation" THEN
    EXIT(TRUE);

  IF "Item Ledger Entry No." = OutbndValueEntry."Item Ledger Entry No." THEN
    EXIT(TRUE);

// GRA1.01 - Add Start
  IF "Item Ledger Entry Type" = "Item Ledger Entry Type"::Transfer THEN

    IF Adjustment AND ("Applies-to Entry" < OutbndValueEntry."Entry No.") THEN
      EXIT(FALSE);
// GRA1.01 - Add End

  IF NOT "Valued By Average Cost" THEN
    EXIT(FALSE);

// GRA1.01 - Delete Start
{
  IF NOT InvtSetup.IsAvgCostCalcTypeItem AND
     ("Item Ledger Entry Type" = "Item Ledger Entry Type"::Transfer) AND
     ("Valued Quantity" >= 0)
  THEN
    EXIT(FALSE);
}
// GRA1.01 - Delete End
...

UpdateAvgCostAdjmtEntryPoint:
...
// GRA1.01 - Delete Start
{
AvgCostAdjmtEntryPoint.UpdateValuationDate(
  ValueEntry,IsAvgCostItem,InvtSetup.IsAvgCostCalcTypeItem);
}
// GRA1.01 - Delete End

// GRA1.01 - Add Start
// Add the following lines.
IF (ValueEntry."Item Ledger Entry Type" = ValueEntry."Item Ledger Entry Type"::Transfer) AND
    InvtSetup.IsAvgCostCalcTypeItem
THEN
  EXIT;

AvgCostAdjmtEntryPoint.UpdateValuationDate(ValueEntry,IsAvgCostItem,InvtSetup.IsAvgCostCalcTypeItem);
// End of the added lines.
// GRA1.01 - Add End

Comments

  • herrlutzherrlutz Member Posts: 58
    Is the database a new implementation? Did you just update from a previous version? Why does the problem appear right now?

    I've experienced, that endless loops can appear when entries are manipulated incorrectly. Such as deleted item ledger entries or modified closed by entry no field. The same for item application entries.
    You can trace the entries causing the problem using the debugger. Then check if all fields and relations are plausible.
    Here its helpful if you would run adjust cost for only that item which causes the problem. I could give you a code for that on tuesday
  • mel_sadekmel_sadek Member Posts: 23
    Hi herrlutz,

    Thanks for the quick feedback. To answer your last point, yes I am running the Adjust Cost Item Entries routine for a singular item. The modification put in is similar to the way it was implemented in NAV 5.0, and it's also similar to how ara3n coded it on this forum. So no worries there... :)

    Regarding the database, this was not a new implementation, and it has been going on for a while actually. I used the debugger and was able to find several value entries that the system keeps looping through time and time again. I know how many there are and what they are. The main challenge here is that I wasn't around when any potential manipulation was done to the system :(, so I cannot figure out where to start. However, maybe correcting the code above (if there's something wrong with it) would be a good start to solving this mystery.
  • raveendran.sraveendran.s Member Posts: 119
    are you using Manufacturing? If yes, by any chance you posted the Consumption and output has the same item? In one my client place the same thing happened and Adjust cost item entries was keep on going in the loop. Finally we found out and resolved.
    --
    Regards,
    Raveendran.BS
  • mel_sadekmel_sadek Member Posts: 23
    Hi Raveendran,

    The client doesn't use manfuacturing, however one of the items in question that loops endlessly has an assembly BOM. I did take Rashed's advice and ran the Adjust Cost Item Entries report on all components of an item before running it on the master item. Interestingly enough, all components finished adjustment almost instantaneously, but the master item just kept looping endlessly.
  • mel_sadekmel_sadek Member Posts: 23
    Reveendran, herrlutz...any updates from your side?

    Anybody else might have a beat on this?
  • ouredpouredp Member Posts: 56
    Hello,

    We run in an endless Loop caused by a blank Item Number in Tab27 some times ago.
    We put Cost is Adjusted = true in this record.
  • rdebathrdebath Member Posts: 383
    There is something wrong with the creation of Item application entries in NAV. It's a very rare problem but it does occur with unmodified code. It seems to be possibly related to average costing and systems that frequently have the Navision stock level going negative.

    If you trace through the "Item application entry" records starting from the Item ledger entry numbers that have the "Applied item to adjust" flag set you should find a loop.

    Break the loop.

    It's a protected table so you'll need a dev license.
Sign In or Register to comment.