Compaq COBOL AAQ2G1FTK User Manual

Page 114

Advertising
background image

Handling Nonnumeric Data
3.4 Testing Nonnumeric Items

Table 3–1 Relational Operator Descriptions

Operator

Description

IS [NOT] GREATER THAN
IS [NOT] >

The first operand is greater than (or not greater
than) the second operand.

IS [NOT] LESS THAN
IS [NOT] <

The first operand is less than (or not less than) the
second operand.

IS [NOT] EQUAL TO
IS [NOT] =

The first operand is equal to (or not equal to) the
second operand.

IS GREATER THAN OR
EQUAL TO
IS >=

The first operand is greater than or equal to the
second operand.

IS LESS THAN OR EQUAL TO
IS <=

The first operand is less than or equal to the second
operand.

3.4.1.1 Classes of Data

Compaq COBOL allows comparison of both numeric class operands and
nonnumeric class operands; however, it handles each class of data differently.
For example, it allows a comparison of two numeric operands regardless of the
formats specified in their respective USAGE clauses, but it requires that all other
comparisons (including comparisons of any group items) be between operands
with the same usage. It compares numeric class operands with respect to their
algebraic values and nonnumeric (or numeric and nonnumeric) class operands
with respect to a specified collating sequence. (See Section 2.5.1 for numeric
comparisons.)

If only one of the operands is numeric, it must be an integer data item or an
integer literal, and it must be DISPLAY usage. In these cases, the manner
in which the compiler handles numeric operands depends on the nonnumeric
operand, as follows:

If the nonnumeric operand is an elementary item or a literal, the compiler
treats the numeric operand as if it had been moved into an alphanumeric
data item the same size as the numeric operand and then compared. This
causes any operational sign, whether carried as a separate character or as
an overpunched character, to be stripped from the numeric item so that it
appears to be an unsigned quantity.

In addition, if the PICTURE character-string of the numeric item contains
trailing P characters, indicating that there are assumed integer positions that
are not actually present, they are filled with zero digits. Thus, an item with
a PICTURE character-string of S9999PPP is moved to a temporary location
where it is described as 9999999. If its value is 432J (–4321), the value in
the temporary location will be 4321000. The numeric digits take part in the
comparison.

If the nonnumeric operand is a group item, the compiler treats the numeric
operand as if it had been moved into a group item the same size as the
numeric operand and then compared. This is equivalent to a group move.

The compiler ignores the description of the numeric item (except for length)
and, therefore, includes in its length any operational sign, whether carried as
a separate character or as an overpunched character. Overpunched characters
are never ASCII numeric digits. They are characters ranging from A to R,
left brace ( { ), or right brace ( } ). Thus, the sign and the digits, stored as

3–4 Handling Nonnumeric Data

Advertising