Calculate. DORIC 9.65, INFO-Text software
Reklam
Reklam
CALCULATE
CA
LCULATE DF_item system_item system_variable
or
DF_item system_item system_variable
=
arithmetic_expression
=
arithmetic_expression
computes and assigns a numeric value to numeric data file items, numeric system items and date variables.
arguments
The specified datafile item, system item or system variable must be numeric.
= the operator 'equals'.
arithmetic_expression the expression that INFO computes before assigning the new value. You may also specify a single numeric value.
commandless syntax it is not necessary to include the command name CALCULATE in the statement.
CA $NUM1 = 99
$NUM1 = 99
can be coded as
notes
n
CALCULATE computes and assigns the value of an INFO arithmetic expression into the named numeric data file item, system item, or system variable. For more information on arithmetic expressions, see the chapter
'Building Expressions' in the beginning of this guide.
n
Once INFO computes the value of the arithmetic expression, at the time that it stores that value, INFO tailors the result to the target item or variable, as follows:
If the receiving data file item, system item, or system rounding variable is other than an I (integer) or (not VMS)
B (binary) type, INFO rounds the value to the nearest value that fits within the allowed precision for that item or variable.
INFO Reference Manual Commands 51
CALCULATE
If the receiving data file item, system item, or system truncating variable is an I or (not VMS) B type, INFO truncates the result to fit the input width of the item or variable.
n
The operation of the CALCULATE command varies, depending on whether you use it interactively or in an
INFO program.
In interactive mode, the CALCULATE command operates on every selected record. If no records are selected, you can use the CALCULATE command to perform calculations on system items or system variables, but not on data file items.
In program processing, the results of a CALCULATE depend on whether the command is issued from within an odd-numbered or even-numbered section. Each
CALCULATE command in an odd-numbered section is executed repeatedly, once for each selected record, before processing passes to the next INFO command. On the other hand, each CALCULATE command in an evennumbered section operates only on the currently positioned selected record.
n
If you attempt to assign a numeric value too large or too small for the receiving item or system variable, INFO displays an error message. INFO then checks the value of the $ARITH-QUESTION system item to determine whether to prompt you with the message DO YOU WANT
TO TRY AGAIN?>. Respond to this prompt as follows:
Y instructs INFO to repeat the calculation that caused the error message and assign the overflow/underflow value
(which is truncated to fit) in the item, system item, or system variable.
N instructs INFO not to repeat the calculation that caused the error message. The item value, system item, or system variable involved is not changed.
52 Commands INFO Reference Manual
CALCULATE notes for using $DAT and $NUM
n
INFO maintains accuracy of up to 12 significant positions.
n
Remember to include a space between each term and operator in an arithmetic expression.
n
When a CALC is performed from an item on a related file where there is a ‘NO-MATCH’, by default the target item is zero-filled. This can be avoided by setting the system variable $MOVFLG to 1. If this is done the target item will be left intact if the source item has not been matched.
Special considerations apply when a CALCULATE command references the $DAT# and $NUM# system variables, either interactively or within an odd-numbered program section.
n
If you set the value $DAT# or $NUM# without looping — that is, without using the same variable on both sides of the CALCULATE equation — then the CALCULATE operation occurs once, regardless of the number of records selected.
CALCULATE $DAT3 = 5/7/1983 n
If you assign the value of a $DAT# or $NUM# variable in loop processing — that is, while using the same variable on both sides of the equation — then the CALCULATE operation occurs repeatedly, once for each selected record.
CALCULATE $NUM1 = $NUM1 + PRICE n
At the end of the looping process, the value of the variable
($NUM1 above) equals the total of all the calculated values (in the above example, the total of the PRICE field in all selected records). If no records are selected, the calculation does not occur.
n
If you include more than one $DAT# or $NUM# variable in the arithmetic expression, then the CALCULATE operation occurs once, regardless of the number of selected records.
CALCULATE $NUM1 = $NUM1 + $NUM2
INFO Reference Manual Commands 53
CALCULATE example
ENTER COMMAND >CALCULATE GROSS = HRS_WORKED * HRLY_WAGE
ENTER COMMAND >CALCULATE $REPDAT = $TODAY - 3
When performing complex calculations, INFO processes expressions inside parentheses first.
ENTER COMMAND >CALC WAGE = RATE / ( HRS_WRKD * WKS_MO )
Note that there is a space on either side of each operator and each parenthesis.
see also
Appendix L, Functions.
54 Commands INFO Reference Manual
İndir
Reklam