Saturday, July 18, 2009

CALCFIELDS, CALCSUMS Functions In Navision

CALCFIELDS updates FlowFields. FlowFields are automatically updated when they are the direct source expressions of controls, but they must be explicitly calculated when they are part of a more complicated expression.
CALCFIELDS has the following syntax.
[Ok :=] Record.CALCFIELDS(Field1, [Field2],...)
When you use FlowFields in C/AL functions, you must use the CALCFIELDS function to update them.
For Eg:
In the following example, the SETRANGE function sets a filter and then the CALCFIELDS function calculates the Balance and Balance Due fields by using the current filter and performing the calculations that are defined as the CalcFormula properties of the FlowFields.
Let the Variable Be 'Customer', Data Type be 'Record'.
Customer.GET(INDG-CUS-005); // Will Selct The Customer No: INDG-CUS-005
Customer.SETRANGE("Date Filter",0D,TODAY); // Will set the date Range for the Present Dt
Customer.CALCFIELDS(Balance,"Balance Due"); // Using, Calcfields system calcs the balance as per Dt.
MESSAGE('The Balance is %1 and your Balance Due is %2',Customer.Balance,Customer."Balance Due"); // Will Displays the balance in a Message Box, with Corresponding Value.
CALCSUMS Function
CALCSUMS calculates the sum of one or more fields that are SumIndexFields in the record.
CALCSUMS has the following syntax.
[Ok :=] Record.CALCSUMS (Field1, [Field2],...)
For CALCSUMS, a key that contains the SumIndexFields must be selected as the current key. Similar to CALCFIELDS, CALCSUMS uses the current filter settings when performing the calculation.
For Eg:
Let the Variable be 'CustLdgentry' & Datatype be 'Record'
CustLdgentry.SETCURRENTKEY("Customer No."); // will Set the Key Customer No.
CustLdgentry.SETRANGE("Customer No.",'50000','90000');// Will set Range of Customers No. From 50000-90000.
CustLdgentry.SETRANGE("Posting Date",0D,TODAY); // will Filter the posting date with Present date.
CustLdgentry.CALCSUMS("Sales (LCY)"); // Will Calculate total Sales Froam Sales(LCY) Field.
MESSAGE ('%1 calculated sales',custledgerentry."Sales (LCY)") // Total sales Amount in Local Currency Will be displayed in Message Box.

No comments: