You experience slow performance when you run the "Adjust cost item entries" batch job in Microsoft Dynamics NAV

Applies to: Microsoft Dynamics NAV 2009 R2Dynamics NAV 2009 Service Pack 1Microsoft Dynamics NAV 5.0 Service Pack 1

This article applies to Microsoft Dynamics NAV for all countries and all language locales.

Symptoms


When you run the "Adjust cost item entries" batch job, you experience slow performance when items that use Average costing method and frequent usage of Transfers are adjusted. This problem occurs in the following products:
  • Microsoft Dynamics NAV 2009 R2
  • Microsoft Dynamics NAV 2009 Service Pack 1
  • Microsoft Dynamics NAV 2009
  • Microsoft Dynamics NAV 5.0 Service Pack 1

Resolution


Hotfix information

A supported hotfix is now available from Microsoft. However, it is only intended to correct the problem that is described in this article. Apply it only to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Microsoft Dynamics NAV 2009 service pack or the next Microsoft Dynamics NAV version that contains this hotfix.

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Technical Support Professional for Microsoft Dynamics and related products determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.



Installation information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Note Before you install this hotfix, verify that all Microsoft Navision client users are logged off the system. This includes Microsoft Navision Application Services (NAS) client users. You should be the only client user who is logged on when you implement this hotfix.

To implement this hotfix, you must have a developer license.

We recommend that the user account in the Windows Logins window or in the Database Logins window be assigned the "SUPER" role ID. If the user account cannot be assigned the "SUPER" role ID, you must verify that the user account has the following permissions:
  • The Modify permission for the object that you will be changing.
  • The Execute permission for the System Object ID 5210 object and for the System Object ID 9015 object.


Note You do not have to have rights to the data stores unless you have to perform data repair.

Code changes

