ILE COBOL Language Reference

Comparison of Numeric and Nonnumeric Operands

Rules for numeric and nonnumeric comparisons are given in the following tables. If either of the operands is a group item, nonnumeric comparison rules apply.

Table 21 summarizes permissible comparisons with nonnumeric operands.

Table 22 summarizes permissible comparisons with numeric operands.

The symbols used in Table 21 and Table 22 are as follows:


Table 21. Permissible Comparisons with Nonnumeric Second Operands

FIRST OPERAND SECOND OPERAND
GR AL AN ANE NE FC1 NNL DB DBE DA TI TS NL
NONNUMERIC OPERAND
Group (GR) NN NN NN NN NN NN NN

NN NN NN NN
Alphabetic (AL) NN NN NN NN NN NN NN




NLN
Alphanumeric (AN) NN NN NN NN NN NN NN

NN NN NN NLN
Alphanumeric Edited (ANE) NN NN NN NN NN NN NN

NN NN NN
Numeric Edited (NE) NN NN NN NN NN NN NN

NU NU NU
Figurative Constant (FC1) NN NN NN NN NN






NL4
Nonnumeric Literal (NNL) NN NN NN NN NN



NN NN NN NLN
DBCS items (DB)3






NN NN


NLN
DBCS-edited items (DBE)3






NN NN



Date (DA)3 NN
NN NN NU
NN

DT
DT
Time (TI)3 NN
NN NN NU
NN


DT DT
Timestamp (TS)3 NN
NN NN NU
NN

DT DT DT
National (NL) NN NLN NLN

NL4 NLN NLN



NL
NUMERIC OPERAND
Figurative Constant ZERO (ZR) NN NN NN NN NN







Numeric Literal (NL) NN NN NN NN NN



NU NU NU
External Decimal (ED)2 NN NN NN NN NN NN NN

NU NU NU
Binary (BI)








NU NU NU
Arithmetic Expression (AE)








NU NU NU
Boolean data item or Boolean Literal (BO)3












Internal Decimal (ID)








NU NU NU
Internal Floating-Point (IFP)3












External Floating-Point (EFP)3 NN3 NN3 NN3 NN3 NN3 NN3 NN3





Floating-Point Literal (FPL)3













Table 22. Permissible Comparisons with Numeric Second Operands

FIRST OPERAND SECOND OPERAND
ZR NL ED BI AE BO ID IFP3 EFP3 FPL3
NONNUMERIC OPERAND
Group (GR) NN NN NN2




NN3
Alphabetic (AL) NN NN NN2




NN3
Alphanumeric (AN) NN NN NN2




NN3
Alphanumeric Edited (ANE) NN NN NN2




NN3
Numeric Edited (NE) NN NN NN2




NN3
Figurative Constant (FC1)

NN2




NN3
Nonnumeric Literal (NNL)

NN2




NN3
Date (DA)
NU NU2 NU NU
NU


Time (TI)
NU NU2 NU NU
NU


Timestamp (TS)
NU NU2 NU NU
NU


NUMERIC OPERAND
Figurative Constant ZERO (ZR)

NU NU NU NU3 NU NU3 NU3
Numeric Literal (NL)

NU NU NU
NU NU3 NU3
External Decimal (ED) NU NU NU NU NU
NU NU3 NU3 NU3
Binary (BI) NU NU NU NU NU
NU NU3 NU3 NU3
Arithmetic Expression (AE) NU NU NU NU NU
NU NU3 NU3 NU3
Boolean data item or Boolean Literal (BO)3 NU3



NU3



Internal Decimal (ID) NU NU NU NU NU
NU NU3 NU3 NU3
Internal Floating-Point (IFP)3 NU3 NU3 NU3 NU3 NU3
NU3 NU3 NU3 NU3
External Floating-Point (EFP)3 NU3 NU3 NU3 NU3 NU3
NU3 NU3 NU3 NU3
Floating-Point Literal (FPL)3

NU3 NU3 NU3
NU3 NU3 NU3

Notes to Table 21 and Table 22:

1
Includes all figurative constants except ZERO and NULL

2
Integer item only

3
IBM extension

4
Only for SPACE

Comparing Numeric Operands

The algebraic values of numeric operands are compared.

Comparing Nonnumeric Operands

Comparisons of nonnumeric operands

are made with respect to the collating sequence of the character set in use.

