Compare Operations

The compare operations are shown in the following table.

Table 1. Compare Operations
Operation Traditional Syntax Free-Form Syntax
And ANDxx (And) AND operator
Compare COMP (Compare) =, <, >, <=, >=, or <> operator
Compare and Branch CABxx (Compare and Branch) (not allowed)
Conditional Subroutine CASxx (Conditionally Invoke Subroutine) IF (If) and EXSR (Invoke Subroutine)
Do Until DOU (Do Until) or DOUxx (Do Until) DOU (Do Until)
Do While DOW (Do While) or DOWxx (Do While) DOW (Do While)
If IF (If) or IFxx (If) IF (If)
Or ORxx (Or) OR operator
When WHEN (When True Then Select) or WHENxx (When True Then Select) WHEN (When True Then Select)
In the ANDxx, CABxx, CASxx, DOUxx, DOWxx, IFxx, ORxx, and WHENxx operations, xx can be:
xx
Meaning
GT
Factor 1 is greater than factor 2.
LT
Factor 1 is less than factor 2.
EQ
Factor 1 is equal to factor 2.
NE
Factor 1 is not equal to factor 2.
GE
Factor 1 is greater than or equal to factor 2.
LE
Factor 1 is less than or equal to factor 2.
Blanks
Unconditional processing (CASxx or CABxx).

The compare operations test fields for the conditions specified in the operations. These operations do not change the values of the fields. For COMP, CABXX, and CASXX, the resulting indicators assigned in postions 71 and 76 are set according to the results of the operation. All data types may be compared to fields of the same data type.

Remember the following when using the compare operations:

Attention!

Note the following points, especially if you want to avoid unpredictable results.
  • The order of the characters is not necessarily the same for UCS-2 data as it is for character or graphic data; for example '2' is less than 'A' in UCS-2, but it is greater than 'A' for a character comparison. If a comparison operation involves implicit conversion to UCS-2, or if you change some of your fields to have UCS-2 type instead of character or graphic type, then you may notice that some less-than or greater-than comparisons have different results than you expect.
  • All graphic and UCS-2 comparisons are done using the hexadecimal representation of the data. The alternate sequence is not used.
  • If an alternate collating sequence (using the ALTSEQ{(*NONE | *SRC | *EXT)} keyword on the Control specification) has been specified for the comparison of character fields, the comparands are converted to the alternate sequence and then compared. If *HIVAL or *LOVAL is used in the comparison, the alternate collating sequence may alter the value before the compare operation. Note that if either comparand is defined with the ALTSEQ(*NONE) keyword on the definition specification, the alternate collating sequence is not used.
  • When comparing a basing pointer to *NULL (or to a basing pointer with value *NULL), the only comparisons that produce predictable results are for equality and inequality.
  • Comparing pointers for less-than or greater-than produces predictable results only when the pointers point to addresses in contiguous storage. For example, all pointers are set to addresses in one *USRSPC, or all pointers are set to the addresses of array elements in one array.
  • When procedure pointer fields are compared for anything except equality or inequality, the results will be unpredictable.
  • Because of the way float values are stored, they should not be compared for equality or inequality. Instead, the absolute value of the difference between the two values should be compared with a very small value.