HomeStartingEnvironmentDBMSVisualPQLProceduresSQLFormsHost/APIIndex
Forms homecontents start chapter top of pagebottom of pagenext page index COMPUTE

COMPUTE

COMPUTE assigns the value of an expression to a variable. IF is similar to COMPUTE and assigns a value to a variable but only when a particular condition is true.

These are stand alone commands where the values are computed each time the command is traversed. These commands do not affect the current cursor position.

COMPUTE and IF are also options on the INITIAL and FINAL clauses of the MENU, RECORD, TABLE, CALL and FIELD commands. These options use expressions and conditions in exactly the same manner.

homecontents start chapter top of pagebottom of pagenext page index

COMPUTE

COMPUTE variable =
expression

The variable specified on the left side of the equal sign must be defined in the record or table accessed by the current screen or in the DECLARE clause of the FORM command.

COMPUTE AVERAGE = (VARX + VARY + VARZ) / 3

homecontents start chapter top of pagebottom of pagenext page index

IF

IF (
condition) variable = expression

The variable specified on the left side of the equal sign must be defined in the record or table accessed by the current screen or in the DECLARE clause of the FORM command. The variable is only calculated if the condition is true.

Example: To give a $1,000 raise to all technical writers (position = 10):
IF (position eq 10) salary = salary + 1000

homecontents start chapter top of pagebottom of pagenext page index

Conditions

An IF condition may include the following operators:

The logical operator NOT can be used to test for the opposite of any condition. Parentheses ( ) can be used in the IF clause to denote explicitly the order of evaluation. The default order of precedence is to evaluate expressions first, then to use the relational operators to determine whether the test is true, then to test compound conditions.

EQ, NE, LT, LE, GT, GE

These operators test the relationship between two values. If the specified condition is true, the field is computed. NE is provided as a convenient shorthand; it is identical to NOT EQ.

LIKE Pattern Matching

A pattern is a partial string where symbols are used to indicate how that position is to be treated. (see Pattern Matching for information on LIKE pattern matching.)

compound conditions

An IF condition may consist of a number of conditions connected by the logical operators AND, OR, and XOR.
AND means both conditions must be true;
OR means either condition must be true;
XOR means either condition must be true but not both.

homecontents start chapter top of pagebottom of pagenext page index

Expressions

Expressions are a combination of variables and operators which produce a new value.

There are numeric expressions and string expressions. Adding two numeric variables produces the sum. Concatenating two string variables produces a longer string. Numeric and string variable types cannot be mixed. There are functions to convert numbers to strings and vice versa.

Numeric expressions consist of numeric variables, constants, all of the normal arithmetic operators (+, -, /, *, **), numeric functions, and parentheses. A numeric constant starts with a number and may have a decimal point.

String expressions may use quoted strings, variables which are strings, the "+" character to join strings, string functions, and parentheses to denote the order of operation. Enclose strings in single quotes.

A function is a keyword followed by one or more arguments enclosed in parentheses. Arguments may be variable names, constants or expressions. The function operates on the arguments and returns an appropriate value. For example, MOD returns the remainder from an integer division. The following order of precedence applies to expressions:

For example:
2*5-4                    (6)
2*(5-4)                  (2)
MOD(5,2)                 (remainder; 1)
SALARY*52/12             (monthly salary from  weekly (approx))
'ABC' + 'DEF'            ('ABCDEF')
SBST('ABCDEF',4,3)       ('DEF')
TIMEC(NOW(0),'HH:MM:SS') (current time in display format)

homecontents start chapter top of pagebottom of pagenext page index

Functions

Functions can be used in expressions in IF and COMPUTE. A function is a keyword followed by one or more arguments enclosed in parentheses. Arguments may be either variable names, constants or expressions. The function operates on the arguments and returns an appropriate numeric (n) or string (s) value . The available functions are:

ABS

ACOS
AINT
ALOG
ALOG10
AMOD
ASIN
ATAN
CDATE
CEILING
CNT
COUNT
COS
CTIME
DATE
DATEC
DATET
EXISTS
EXP
FIX
FLOOR
FORMAT
GROUP
INT
JULC
JULN
LEN
LOG10
LOG
LOWER
MAX
MIN
MOD
NOW
NUMBR
PATTERN
RAND
SBST
SIGN
SQRT
SRST
STR
SYSTEM
TAN
TANH
TIME
TIMEC
TODAY
TRIM
TRIML
TRIMLR
TRUNC
UPPER
USER

homecontents start chapter top of pagebottom of pagenext page index