Note Always test code fixes in a controlled environment before you apply the fixes to your production computers.
To resolve this problem, follow these steps:
  1. Add the following local variables in the IsAvgCostException function in the Value Entry Table (5802):
    • ItemLedgEntry@1002 : Record 32;
    • xItemLedgEntry@1003 : Record 32;
    • TempItemLedgEntry@1005 : TEMPORARY Record 32;
    • GoThroughChain@1004 : Boolean;
  2. Change the code in the IsAvgCostException function in the Value Entry Table (5802) as follows:
    Existing code
    ...
    IF "Partial Revaluation" THEN
    EXIT(TRUE);

    // Delete the following lines.
    IF "Item Ledger Entry Type" = "Item Ledger Entry Type"::Transfer THEN
    EXIT(TRUE);
    IF ItemApplnEntry.AppliedInbndEntryExists("Item Ledger Entry No.",TRUE) THEN
    EXIT(TRUE);
    // End of the lines.

    EXIT(FALSE);
    ...
    Replacement code
    ...
    IF "Partial Revaluation" THEN
    EXIT(TRUE);

    // Add the following lines.
    IF "Item Ledger Entry Type" = "Item Ledger Entry Type"::Consumption THEN
    GoThroughChain := ItemApplnEntry.AppliedFromEntryExists("Item Ledger Entry No.")
    ELSE
    GoThroughChain := ItemApplnEntry.AppliedInbndEntryExists("Item Ledger Entry No.",TRUE);

    IF GoThroughChain THEN
    REPEAT
    IF "Item Ledger Entry Type" = "Item Ledger Entry Type"::Transfer THEN
    ItemLedgEntry.GET(ItemApplnEntry."Inbound Item Entry No.")
    ELSE
    ItemLedgEntry.GET(ItemApplnEntry."Outbound Item Entry No.");
    IF ItemLedgEntry."Entry No." <> xItemLedgEntry."Entry No." THEN BEGIN
    xItemLedgEntry := ItemLedgEntry;
    ItemApplnEntry.GetVisitedEntries(ItemLedgEntry,TempItemLedgEntry);
    TempItemLedgEntry.SETCURRENTKEY("Item No.",Positive,"Location Code","Variant Code");
    TempItemLedgEntry.SETRANGE("Item No.","Item No.");
    TempItemLedgEntry.SETRANGE(Positive,TRUE);
    TempItemLedgEntry.SETRANGE("Location Code","Location Code");
    TempItemLedgEntry.SETRANGE("Variant Code","Variant Code");
    IF NOT TempItemLedgEntry.ISEMPTY THEN
    EXIT(TRUE);
    END;
    UNTIL ItemApplnEntry.NEXT = 0;
    // End of the lines.



    EXIT(FALSE);
    ...
  3. Add the following global variable in the Inventory Adjustment codeunit (5895):
    • RevaluationPoint@1022 : TEMPORARY Record 2000000026;
  4. Add the following local variables in the AvgValueEntriesToAdjustExist function in the Inventory Adjustment codeunit (5895):
    • CurrIsException@1009 : Boolean;
    • NextIsException@1010 : Boolean;
  5. Change the code in the AvgValueEntriesToAdjustExist function in the Inventory Adjustment codeunit (5895) as follows:
    Existing code
    ...
    END;

    FINDSET;
    REPEAT
    IF "Valued By Average Cost" AND NOT Adjustment AND ("Valued Quantity" < 0) THEN BEGIN
    OutbndValueEntry := ValueEntry;
    OutbndValueEntry.INSERT;
    FindNextRange := FALSE;
    END;

    // Delete the following lines.
    IF IsAvgCostException THEN BEGIN
    AvgCostExceptionBuf.Number := "Entry No.";
    AvgCostExceptionBuf.INSERT;
    END;
    // End of the lines.

    IF ("Entry Type" = "Entry Type"::Revaluation) OR
    ...
    Replacement code
    ...
    END;

    CLEAR(RevaluationPoint);
    RevaluationPoint.DELETEALL;



    FINDSET;
    REPEAT

    // Add the following lines.
    IF "Partial Revaluation" THEN BEGIN
    RevaluationPoint.Number := "Entry No.";
    RevaluationPoint.INSERT;
    END;
    // End of the lines.

    IF "Valued By Average Cost" AND NOT Adjustment AND ("Valued Quantity" < 0) THEN BEGIN
    OutbndValueEntry := ValueEntry;
    OutbndValueEntry.INSERT;
    FindNextRange := FALSE;
    END;

    // Add the following lines.
    IF NOT Adjustment THEN BEGIN
    CurrIsException := NextIsException;
    NextIsException := IsAvgCostException;
    IF NextIsException OR CurrIsException THEN BEGIN
    AvgCostExceptionBuf.Number := "Entry No.";
    AvgCostExceptionBuf.INSERT;
    END;
    END;
    // End of the lines.

    IF ("Entry Type" = "Entry Type"::Revaluation) OR
    ...
  6. Change the code in the IsExcludeEntryFromAvgCostCalc function in the Inventory Adjustment codeunit (5895) as follows:
    Existing code
    ...
    WITH ValueEntry DO BEGIN
    IF "Partial Revaluation" THEN
    ...
    Replacement code
    ...
    WITH ValueEntry DO BEGIN

    // Add the following lines.
    RevaluationPoint.SETRANGE(Number,"Entry No.",OutbndValueEntry."Entry No.");
    IF NOT RevaluationPoint.ISEMPTY THEN
    EXIT(FALSE);
    // End of the lines.


    IF "Partial Revaluation" THEN
    ...

Prerequisites

You must have one of the following products installed to apply this hotfix:
  • Microsoft Dynamics NAV 2009 R2
  • Microsoft Dynamics NAV 2009 Service Pack 1
  • Microsoft Dynamics NAV 2009
  • Microsoft Dynamics NAV 5.0 Service Pack 1
Additionally, you must have hotfix 2481793 installed to apply this hotfix.
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
2481793 The unit cost of items becomes negative after you run the revaluation on items that use the Average costing method in Microsoft Dynamics NAV

Removal information

You cannot remove this hotfix.

Status


Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.