When the PROGRAM COLLATING SEQUENCE clause is specified in the OBJECT-COMPUTER paragraph, the collating sequence associated with the alphabet-name clause in the SPECIAL-NAMES paragraph is used. Otherwise, the native EBCDIC character set is used.

The size of each operand is the total number of characters in that operand. There are two cases to consider:

Operands of Equal Size
Characters in corresponding positions of the two operands are compared, beginning with the leftmost character and continuing through the rightmost character.

If all pairs of characters through the last pair test as equal, the operands are considered equal.

If a pair of unequal characters is encountered, the characters are tested to determine their relative positions in the collating sequence. The operand containing the character higher in the sequence is considered the greater operand.

Operands of Unequal Size
If the operands are of unequal size, the comparison is made as though the shorter operand were extended to the right with enough spaces to make the operands equal in size.

Comparing Numeric and Nonnumeric Operands

The nonnumeric comparison rules, discussed above, apply. In addition, when numeric and nonnumeric operands are being compared, their USAGE must be the same. In such comparisons:

If either of the operands is a group item, the nonnumeric comparison rules, discussed above, apply. In addition to those rules:

+-------------------------------IBM Extension--------------------------------+

Comparing Boolean Operands

Boolean operands are used only in the [NOT] EQUAL TO relation condition. Boolean operands cannot be compared to non-Boolean operands. Boolean data items and literals must be one position in length. Two Boolean operands are equal if they both have a value of Boolean 1 or Boolean 0.

+----------------------------End of IBM Extension----------------------------+

+-------------------------------IBM Extension--------------------------------+

Comparing DBCS Operands

The rules for comparing DBCS or DBCS-edited operands are the same as those for the comparison of nonnumeric operands. The comparison is based on a binary collating sequence of the hexadecimal values of the DBCS characters. The PROGRAM COLLATING clause of the OBJECT-COMPUTER paragraph will have no effect on this.

+----------------------------End of IBM Extension----------------------------+

+-------------------------------IBM Extension--------------------------------+

Comparing National Operands

An operand of class NATIONAL may be compared to another operand of class NATIONAL. The result of such a comparison is based on the binary collating sequence of the hexadecimal values of the UCS-2 character set. If two operands have unequal size, the shorter one is padded to the right with the padding character specified in the Padding Character compile option or the equvilant process option. The default is the UCS-2 double-byte space character (NX"3000").

+----------------------------End of IBM Extension----------------------------+

+-------------------------------IBM Extension--------------------------------+

Comparing National and Non-National Operands

An operand of class NATIONAL may be compared with an Alphabetic data item, an Alphanumeric data item, a DBCS data item, a Nonnumeric literal, or a DBCS literal.

The data item or literal that is not a national item is treated as though it were moved, in accordance with the rules of the MOVE statement, to an elemntary data item of class national and the same logical length. The converted value is then compared to the national operand. If the items are of different length, the shorter item is padded to the right with the padding character specified in the Padding Character compile option, or the equivalant process option. The default is the UCS-2 single-byte space character if the non-national operand is a single-byte item, or the UCS-2 double-byte space character (NX"3000") if the non-national operand is a double-byte item.

+----------------------------End of IBM Extension----------------------------+

+-------------------------------IBM Extension--------------------------------+

Comparing Date-Time Operands

If an item of class date-time is compared to a nonnumeric operand (except for numeric-edited operands), the date-time item is treated as if it were nonnumeric.

During the comparison of an item of class date-time to an numeric-edited or numeric operand, the date-time item is de-edited. De-editing results in a numeric integer. This numeric integer is then numerically compared with the other operand.

During the comparison of one date-time item with another, the items are first converted to a common date, time, or timestamp format, and then compared. Characters that are part of a format literal, but which are not conversion specifiers (for example the / or - characters), have no effect on a date-time comparison.

When comparing a date item to a timestamp item, only the date portion of the timestamp is considered. When comparing a time item to a timestamp item, only the time portion of the timestamp is considered.

+----------------------------End of IBM Extension----------------------------+

Comparing Index-Names and Index Data Items

Comparisons involving index-names and/or index data items conform to the following rules:

Table 23 shows valid comparisons involving index-names and index data items.

Table 23. Comparisons Involving Index Names and Index Data Items

Operands Compared Index-Name Index Data Item Data-Name Literal Arithmetic Expression
Index-Name Compare occurrence number Compare without conversion Compare occurrence number with data-name Compare occurrence number with literal Compare occurrence number with arithmetic expression
Index Data Item Compare without conversion Compare without conversion Not permitted Not permitted Not permitted


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]