Manipulating literals as dates

If a windowed date field has an associated level-88 condition-name, then the literal in the VALUE clause is windowed against the century window of the compile unit rather than against the assumed century window of 1900-1999.

About this task

For example, suppose you have these data definitions:


05  Date-Due        Pic 9(6)  Date Format yyxxxx.
    88  Date-Target           Value 101220.

If the century window is 1950-2049, and the contents of Date-Due are 101220 (representing December 20, 2010), then the first condition below evaluates to true, but the second condition evaluates to false:


If Date-Target. . .
If Date-Due = 101220

The literal 101220 is treated as a nondate; therefore it is windowed against the assumed century window of 1900-1999, and represents December 20, 1909. But where the literal is specified in the VALUE clause of a level-88 condition-name, the literal becomes part of the data item to which it is attached. Because this data item is a windowed date field, the century window is applied whenever that data item is referenced.

You can also use the DATEVAL intrinsic function in a comparison expression to convert a literal to a date field. The resulting date field is treated as either a windowed date field or an expanded date field to ensure a consistent comparison. For example, using the above definitions, both of the following conditions evaluate to true:


If Date-Due = Function DATEVAL (101220 "YYXXXX")
If Date-Due = Function DATEVAL (20101220 "YYYYXXXX")

With a level-88 condition-name, you can specify the THRU option on the VALUE clause, but you must specify a fixed century window in the YEARWINDOW compiler option rather than a sliding window. For example:


05  Year-Field  Pic 99  Date Format yy.
    88 In-Range         Value 98 Thru 06.

With this form, the windowed value of the second item in the range must be greater than the windowed value of the first item. However, the compiler can verify this difference only if the YEARWINDOW compiler option specifies a fixed century window (for example, YEARWINDOW(1940) rather than YEARWINDOW(-70)).

The windowed order requirement does not apply to year-last date fields. If you specify a condition-name VALUE clause with the THROUGH phrase for a year-last date field, the two literals must follow normal COBOL rules. That is, the first literal must be less than the second literal.