Rational Developer for System z
Enterprise COBOL for z/OS, Version 4.1, Language Reference


Comparison of date fields

Date fields can be alphanumeric category, zoned decimal, or internal decimal; the existing rules for the validity and comparison type (numeric or alphanumeric) apply. For example, an alphanumeric date field cannot be compared with an internal decimal date field. In addition to these rules, two date fields can be compared only if they are compatible; they must have the same date format except for the year part, which can be windowed or expanded.

For year-last date fields, the only comparisons that are supported are IS EQUAL TO and IS NOT EQUAL TO between two year-last date fields with identical date formats, or between a year-last date field and a nondate.

Table 1 shows supported comparisons for nonyear-last date fields. This table uses the following terms to describe how the comparisons are performed:

Nonwindowed
The comparison is performed with no windowing, as if the operands were both nondates.
Windowed
The comparison is performed as if:
  1. Any windowed date field in the relation were expanded according to the century window specified by the YEARWINDOW compiler option, as described under Semantics of windowed date fields.

    This expansion is sensitive to trigger values in the date field comparand if the DATEPROC(TRIG) compiler option is in effect.

  2. Any repetitive alphanumeric figurative constant were expanded to the size of the windowed date field with which it is compared, giving an alphanumeric nondate comparand. Repetitive alphanumeric figurative constants include ZERO (in an alphanumeric context), SPACE, LOW-VALUE, HIGH-VALUE, QUOTE and ALL literal.
  3. Any nondate operands were treated as if they had the same date format as the date field, but with a base year of 1900.

    If the DATEPROC(NOTRIG) compiler option is in effect, the comparison is performed as if the nondate operand were expanded by assuming 19 for the century part of the expanded year.

    If the DATEPROC(TRIG) compiler option is in effect, the comparison is sensitive to date trigger values in the nondate operand. For alphanumeric operands, these trigger values are LOW-VALUE, HIGH-VALUE, and SPACE. For alphanumeric and numeric operands compared with windowed date fields with at least one X in the DATE FORMAT clause (that is, windowed date fields other than just a windowed year), values of all zeros or all nines are also treated as triggers. If a nondate operand contains a trigger value, the comparison proceeds as if the nondate operand were expanded by copying the trigger value to the assumed century part of the expanded year. If the nondate operand does not contain a trigger value, the century part of the expanded year is assumed to be 19.

The comparison is then performed according to normal COBOL rules. Alphanumeric comparisons are not changed to numeric comparisons by the prefixing of the century value.

Table 1. Comparisons with date fields
 


Nondate
second operand

Windowed
date field
second operand

Expanded
date field
second operand

Nondate
first operand

Nonwindowed Windowed1 Nonwindowed

Windowed date field
first operand

Windowed1 Windowed Windowed

Expanded date field
first operand

Nonwindowed Windowed Nonwindowed
  1. When compared with windowed date fields, nondates are assumed to contain a windowed year relative to 1900. For details, see item 3 under the definition of "Windowed" comparison.

Relation conditions can contain arithmetic expressions. For information about the treatment of date fields in arithmetic expressions, see Arithmetic with date fields.


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)