General Formats (Continued) [ Micro Focus COBOL Language Reference ] MPE/iX 5.0 Documentation
Micro Focus COBOL Language Reference
General Formats (Continued)
Numeric Expressions
Arithmetic expressions may appear in a number of places in your COBOL
program, notably in the COMPUTE, If and SEARCH verbs, and reference
modification.
These expressions are evaluated at run time to give a single numerical
result. The operands of a numerical expression may be either numeric
constants or numeric variables.
Evaluation of Numeric Expressions.
Expressions are evaluated using the normal rules of precedence. Thus, in
the expression:
1 + 2 * 3
the order of evaluation is:
1. 2 * 3
yielding an intermediate result of 6
2. 1 + 6
giving a result of 7.
As the expression is evaluated, one or more intermediate results is
derived. Conceptually, each intermediate result is stored in a temporary
data item, the value of which is determined by the parameter you select
in the ARITHMETIC directive.
The Micro Focus COBOL system can evaluate each intermediate result using
up to 18 integer and 18 decimal places. If you select the ARITHMETIC"MF"
system directive, intermediate results are not truncated, and thus this
maximum accuracy is obtained. In this instance, each intermediate result
has a picture of 9(18)V9(18).
The OS/VS COBOL, VS COBOL II, DOS/VS COBOL and COBOL/370 systems compute
intermediate results to an accuracy determined by the pictures of the
operands in the expressions. The rules, which are slightly different for
each version of COBOL, are documented in appendices of the IBM VS COBOL
for OS/VS manual and the VS COBOL II Application Programming Guide.
Thus, each intermediate result has a picture of 9(n)V9(m). The maximum
value of n+m is 30.
If you specify the OSVS or VSC2 options for intermediate results, this
COBOL system will emulate the selected mainframe behaviour by truncating
its results accordingly, with the following limitations:
* The maximum number of integer and decimal places allowed by this
COBOL system is 18 for each. Truncation of intermediate results
will cease at the point in the expression where this limit is
reached. A warning message is issued at compile time if this
occurs.
* The rules apply to fixed point numerical expressions only. If the
expression contains any floating-point operands or any operation
which causes it to be evaluated in floating point (see the section
Intrinsic Functions), all truncation of intermediate results
ceases.
* Floating-point results are, by their nature, inexact and may vary
across platforms by a small degree.
Conditional Expressions
Conditional expressions identify conditions that are tested to enable the
object program to select between alternate paths of control depending
upon the truth value of the condition. Conditional expressions are
specified in the EVALUATE (ANS85 only), IF, PERFORM and SEARCH
statements. Two categories of conditions are associated with conditional
expressions: simple conditions and complex conditions. Each can be
enclosed within any number of paired parentheses, in which case its
category is not changed.
If the OSVS system directive (see your COBOL System Reference ) is set,
reference modification cannot be used within a conditional expression
(OSVS).
Simple Conditions.
The simple conditions are the relation, class, condition-name,
switch-status, and sign conditions. A simple condition has a truth value
of "true" or "false". The inclusion in parentheses of simple conditions
does not change the simple truth value.
Relation Condition.
A relation condition causes a comparison of two operands, each of which
can be the data item referenced by an identifier, a literal or the value
resulting from an arithmetic expression. A relation condition has a
truth value of "true" if the relation exists between the operands.
Comparison of two numeric operands is permitted regardless of the formats
specified in their respective USAGE clauses. However, for all other
comparisons the operands must have the same usage. If either of the
operands is a group item, the nonnumeric comparison rules apply.
For OSVS and VSC2 only: A nonnumeric literal can be enclosed in
parentheses.
The general format of a relation condition is as follows:
Note that the required relational characters "<" , ">", and "=" are not
underlined, to avoid confusion with other symbols such as ">=".
Note that "= TO", "> THAN" and "< THAN" will be accepted (OSVS).
The first operand (identifier-1, literal-1 or arithmetic-expression-1) is
called the subject of the condition; the second operand (identifier-2 or
literal-2 or arithmetic-expression-2) is called the object of the
condition. The relation condition must contain at least one reference to
a variable.
The relational operator specifies the type of comparison to be made in a
relation condition. A space must precede and follow each reserved word
comprising the relational operator. When used, "NOT" and the next key
word or relation character are one relational operator that defines the
comparison to be executed for truth value; for example, "NOT EQUAL" is a
truth test for an "unequal" comparison; "NOT GREATER" is a truth test for
an "equal" or "less" comparison. The meaning of the relational operators
is as shown in Table 4-8.
The following relational operators are equivalent:
IS EQUAL TO and EQUALS;
IS NOT EQUAL TO and IS UNEQUAL TO;
IS GREATER THAN and EXCEEDS;
IS NOT GREATER and IS LESS THAN OR EQUAL
THAN TO;
IS NOT LESS THAN and IS GREATER THAN OR
EQUAL TO.
Table 4-8 : Relational Operators
Comparison of Numeric Operands.
For operands whose class is numeric a comparison is made with respect to
the algebraic value of the operands. The length of the literal or
arithmetic expression operands in terms of number of digits represented,
is not significant. Zero is considered a unique value regardless of the
sign.
Comparison of these operands is permitted regardless
of the manner in which their usage is described. Unsigned numeric
operands are considered positive for purposes of comparison.
Numeric edited items are of class alphanumeric, and comparisons involving
them follow the rules for comparison of nonnumeric operands, as below.
Comparison of Nonnumeric Operands.
For nonnumeric operands, or one numeric and one nonnumeric operand, a
comparison is made with respect to a specified collating sequence of
characters (see the section The OBJECT-COMPUTER Paragraph earlier in this
chapter). If one of the operands is specified as numeric, it must be an
integer data item or an integer literal and:
1. If the nonnumeric operand is an elementary data item or a
nonnumeric literal, the numeric operand is treated as though it
were moved to an elementary alphanumeric data item of the same
size as the numeric data item (in terms of standard data format
characters), and the contents of this alphanumeric data item were
then compared to the nonnumeric operand. (See the section The
MOVE Statement in this chapter and the PICTURE character "P" in
the section Symbols Used earlier in this chapter.)
2. If the nonnumeric operand is a group item, the numeric operand is
treated as though it were moved to a group item of the same size
as the numeric data item (in terms of standard data format
characters), and the contents of this group item were then
compared to the nonnumeric operand. (See the section The MOVE
Statement in this chapter, and the PICTURE character "P" in the
section Symbols Used earlier in this chapter.)
3. A non-integer numeric operand cannot be compared to a nonnumeric
operand.
The size of an operand is the total number of standard data format
characters in the operand.
For OSVS only: Comparison of a numeric edited data item with figurative
constants is allowed and is treated as an alphanumeric comparison.
For MF only: Numeric and nonnumeric operands can be compared when
their usage is not the same. The numeric operand is treated as if it
were moved to a USAGE DISPLAY item of the same size (in terms of standard
data format characters), and the contents of this were then compared to
the nonnumeric operand.
There are two cases to consider:
1. Operands of equal size - if the operands are of equal size,
comparison effectively proceeds by comparing characters in
corresponding character positions starting from the high order end
and continuing until either a pair of unequal characters is
encountered or the low order end of the operand is reached,
whichever comes first. The operands are determined to be equal if
all pairs of characters compare equally through the last pair,
when the low order end is reached.
The first encountered pair of unequal characters is compared to
determine their relative position in the collating sequence. The
operand that contains the character that is positioned higher in
the collating sequence is considered to be the greater operand.
2. Operands of unequal size - if the operands are of unequal size,
comparison proceeds as though the shorter operand were extended on
the right by sufficient spaces to make the operands of equal size.
Comparisons Involving Index-Names and/or Index Data Items.
Relation tests can be made only between:
1. Two index-names. The result is the same as if the corresponding
occurrence numbers were compared.
2. An index-name and a numeric data item or numeric literal. The
occurrence number that corresponds to the value of the index-name
is compared to the data item or literal.
3. An index data item and an index-name or another index data item.
The actual values are compared without conversion.
4. For OSVS and VSC2 only: An index-name can be compared with an
arithmetic expression. The occurrence number that corresponds to
the value of the index-name is compared to the computed value of
the expression .
5. The result of the comparison of an index data item with any data
item or literal not specified above is undefined.
For VSC2 and MF only: Comparisons Involving Data Items with.
USAGE POINTER
Two items whose USAGE is either implicitly or explicitly POINTER can be
compared. Only the relational operators which test for exact equality or
inequality are permitted in pointer comparisons.
General Format.
Syntax Rules
1. Identifier-1 and identifier-3 refer to an 01 or 77 level items in
the Linkage Section.
2. For MF only: Identifier-1 and identifier-3 can refer to any
data items defined in the Data Division.
3. Identifier-2 and identifier-4 refer to items with USAGE IS
POINTER.
Only one operand in the comparison can be the figurative constant NULL.
General Rules.
1. The operands are equal if the two addresses are the same,
otherwise they are unequal.
2. This type of relation condition is allowed in IF, PERFORM,
EVALUATE and SEARCH (Format 1) statements. It is not allowed in
SEARCH (Format 2) statements (SEARCH ALL) because no meaningful
ordering can be applied to pointer data items.
For VSC2 and MF only: Comparisons Involving Data Items with USAGE
PROCEDURE-POIN.
Two items whose USAGE is PROCEDURE-POINTER can be compared.
General Format.
Syntax Rules.
1. Identifier-1 and identifier-2 refer to items with USAGE IS
PROCEDURE-POINTER.
2. Only one operand in the comparison can be the figurative constant
NULL.
General Rules.
1. The operands are equal if the two addresses are the same,
otherwise they are unequal.
2. This type of relation condition is allowed in IF, PERFORM,
EVALUATE and SEARCH (Format 1) statements. It is not allowed in
SEARCH (Format 2) statements (SEARCH ALL) because no meaningful
ordering can be applied to pointer data items.
Class Condition.
Function.
The class condition determines whether the operand is numeric, or
alphabetic or alphabetic-lower, or alphabetic-upper, or contains only the
characters in the set of characters specified by the CLASS clause as
defined in the SPECIAL-NAMES paragraph of the Environment Division
(ANS85 only).
General Format.
Syntax Rules.
1. The class of an operand is determined as follows:
a. An operand is numeric if it consists entirely of the
characters 0, 1, 2, 3,..., 9, with or without an
operational sign.
b. An operand is alphabetic if it consists entirely of the
uppercase letters A, B, C,..., Z, space, or the lowercase
letters a, b, c,..., z, space (ANS85 only) or any
combination of the uppercase and lowercase (ANS85 only)
letters and spaces.
c. For ANS85 only: An operand is alphabetic-lower if it
consists entirely of the lowercase letters a, b, c,..., z,
and space.
d. For ANS85 only: An operand is alphabetic-upper if it
consists entirely of the uppercase letters A, B, C,..., Z,
and space.
e. For ANS85 only: An operand conforms to class-name-1 if it
consists entirely of the characters listed in the
definition of class-name-1 in the SPECIAL-NAMES paragraph.
2. Identifier-1 must reference a data item whose usage is explicitly
or implicitly DISPLAY, or in the case of the NUMERIC test, as one
of DISPLAY,
COMPUTATIONAL, COMPUTATIONAL-X (MF),
COMPUTATIONAL-3 (OSVS, VSC2, MF and XOPEN).
COMPUTATIONAL-5 (MF and XOPEN)
PACKED-DECIMAL (ANS85).
3. For ANS85 only: If identifier-1 is a function-identifier, it must
reference an alphanumeric function.
General Rules.
1. When the class condition does not include the word NOT and
identifier-1 is a zero-length item, the result of the class test
is always false.
When used, "NOT" and the next key word specify one class condition
that defines the class test to be executed for truth value; for
example, "NOT NUMERIC" is a truth test for determining that an
operand is nonnumeric. When the class-condition includes the word
NOT, and identifier-1 is a zero-length group-item, the result of
the class test is always true.
For MF only: The truth value of a class test invloving a
zero-length group item is reversed by the ZEROLENGTHFALSE system
directive. See your COBOL System Reference for details.
2. The NUMERIC test cannot be used with an item whose data
description describes the item as alphabetic or as a group item
composed of elementary items whose data description indicates the
presence of operational sign(s). If the data description of the
item being tested does not indicate the presence of an operational
sign, the item being tested is determined to be numeric only if
the contents are numeric and an operational sign is not present.
If the data description of an elementary item being tested does
indicate the presence of an operational sign, the item being
tested is determined to be numeric only if the contents are
numeric and a valid operational sign is present. Valid
operational signs for data items described with the SIGN IS
SEPARATE clause are the standard data format characters, "+" and
"-"; valid operational signs for data items not described with the
SIGN IS SEPARATE clause are described in the section Selection of
Character Representation and Radix in the chapter Concepts of the
COBOL Language.
For MF and OSVS only: The NUMERIC test can be used with an item
defined as a group item composed of elementary items whose data
description indicates the presence of operational sign(s).
3. The ALPHABETIC test cannot be used with an item whose data
description describes the item as numeric. The item being tested
is determined to be alphabetic only if the contents consist of any
combination of the uppercase alphabetic characters "A" through "Z
" and the space and any combination of the lowercase alphabetic
characters "a" through "z" (ANS85) and the space.
For OSVS, VSC2 and MF only: The class condition cannot be used
for external floating- point (USAGE DISPLAY) or internal
floating-point (USAGE COMP-1 and USAGE COMP-2) items .
4. For ANS85 only: The ALPHABETIC-LOWER test cannot be used with an
item whose data description describes the item as numeric. The
result of the test is true if the content of the data item
referenced by identifier-1 consists entirely of the lowercase
alphabetic characters "a" through "z" and space.
5. For ANS85 only: The ALPHABETIC-UPPER test cannot be used with an
item whose data description describes the item as numeric. The
result of the test is true if the content of the data item
referenced by identifier-1 consists entirely of the uppercase
alphabetic characters "A" through "Z" and space.
6. For ANS85 only: The class-name-1 test must not be used with an
item whose data description describes the item as numeric.
Condition-Name Condition (Conditional Variable).
Function.
In a condition-name condition, a conditional variable is tested to
determine whether or not its value is equal to one of the values
associated with a condition-name.
General Format.
Syntax Rules.
1. For OSVS, VSC2 and MF only: Condition-names with DBCS and
internal floating-point items are allowed.
2. For MF only: Condition-names with external floating-point items
are allowed .
General Rules.
1. If the condition-name is associated with a value or range of
values, then the conditional variable is tested to determine
whether or not its value falls in this range, including the end
values.
2. The rules for comparing a conditional variable with a
condition-name value are the same as those specified for relation
conditions.
3. The result of the test is true if one of the values corresponding
to the condition-name equals the value of its associated
conditional variable.
Switch-Status Condition.
A switch-status condition determines the "on" or "off" status of one of
the nine (MF only) COBOL switches named respectively SWITCH 0 through
SWITCH 8 (MF only).
The value of each of these switches ("on" or "off" ) is set by the
operator at the start of execution of the COBOL object program. (See the
discussion of run-time switches in your COBOL System Reference for
details.) The switch and the "on" or "off" value associated with the
condition must be named in the SPECIAL-NAMES paragraph of the Environment
Division described earlier in this chapter.
General Format.
The result of the test is true if the switch is set to the specified
position corresponding to the condition-name.
It is only possible to use the Switch-Status Condition to test if a COBOL
switch is set from within the program that set the switch.
Sign Condition.
The sign condition determines whether or not the algebraic value of an
arithmetic expression is less than, greater than, or equal to zero. The
general format for a sign condition is as follows:
When used, "NOT" and the next keyword specify one sign condition that
defines that algebraic test to be executed for truth value; for example,
"NOT ZERO" is a truth test for a nonzero (positiveor negative) value. An
operand is positive if its value is greater than zero, negative if its
value is less than zero, and zero if its value is equal to zero. The
arithmetic expression must contain at least one reference to a variable.
ZEROS or ZEROES can be used instead of ZERO in a sign test (OSVS only).
Complex Conditions.
A complex condition is formed by combining simple conditions, combined
conditions and/or complex conditions with logical connectors (logical
operators "AND" and "OR" ) or negating these conditions with logical
negation (the logical operator "NOT"). The truth value of a complex
condition, whether parenthesized or not, is that truth value which
results from the interaction of all the stated logical operators on the
individual truth values of simple conditions, or the intermediate truth
values of conditions logically connected or logically negated.
The logical operators and their meanings are:
Operator Meaning
AND Logical conjunction; the truth value is
"true" if both of the conjoined conditions
are true; "false" if one or both of the
conjoined conditions is false.
OR Logical inclusive OR; the truth value is
"true" if one or both of the included
conditions is true; "false" if both
included conditions are false.
NOT Logical negation or reversal of truth
value; the truth value is "true" if the
condition is false; "false" if the
condition is true.
The logical operators must be preceded by a space and followed by a
space.
Negated Simple Condition.
A simple condition is negated through the use of the logical operator
"NOT". The negated simple condition effects the opposite truth value for
a simple condition. Thus the truth value of a negated simple condition
is "true" if and only if the truth value of the simple condition is
"false" ; the truth value of a negated simple condition is "false" if and
only if the truth value of the simple condition is "true". The inclusion
in parentheses of a negated simple condition does not change the truth
value.
General Format.
Combined and Negated Combined Condition.
A combined condition results from connecting conditions with one of the
logical operators "AND" or "OR".
General Format.
MPE/iX 5.0 Documentation