National comparisons
A national comparison is a comparison of the national character value of
two operands of class national.
When the relation condition specifies an operand that is not class
national, that operand is converted to a data item of category national before
the comparison. The following list describes the conversion of operands to
category national.
- DBCS
- A DBCS operand is treated as though it were moved to a temporary data item
of category national of the same length as the DBCS operand. DBCS characters
are converted to the corresponding national characters. The source code page
used for the conversion depends
on whether the DBCS operand is an EBCDIC or ASCII data item. If the DBCS
operand is an EBCDIC data item (that is, the compiler option CHAR(EBCDIC) is
in effect and the NATIVE phrase is not specified for the operand), the
EBCDIC code page in effect for the operand is used; otherwise, the code page
indicated by the locale in effect for the operand is used. For details, see Appendix G. Locale considerations.
- Alphabetic, alphanumeric, alphanumeric-edited, and numeric-edited
with usage DISPLAY
- The operand is treated as though it were moved to a temporary data item
of
category national of the length needed to represent the number of
character positions in that operand. Alphanumeric characters are converted
to the corresponding national characters. The source code page used for the
conversion depends on
whether the alphanumeric operand is an EBCDIC or ASCII data item. If the
alphanumeric operand is an EBCDIC data item (that is, the compiler option
CHAR(EBCDIC) is in effect and the NATIVE phrase is not specified for the
operand), the EBCDIC code page in effect for the operand is used; otherwise,
the code page indicated by the locale in effect for the operand is used. For
details, see Appendix G. Locale considerations.
- Numeric integer
- A numeric integer operand is treated as though it were moved to a
temporary data item of category alphanumeric of a length the same as the
number of digits in the integer. The unsigned value is used. The resulting
temporary data item is then converted as an alphanumeric operand.
- External floating-point
- A display floating-point item is treated as though it were a data
item of category alphanumeric, rather than as a numeric value, and then
converted as an alphanumeric operand.
A national floating-point item is treated as though it were a data
item of category national, rather than as a numeric value.
The implicit moves for the conversions are carried out in accordance
with the rules of the MOVE statement.
The resulting
category national data item is used in the
comparison of two national operands.
The method used for comparison is determined by the setting
of the NCOLLSEQ compiler option.
If the NCOLLSEQ(BINARY) compiler option is in effect, the
collating sequence is determined by the binary values of national characters.
The comparison proceeds as follows:
- If the operands are of unequal length, the comparison
proceeds as though the shorter operand were padded on the right with the
default national space character (NX'0020') to make the operands of equal
length. The comparison then proceeds according to the rules for the
comparison of operands of equal length.
- If the operands are of equal length, the comparison proceeds by comparing
corresponding national character positions in the two operands, starting
from the leftmost position, until either unequal national characters are
encountered or the rightmost national character position is reached,
whichever comes first. The operands are determined to be equal if all
corresponding national characters are equal.
- The first-encountered unequal national character in the operands is
compared to determine the relation of the operands. The operand that
contains the national character with the higher collating value is the
greater operand.
If the NCOLLSEQ(LOCALE) compiler option is in effect, the
collating sequence is determined by the runtime locale. For purposes of
comparison, trailing spaces are truncated from the operands except that an
operand consisting of all spaces is truncated to a single space. Locale-based
comparison is not necessarily a character-by-character comparison. If the
shorter operand were extended with spaces as for a nonlocale-based comparison,
the result might not be the culturally-expected result. For information about
locales, see Appendix G. Locale considerations.
The PROGRAM COLLATING SEQUENCE clause has no effect on comparisons of
national operands.
|