Compatible dates
The meaning of the term compatible dates depends
on whether the usage occurs in the DATA DIVISION
or
the PROCEDURE DIVISION
.
The DATA
DIVISION
usage deals with the declaration of date fields,
and the rules that govern COBOL language elements such as subordinate
data items and the REDEFINES
clause. In the following
example, Review-Date
and Review-Year
are
compatible because Review-Year
can be declared as
a subordinate data item to Review-Date
:
01 Review-Record.
03 Review-Date Date Format yyxxxx.
05 Review-Year Pic XX Date Format yy.
05 Review-M-D Pic XXXX.
The PROCEDURE
DIVISION
usage deals with how date fields can be used together
in operations such as comparisons, moves, and arithmetic expressions.
For year-first and year-only date fields to be considered compatible,
date fields must have the same number of nonyear characters. For example,
a field with DATE FORMAT YYXXXX
is compatible with
another field that has the same date format and with a YYYYXXXX
field,
but not with a YYXXX
field.
Year-last date fields must have identical DATE FORMAT
clauses.
In particular, operations between windowed date fields and expanded
year-last date fields are not allowed. For example, you can move a
date field that has a date format of XXXXYY
to another XXXXYY
date
field, but not to a date field that has a format of XXXXYYYY
.
You can perform operations on date fields, or on a combination of date fields and nondates, provided that the date fields in the operation are compatible. For example, assume the following definitions:
01 Date-Gregorian-Win Pic 9(6) Packed-Decimal Date Format yyxxxx.
01 Date-Julian-Win Pic 9(5) Packed-Decimal Date Format yyxxx.
01 Date-Gregorian-Exp Pic 9(8) Packed-Decimal Date Format yyyyxxxx.
The following statement is inconsistent because the number of nonyear digits is different between the two fields:
If Date-Gregorian-Win Less than Date-Julian-Win . . .
The following statement is accepted because the number of nonyear digits is the same for both fields:
If Date-Gregorian-Win Less than Date-Gregorian-Exp . . .
In this case the century window is applied to the windowed date
field (Date-Gregorian-Win
) to ensure that the comparison
is meaningful.
When a nondate is used in conjunction with a date field, the nondate is either assumed to be compatible with the date field or is treated as a simple numeric value.