CALCULATION
CALCULATION name TYPE type SIZE size [PRECISION dec_places] [IF conditional_spec] EXPRESSION "expression" [ALTERNATE "alt_expression"] [DESCRIPTION "description"] [JUST just] [FORMAT "format"] [AFTER_SORT]
Arguments
name
The name of the temporary calculation field. It can have up to 15 characters and cannot contain spaces.
TYPE type
The data type of the calculation’s result. Valid values are ALPHANUMERIC, NUMERIC, DATE, TIME.
SIZE size
The length of the calculation’s result. When using date or time fields in your calculation, the length should match the storage length of the base value in the expression.
PRECISION dec_places
(optional) The number of characters to the right of the decimal in the implied-decimal calculation field. If the data type is implied-decimal, this attribute must be present, and it must be less than or equal to the size of the field. Otherwise, the field is ignored.
IF conditional_spec
(optional) Specifies a condition or set of conditions in a report. The conditional_spec can have up to five conditions connected together. See Condition_spec definition.
EXPRESSION “expression”
(optional) The calculation’s expression. It can have up to 150 characters and must be enclosed in quotation marks. See Entering an expression for the syntax.
ALTERNATE “alt_expression”
(optional) The calculation’s alternate expression. It can have up to 150 characters and must be enclosed in quotation marks. See Entering an expression for the syntax.
DESCRIPTION “description”
(optional) A description of the calculation field. It can have up to 40 characters.
JUST just
(optional) The justification of the calculation field. Valid values are:
LEFT (default for alpha, date, time, and user type fields)
CENTER (valid only for alpha and user fields)
RIGHT (default for decimal and implied-decimal fields)
FORMAT “format”
(optional) The display format for the calculation field. It can have up to 40 characters.
AFTER_SORT
(optional) Indicates that the calculation field will be evaluated after the sort. If the field is dependent on one or more subtotal access fields, it is automatically evaluated after the sort.
Discussion
The CALCULATION statement describes a temporary calculation field to be created in a report.
A calculation field defines a mathematical expression. Calculation fields are temporary fields that are not found in the repository. To create this type of field, you must specify the field name, data type, data length, and calculation expression. You can also define an alternate expression based on a conditional.
The order in which you specify your calculation fields determines the order in which ReportWriter evaluates them. The maximum number of calculation fields that can be defined in a report is 99.
If a temporary calculation field does not have a unique name, it must be preceded by “TEMP.”. For example, if the temporary field is called AVERAGE and one of the selected files also contains a field called AVERAGE, you would specify the temporary field like this:
TEMP.AVERAGE
Examples
- In the example below, the following expression is always calculated:
"ORDER.SHP_DATE - ORDER.ORD_DATE" CALCULATION TURNTIME TYPE NUMERIC SIZE 8 EXPRESSION "ORDER.SHP_DATE - ORDER.ORD_DATE"
- In the following example, the expression is only calculated if the conditional is true. If the conditional is false, the numeric value 0 is assigned to the field. An alternate expression could have been defined for the false conditional.
CALCULATION TURNTIME TYPE NUMERIC SIZE 8 IF CUSTOMER.CUST_ID LT "100" AND CUSTOMER.CUST_ID GT "50" EXPRESSION "ORDER.SHP_DATE - ORDER.ORD_DATE"