CLEAR(CostElementBuf); WITH CostElementBuf DO BEGIN TransValueEntry2 := TransValueEntry; TransValueEntry.SETCURRENTKEY("Item Ledger Entry No.","Entry Type"); TransValueEntry.SETRANGE("Item Ledger Entry No.",ItemLedgEntryNo); TransValueEntry.SETRANGE("Entry Type",TransValueEntry."Entry Type"::"Direct Cost"); TransValueEntry.FIND('+'); REPEAT IF TransValueEntry."Item Charge No." = '' THEN BEGIN IF AdjmtBuf.GET(TransValueEntry."Entry No.") THEN TransValueEntry.AddCost(AdjmtBuf); "Actual Cost" := "Actual Cost" + TransValueEntry."Cost Amount (Actual)"; "Actual Cost (ACY)" := "Actual Cost (ACY)" + TransValueEntry."Cost Amount (Actual) (ACY)"; TransValueEntry2 := TransValueEntry; END; UNTIL TransValueEntry.NEXT(-1) = 0; TransValueEntry := TransValueEntry2; END;
CLEAR(CostElementBuf); WITH CostElementBuf DO BEGIN TransValueEntry2 := TransValueEntry; TransValueEntry.SETCURRENTKEY("Item Ledger Entry No.","Entry Type"); TransValueEntry.ASCENDING(FALSE); //Added this statement to try to increase performance TransValueEntry.SETRANGE("Item Ledger Entry No.",ItemLedgEntryNo); TransValueEntry.SETRANGE("Entry Type",TransValueEntry."Entry Type"::"Direct Cost"); //TransValueEntry.FIND('+'); //Replaced this statement with next statement TransValueEntry.FINDSET; REPEAT IF TransValueEntry."Item Charge No." = '' THEN BEGIN IF AdjmtBuf.GET(TransValueEntry."Entry No.") THEN TransValueEntry.AddCost(AdjmtBuf); "Actual Cost" := "Actual Cost" + TransValueEntry."Cost Amount (Actual)"; "Actual Cost (ACY)" := "Actual Cost (ACY)" + TransValueEntry."Cost Amount (Actual) (ACY)"; TransValueEntry2 := TransValueEntry; END; //UNTIL TransValueEntry.NEXT(-1) = 0; //Replaced this statement with the next statement UNTIL TransValueEntry.NEXT = 0; TransValueEntry := TransValueEntry2; END;
Comments
As far has adjust cost routine goes, this has been already discussed before that after update adjust cost looks at all ILE. There is a field in ILE that you can "Applied Entry to Adjust" You can set to false, and it won't look at old records, but it's a lot easier to filter by item and run it over a period of a week and finish all the items. Afterwards adjust cost will run the usual speed.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Peter
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book