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.))).
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 ...