CALCFIELDS and CALCSUMS comparison

In the Sales Header record, there are FlowFields defined for Amount and "AmountIncludingVAT". These FlowFields are all based on Sums of entries in the SalesLine table. The CalcFormula for Amount is Sum("SalesLine".AmountWHERE(DocumentType=FIELD(DocumentType), DocumentNo.=FIELD(No.))).

CALCSUMS can be used on any integer, big integer, or decimal field with any filter on any table, but for larger datasets creating a key with a SumIndexField is recommended.

To calculate a TotalOrderAmount value while referencing the Sales Header table, the code can be as simple as this:

"Sales Header".CALCFIELDS (Amount);
TotalOrderAmount := "Sales Header".Amount;

To calculate the same value from code directly referencing the Sales Line table, the required code is similar to the following (assuming a Sales Header record has already been read):

"Sales Line".SETRANGE("Document Type","Sales Header"."Document Type"); 
"Sales Line".SETRANGE("Document No.","Sales Header"."No.");
"Sales Line".CALCSUMS(Amount);
TotalOrderAmount := "Sales Line".Amount;
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.77.63