Advice on NAV 2017 Code efficiency

djdave
djdave Member Posts: 12

This code is taking hours to run but my earlier itterations of it were only taking minutes to run. No change in record count - loking for advice from more seasons developers as to what can i do to improove its runtime - my only thought is to create a temp table and store the records tehre before itterating

CustomerPriceGroup.RESET;
CustomerPriceGroup.SETFILTER("Source Price List",'<>%1','');
IF CustomerPriceGroup.FINDSET THEN BEGIN
REPEAT
DestSalesPrices.RESET;
DestSalesPrices.SETCURRENTKEY("Sales Type","Sales Code","Item No.","Starting Date","Currency Code","Variant Code","Unit of Measure Code","Minimum Quantity");
DestSalesPrices.SETRANGE("Sales Type", DestSalesPrices."Sales Type"::"Customer Price Group");
DestSalesPrices.SETFILTER("Sales Code",CustomerPriceGroup.Code); //empty the destination ready to receive more
DestSalesPrices.DELETEALL(TRUE);

SrcSalesPrices.RESET;
SrcSalesPrices.SETCURRENTKEY("Sales Type","Sales Code","Item No.","Starting Date","Currency Code","Variant Code","Unit of Measure Code","Minimum Quantity");
SrcSalesPrices.SETRANGE("Sales Type",SrcSalesPrices."Sales Type"::"Customer Price Group");
SrcSalesPrices.SETFILTER("Sales Code",CustomerPriceGroup."Source Price List"); //filter source to popualte dest
SrcSalesPrices.SETFILTER("Starting Date",'<=%1', TODAY());
SrcSalesPrices.SETRANGE("Currency Code",CustomerPriceGroup."Src. Price List Currency");
//SrcSalesPrices.SETFILTER("Unit of Measure Code", '<>%1','');
IF CustomerPriceGroup."Src. Ending Date" = 0D THEN
// Only get records where Ending Date is blank
SrcSalesPrices.SETRANGE("Ending Date", 0D)
ELSE
SrcSalesPrices.SETRANGE("Ending Date", CustomerPriceGroup."Src. Ending Date");



IF SrcSalesPrices.FINDSET THEN BEGIN
REPEAT
DestSalesPrices.RESET;
DestSalesPrices.INIT;

DestSalesPrices."Sales Type" := DestSalesPrices."Sales Type"::"Customer Price Group";
DestSalesPrices."Sales Code" := CustomerPriceGroup.Code;
DestSalesPrices."Item No." := SrcSalesPrices."Item No.";
DestSalesPrices."Starting Date" := SrcSalesPrices."Starting Date";
DestSalesPrices."Currency Code" := SrcSalesPrices."Currency Code";
DestSalesPrices."Variant Code" := SrcSalesPrices."Variant Code";
DestSalesPrices."Unit of Measure Code" := SrcSalesPrices."Unit of Measure Code";
DestSalesPrices."Minimum Quantity" := SrcSalesPrices."Minimum Quantity";

DestSalesPrices."Price Includes VAT" := SrcSalesPrices."Price Includes VAT";
DestSalesPrices.Active := SrcSalesPrices.Active;
DestSalesPrices."Date to Submit" := SrcSalesPrices."Date to Submit";
DestSalesPrices."Ending Date" := SrcSalesPrices."Ending Date";
DestSalesPrices."Unit Price" := SrcSalesPrices."Unit Price" * (1 / CustomerPriceGroup."Src. Price List Modifier (/by)");
DestSalesPrices."Unit Price Including VAT" := SrcSalesPrices."Unit Price Including VAT" * (1 / CustomerPriceGroup."Src. Price List Modifier (/by)");

DestSalesPrices.INSERT;
UNTIL SrcSalesPrices.NEXT = 0;
END;

UNTIL CustomerPriceGroup.NEXT = 0;
END;