CalcObject Statement: Calc
CalcObject Statement: Calc
Syntax: CALC vname=<arithmetic expression>
Placement: RETURN Section, EVERY Section, ATEND Section
R_INITIAL section
Description: Assigns the value of <arithmetic expression>
to a user defined numeric variable.
<arithmetic expression> may contain a simple operand or
an expression of operands and arithmetic operators.
Terms of an expression are evaluated according to the
hierarchy of the operator, with terms of highest
hierarchy being evaluated first. The order of evaluation
may be changed by using () pairs for grouping.
If <arithmetic expression> contains a string operand,
the numeric value of the operand is used.
For example,
CALC x=123
CALC x="123"
CALC x="ABC123"
CALC x="123ABC"
all assign the value 123 to variable x.
Options which apply to the CALC command are:
N - if null, make result non SQL-null;
refer to CALC-SET-IF with SQL null
1.1 Legal operators for <arithmetic expression> are:
Operator Description Hierarchy
() grouping
+ binary plus 1
- binary minus 1
* multiplication 2
/ division 2
^ exponentiation 3
+ unary plus 4
- unary minus 4
1.2 Legal operands for <arithmetic expression> are:
Integer or fractional numeric constants
Exponential constants
Numeric fields
Numeric local variables
Numeric global variables
Numeric functions
String constant enclosed in ' or "
Alpha fields
Alpha local variables
Alpha global variables
Number valued functions - Math functions
1.3 abs() function - absolute value
1.4 acos() function - arccosine
1.5 asin() function - arcsine
1.6 atan() function - arctangent
1.7 atan2() function - arctangent of two sides
1.8 ceil() function - ceiling function
1.9 cos() function - cosine
1.10 exp() function - exponential function (power of e)
1.11 floor() function - floor function
1.12 int() function - floor function
1.13 log() function - natural log (base e)
1.14 log10() - log function (base 10)
1.15 max() function - max of two numbers
1.16 min() function - min of two numbers
1.17 mod() function - mod of two numbers
1.18 pow() function - power function
1.19 rand() function - random number generator
1.20 round() function - round a number
1.21 sin() function - sine of a number
1.22 sqrt() function - square root of a number
1.23 tan() function - tangent of a number
Number valued functions - Date and Time functions
1.24 jdate() function - numeric date function
1.25 jdate64() function - datetime function
1.26 datediff() function - date difference calculation
1.27 timediff() function - time difference calculation
1.28 dyinc() function - increment the date by number of days
1.29 moinc() function - increment the date by number of months
1.30 yrinc() function - increment the date by number of years
Number valued functions - Miscellaneous functions
1.31 isnull() function - test for SQL NULL
1.32 numval() function - numeric value of a string
1.33 strlen() function - length of a string
1.34 _level() function - hierarchy level function
1.35 _prline() function - printer line number
1.36 _storage() function - disk storage available
1.37 _absrecno() - TB internal record number
1.38 _recno() function - table-relative record number
Number valued functions - Financial functions
|
1.39 fv1(pmt,int,np) |
Future value for periodic payment (pmt), interest (int) and number of periods (np) |
1.40 fv2(pv,int,np) |
Future value for present value (pv), periodic interest (int) and number of periods (np) |
1.41 pv1(pmt,int,np) |
Present value for periodic payment (pmt), interest (int) and number of periods (np) |
1.42 pv2(fv,int,np) |
Present value for future value (fv), periodic interest (int) and number of periods (np) |
1.43 pmt1(int,np,pv) |
Payment amount for periodic interest (int), number of periods (np) and present value (pv) |
1.44 pmt2(int,np,fv) |
Payment amount for periodic interest (int), number of periods (np) and future value (fv) |
1.45 rate1(fv,pv,np) |
Periodic interest rate for future value (fv), present value (pv) and number of periods (np) |
1.46 rate2(fv,pmt,np) |
Periodic interest rate for future value (fv), payment (pmt) and number of periods (np) |
1.47 rate3(pv,pmt,np) |
Periodic interest rate for present value (pv), payment (pmt) and number of periods (np) |
1.48 term1(pv,int,fv) |
Number of periods for present value (pv), periodic interest (int) and future value (fv) |
1.49 term2(pmt,int,fv) |
Number of periods for periodic payment (pmt), periodic interest (int) and future value (fv) |
1.50 term3(pmt,int,pv) |
Number of periods for periodic payment (pmt), periodic interest (int) and present value (fv) |
|
Number valued functions - CalcObject Only
1.51 distinct() function - although strictly speaking, this function
can be used in the context of ddlCalc(), such use would represent
a degenerate case; so for all practical purposes, this function
is restricted to ddlCreateCalcObject().
1.52 search() function - this function
is also restricted to ddlCreateCalcObject().
int() function - floor function
int(x) is a number valued function which returns the
floor integer of x; that is, the largest integer that
is less than or equal to x. For example,
int(5.5) is 5.0
int(-5.5) is -6.0
pow() function - power function
pow(x,y) is a number valued function which returns the value of
x to the power y;
rand() function - random number generator
rand(n) returns a uniformly pseudo-random number between 0 and 1.0.
If n is non-zero, it is taken as a new seed that establishes
a new sequence of random numbers.
If n is 0, the rand() function returns the next value from the sequence.
round() function - round a number
round(x,n)
jdate() function - numeric date function
jdate(string,template) is a function that computes
the numeric date relative to January 1, 1753. "string"
is a digital representation of the date in the form
of a string constant, an alpha field or an alpha
variable. "template" is a string representation of
the format of the date;
Each 'm' or 'M' represents a digit in the mneth;
each 'd' or 'D' represents a digit in the day;
each 'y' or 'Y' represents a digit of the year;
each 'x' or 'X' represents a character of the mnemonic month;
each 'z' or 'Z' represents a character of the mnemonic day;
If the year is edited as 'yy', it will represent the
last two digits of the year. If the year is edited
as 'yyyy' it will represent the absolute year from
1753 to 4999.
If the first argument is all blanks, the current date
is assumed.
If the [,template] argument is omitted, it is assumed
to be 'mm/dd/yy'.
Examples of jdate() usage are:
CALC jd=jdate("04/01/86")
CALC jd=jdate('19860401','yyyymmdd')
jdate64() function - datetime function
jdate64(string,template) is a function that computes
the numeric datetime relative to January 1, 1753. "string"
is a digital representation of the datetime in the form
of a string constant, an alpha field or an alpha
variable. "template" is a string representation of
the format of the datetime; each "m" or "M" represents
a digit of the month; each "d" or "D" represents a
digit of the day; each "y" or "Y" represents a digit
of the year. If the year is in the form 'yy', it is
assumed to be relative to 1753. If the year is in
form 'yyyy' it is assumed to be an absolute year
from 1753 to 4999.
If the first argument is all blanks, the current date
is assumed.
If the [,template] argument is omitted, it is assumed
to be 'mm/dd/yyyy hh:nn:ss.ttt'.
Examples of jdate() usage are:
CALC jd=jdate("04/01/86")
CALC jd=jdate('19860401','yyyymmdd')
_level() function - hierarchy level function
The _level() function in CALC and IF is a function of
the hierarchy level of a data group. In general,
the hierarchy level is the ordinal of the data group
in the collection.
_level(n) is 0 if level n is not currently defined;
_level(n) is 1 if level n is defined but is not in
the current RETURN
_level(n) is 2 if level n is in the current RETURN
For example, the command:
RELATE A CUSTOMERS INVENTORY SALES OVER CUST# ITEM#
would produce a hierarchy that looked like this
in a RAWPRINT:
DGNAME REC# NAME PRICE QUAN
---------- ---- ---- ----- ----
CUSTOMERS 1 BATMAN
INVENTORY 1 12.75
SALES 1 5
SALES 2 8
INVENTORY 2 17.00
INVENTORY 3 25.00
SALES 3 12
SALES 4 24
For each frame of a REPORT, the level(n) function is:
NAME PRICE QUAN _level(1) _level(2) _level(3)
---- ----- ---- --------- --------- ---------
BATMAN 12.75 5 2 2 2
8 1 1 2
17.00 1 2 0
25.00 12 1 2 2
24 1 1 2
The
_present() function is a more user friendly analogue to the
_level() function.
_recno() function - table-relative record number
The _recno(<table-name>) function returns the 1-relative record number
number of the current Calc Object record for <table-name>.
It returns 0 if the current record for <table-name> is not present.