CALC Command [ HP ALLBASE/4GL Developer Reference Manual Vol. 2 ] MPE/iX 5.0 Documentation
HP ALLBASE/4GL Developer Reference Manual Vol. 2
CALC Command
The CALC command calculates the result of an arithmetic expression.
Format
CALC operand [#] operator operand [#] [operator operand...]
= result_data_ref [;command]
Parameters
operand
May be one of the following:
* Whole number.
* Numeric constant.
* Variable or calculated item.
* Screen field reference.
* Scratch-pad field reference.
* File record field reference.
* Work area field reference.
* *TOTALS(n): where n = 1 to 16.
* *COUNT(n), or *CROSS(n): where n = 1 to 5.
operand#
Certain operands can be treated as absolute values. That is, their value
is treated as a positive number. To specify an operand as absolute,
enter the character # after the operand name. You cannot specify the
result of the calculation as absolute.
You can specify the following operands as absolute:
* Numeric variables.
* Numeric constants.
* Screen field names.
* Scratch-pad field names.
* File record field names.
* Work area field names.
operator
The operation to be performed on the two operands. It may be one of the
following arithmetic operators:
+ Add
- Subtract
X or x Multiply
/ Divide
M or m Modulus
e Raised to the power of
result_data_ref
Where the result of the CALC is to be placed. It may be one of the
following:
* Numeric variable.
* Screen field reference.
* Scratch-pad field reference.
* File record field reference.
* Work area field reference.
* *TOTALS(n): where n = 1 to 16.
* *COUNT(n), *CROSS(n): where n = 1 to 5.
command
A command to be executed if an error occurs while the CALC command is
being executed. You can use any of the following commands:
* ENTER
* EXIT
* EXTERNAL
* MESSAGE
* PROCEED
* SERIES
* TOP
* VISIT
* ZIP
HP ALLBASE/4GL executes the command in the following conditions:
* Machine overflow or underflow occurs.
* Division by zero occurs.
* The result is too large to fit in the result field.
* One or more of the operands contains non-numeric data, or an
operand contains a minus sign and has an N edit code.
If you don't specify an optional command, and one of these error
conditions occurs, HP ALLBASE/4GL displays a warning message and then
executes the next command in the logic block.
Description
The CALC command calculates the result of an expression. The operands
are processed in the order in which they are encountered. Algebraic
rules of precedence do not apply.
The first two operands and their associated operator are mandatory. You
can enter successive operator-operand pairs as often as desired.
HP ALLBASE/4GL uses full floating point arithmetic. The result of the
CALC command is rounded off to suit the number of decimal places
specified for result_data_ref. If the result_data_ref is a scratch-pad
field, the number of decimal places used for the result of the
calculation is the number of decimal places specified for the first
operand of the CALC command.
Operands for the CALC command, and values computed by the CALC command,
can contain a maximum of 14 significant digits. Overflow or truncation
errors may occur if you attempt to use values with more than 14
significant digits.
Example
CALC V-rate/100 + 1 e V-years x F-principal.bank = F-interest.bank
This command calculates the compound interest of the value in principal
in the file bank and places the result in interest in the same file.
This command is equivalent to the formula I = P(1 + r/100)n.
MPE/iX 5.0 Documentation