General Format:
Note that the required relational characters "<" , ">", and "=" are not underlined, to avoid confusion with other symbols
such as '>' (greater than or equal to).
General Rules:
- 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 topic
The Object-Computer Paragraph). If one of the operands is specified as numeric, it must be an integer data item or an integer literal and:
- 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 topic
The MOVE Statement.)
- 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 topic
The MOVE Statement.)
- 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.
- Comparison of a numeric-edited data item with figurative constants is allowed and is treated as an alphanumeric comparison.
- 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:
- 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.
- 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.
- A UTF-81 comparison is a comparison between two operands of class UTF-8. When either of those operands is not of class UTF-8, that
operand is converted to an item of class UTF-8 before the comparison.
- If the operands are of unequal length, the comparison is performed as if the shorter operand were padded (with trailing UTF-8
space characters) to the length of the other operand.
- If the operands are of equal length (or assumed to be, due to the additional padding), the comparison compares each corresponding
character position, starting at the left-most position, until either unequal UTF-8 characters are encountered or the right-most
character position is reached, whichever comes first. The operands are considered equal if all corresponding UTF-8 characters
are equal.
- When the first unequal character is encountered, it is compared to determine the relationship of the operands. The operand
that contains the UTF-8 character with the higher collating sequence value is the greater operand.
Note: The higher collating sequence value is determined using the hexadecimal value of characters; the PROGRAM COLLATING SEQUENCE
clause has no effect on UTF-8 comparisons.