Define Calculated Items |
Calculated items are view elements that are derived by creating expressions that combine view elements that have been selected from different files and other calculated items. A name is associated with the calculated item, and the value of the expression is evaluated and stored in the named variable after each data record is retrieved. When evaluating items, the sequence of the calculated items is also important.
(The ability to define calculated items was added in PxPlus 2021.)
To create calculated items for a view, invoke the Define Calculated Items window by clicking the Calc Items toolbar button on the Define a View window.
A calculated item definition consists of the following:
Name |
Name of the data variable in which to store the result when the expression is evaluated. The variable will be prefixed by "calc_" and must contain only alphanumeric characters, underscore or period. Maximum 30 characters. |
Description |
(Optional) Short description of the calculated item. |
Type |
Text or numeric (computational) value. |
Maximum Length |
Maximum length of the value to be stored. If numeric, the length may contain a scaling factor (e.g. 10.2 where total length is 10 with two digits to the right of the decimal). |
(Transfer) |
Button used to transfer to the Expression input box (below the main list) to enter an expression for the calculated item. |
Select |
Click to select/deselect the calculated item as a view element. |
Remove |
Button used to remove the currently selected calculated item from the list. |
Move Up |
Buttons used to move the selected calculated item up or down within the list. |
Expression |
Input box used for manually entering an expression for the calculated item. |
If Type is Numeric: Select this link to invoke the Define a Numeric Expression window for building a numeric expression.
If Type is Text: Select this link to invoke the Define a Text Expression window for building a text expression.
| |
Items available to use in expression |
Displays a list of the selected view elements that can be used in the expression. Add individual items to the Expression input box by double clicking an item or using drag and drop. The Clipboard button beside the list can also be used. |
(Clipboard) |
Button used to place a highlighted item in the Items available to use in expression list onto the Clipboard so that it can then be copied to the Expression input box. |
Once calculated items are defined and selected, they appear in the element lists in the Define a Numeric (Text) Expression windows (when the Click to build an expression link is selected) and in the Define Filters window. Whether they are selected or not, they also display under the *Calculated Items section of the tree view list in the Define a View window where they can be selected/deselected as view elements.
If an element on which a calculated item is based is deselected from the view definition, the data for that element will not be available to the calculated item, rendering its results invalid.
If an error occurs while evaluating a calculated item during execution, default values (0 for numeric and null for string) are assigned to the item.