| Introduction | MTB Statements | File System | Compiler | Applications | Reference Guide | Index |
| Language Structure | Data Division | I/O Format Division | Procedure Division | Mnemonics |
In addition to these operations, there are may functions that operate on string and/or numeric data. For more information, see the Procedure Division documentation.
Also see the notes about Precedence.
Notes:
Also see the LET statement.
Example:
Notes:
Also see the LET statement.
Example:
Notes:
Also see the LET statement.
Example:
Notes:
Also see the LET statement.
Example:
The MOD operator is supported in Comet 504 and greater.
The syntax is:
This algebraic order can be overridden with parentheses. In a
numeric expression containing parentheses, operations inside the
parentheses will be performed first, followed by the algebraic
order previously described. Parentheses may be nested to any
level in a numeric expression -- they will be performed from the
inside to the outside.
Additional information:
See the ASCII chart.
For more information on relational operations and logical
operations, see the IF statement.
Numeric Operations
The following types of operations may be performed on numeric data:
Addition
The plus sign (+) is the operator used to perform addition on
numeric data.
LENGTH 5.0 ! Declare the length for A, B, C
LOCAL A, B, C ! Declare them as LOCAL variables
.
LET A = 500 ! Set the value for A
LET B = 2000 ! Set the value for B
LET C = A + B ! Add A and B, giving C
Subtraction
The minus sign (-) is the operator used to perform subtraction on
numeric data.
LENGTH 5.0 ! Declare the length for A, B, C
LOCAL A, B, C ! Declare them as LOCAL variables
.
LET A = 800 ! Set the value for A
LET B = 200 ! Set the value for B
LET C = A - B ! Subtract B from A, giving C
Multiplication
The asterisk (*) is the operator used to perform multiplication
on numeric data.
LENGTH 5.0 ! Declare the length for A, B, C
LOCAL A, B, C ! Declare them as LOCAL variables
.
LET A = 150 ! Set the value for A
LET B = 25 ! Set the value for B
LET C = A * B ! Multiply A and B, giving C
Division
The backslash (/) is the operator used to perform division on
numeric data.
LENGTH 5.0 ! Declare the length for A, B, C
LOCAL A, B, C ! Declare them as LOCAL variables
.
LET A = 150 ! Set the value for A
LET B = 25 ! Set the value for B
LET C = A / B ! Divide A by B, giving C
Modulo
The MOD operator performs a modulo operation on the two numeric
values (i.e., it divides the first value by the second value and
returns the remainder).
numeric-value-1 MOD numeric-value-2
Example:
10 MOD 3
This operation returns a value of 1. Explanation: 10 divided by 3
equals 3 with a remainder of 1.
Precedence
In a numeric expression containing multiple operations, the
multiplication and division operations are performed first (from
left to right). Next, the addition and subtraction operations are
performed (also from left to right).
Results
The temporary result of a numeric operation will contain only as
many digits to the right of the decimal point as the most precise
operand in the expression. For example, if an expression contains
operand with two digits of precision and four digits of
precision, the temporary result will contain four digits of
precision.
String Operations
The MTB language supports the string operation of concatenation.
The plus sign (+) is used to indicate concatenation (the
combining of strings). For example, concatenating two string
variables would look like this:
FIRSTNAME$ + LASTNAME$
You may concatenate string constants, string variables, and
string functions. Here is an example of concatenating constants
with variables:
"(" + AREACODE$ + ")" + PHONENUMBER$
Note: The maximum number of characters in any string is 254. If a
concatenation operation results in more characters than have been
declared for a receiving variable, characters will be truncated
on the right-hand side. THIS TRUNCATION WILL OCCUR WITHOUT
WARNING OF ANY KIND.
Relational Operations
The MTB language supports relational operations in
IF/THEN
statements. The following operations are supported:
Operation MTB syntax
=================================================================
Equal to EQ or =
Not equal to NE or NOT=
Greater than GT or >
Greater than or equal to GE or >=
Less than LT or <
Less than or equal to LE or <=
Logical Operations
The MTB language supports the AND and OR logical operations to be
used in conjunction with relational expressions. The AND operator
tests whether both relational conditions are true, while the OR
operator tests for truth of either relational condition. For
example:
IF A=B AND B=C THEN... ! Both conditions must be true
IF A=B OR B=C THEN... ! Either condition may be true
If AND and OR are combined in a relational expression, the AND
operator takes precedence (i.e., it will be evaluated first). It
is possible to override this precedence with parentheses, just
like the precedence in numeric operations can be overridden.