Y2K Site Map | Terms of Use | Problem | Steps | Certification | Briefings | Compliance | Solutions | BIOS | Test & Evaluation | Cost


The following Y2K material has been kept available by MITRE for historical purposes only and has not been updated unless noted.

MITRE - Y2K - COBOL Examples
COBOL Examples


Setup of Data

The following examples ignore 'little' details like error and null date handling. They are written in a Cobol-like pseudo code.

The input routine would work like this:

    STD-DATE = Convert-Date-Input (INPUT-DATE, SOURCE-TYPE)

The output routine would work like this:

    OUTPUT-DATE = Convert-Date-Output (STD-DATE, DESTINATION-TYPE)
Assume the following definitions:
  10   STD-DATE         PIC X(08)  /* YYYYMMDD, char format*/
   15  STD-DATE-CC      PIC X(02)
   15  STD-DATE-YYMMDD  PIC X(06)  /* YYMMDD, char format */
    20 STD-DATE-YY      PIC X(02)
    20 STD-DATE-MMDD    PIC X(04)
  10   INPUT-DATE          PIC X(08)  /* indeterminate format */
  10   INPUT-FORMAT-FULL   REDEFINES INPUT-DATE.
   15  INPUT-DATE-CCYYMMDD PIC 9(08) /* YYYYMMDD, numeric format*/
  10   INPUT-FORMAT-SHORT  REDEFINES INPUT-DATE.
   15  INPUT-DATE-YYMMDD   PIC X(06)  /* YYMMDD, char format*/
    20 INPUT-DATE-YY       PIC X(02)
    20 INPUT-DATE-MMDD     PIC X(04)
    20 INPUT-DATE-SURPLUS  PIC X(02)
  10   INPUT-FORMAT-PACKED REDEFINES INPUT-DATE. /* 6 bytes */
   15  INPUT-DATE-BYTE-1   PIC X(01)
   15  INPUT-DATE-PACKED-CCYYMMDD PIC S9(09) COMP-3
  10   OUTPUT-DATE         PIC X(08)  /* indeterminate format */
  10   OUTPUT-FORMAT-FULL  REDEFINES OUTPUT-DATE.
   15  OUTPUT-DATE-CCYYMMDD  PIC X(08)  /* yyYYMMDD, char format */
    25 OUTPUT-DATE-CC      PIC X(02)
    25 filler              PIC X(06)  /* YYMMDD, char format */
  10   OUTPUT-FORMAT-SHORT REDEFINES OUTPUT-DATE. /* 6 Bytes */
   15  OUTPUT-DATE-YYMMDD  PIC X(06)  /* YYMMDD, char format */
    20 OUTPUT-DATE-YY      PIC X(02)
    20 OUTPUT-DATE-MMDD    PIC X(04)
  10   OUTPUT-FORMAT-PACKED REDEFINES OUTPUT-DATE. /* 6 Bytes */
   15  OUTPUT-DATE-PACKED-YYMMDD PIC S9(11) COMP-3
                          /* HEX: 00 0Y YY YM MD DF  */
Example #1. Changing to a fixed window approach.

Suppose system XYZ stores its dates in format character YYMMDD, e.g. '960623'. If XZY only deals with dates in a 10-year window, then this code might suffice:

  Convert-Date-Input code:
    IF SOURCE-TYPE = 'XYZ'
      MOVE INPUT-DATE TO STD-DATE-YYMMDD
      /* use the good old date window technique */
      IF INPUT-DATE-YY < '90'
        MOVE '20' TO STD-DATE-CC
      ELSE
        MOVE '19' TO STD-DATE-CC
      END-IF
      RETURN STD-DATE
  Convert-Date-Output code:
    IF DESTINATION-TYPE = 'XYZ'
      MOVE STD-DATE-YYMMDD TO OUTPUT-DATE-YYMMDD /* Drop Century */
      RETURN OUTPUT-DATE

Conversion of programs can be done one at a time.

Example #2. Refining the fixed window approach.

Suppose that testing finds that the windowing approach did not work in one case. Birthdates go back to 1930. We could refine our definition of "source" for that special case:

  Convert-Date-Input code:
    IF SOURCE-TYPE = 'XYZ' or 'XYZ-BIRTHDATE'
      MOVE INPUT-DATE TO STD-DATE-YYMMDD
      /* use the good old date window technique */
      IF SOURCE-TYPE = 'XYZ-BIRTHDATE'
        IF INPUT-DATE-YY < '30'
          MOVE '20' TO STD-DATE-CC
        ELSE
          MOVE '19' TO STD-DATE-CC
        END-IF
      ELSE
        IF INPUT-DATE-YY < '90'
          MOVE '20' TO STD-DATE-CC
        ELSE
          MOVE '19' TO STD-DATE-CC
        END-IF
      END-IF
      RETURN STD-DATE

Date-windowing may be crude, but cost-effective in many cases. Every 10 years or so the window threshold would have to be shifted.

Example #3. Changing to a packed date in the same location.

Of special interest is field reuse, changing from character (e.g. character YYMMDD) to compressed formats(e.g. packed yyyymmdd) such as binary or packed because often the cost to expand or move a field is huge, much more than the reprogramming cost.

Instead of adding special exceptions to help us deduce the full date, we can reuse the same 6-byte field and put the full date in it. The input routine can dynamically deduce the input format by inspecting the first byte.

  Convert-Date-Input code:
    IF SOURCE-TYPE = 'XYZ'  /* this line is optional */
      /* Deduce the input format from the first byte */
      IF INPUT-DATE-BYTE-1 = LOW-VALUES   /* is it hex 00? */
        MOVE INPUT-DATE-PACKED-CCYYMMDD TO STD-DATE-CCYYMMDD
      ELSE  /* must be old character format */
        MOVE INPUT-DATE-YYMMDD TO STD-DATE-YYMMDD
        /* use the good old date window technique */
        IF INPUT-DATE-YY < '90'
          MOVE '20' TO STD-DATE-CC
        ELSE
          MOVE '19' TO STD-DATE-CC
        END-IF
      END-IF
      RETURN STD-DATE
  Convert-Date-Output code, starts out as:
    IF DESTINATION-TYPE = 'XYZ'
      MOVE STD-DATE-YYMMDD TO OUTPUT-DATE-YYMMDD
      RETURN OUTPUT-DATE

When all programs are modified to use these routines, then the output routine can be modified to pack system XYZ's dates:

  Convert-Date-Output code:
    IF DESTINATION-TYPE = 'XYZ'
      MOVE STD-DATE-CCYYMMDD TO OUTPUT-DATE-PACKED-YYMMDD
      RETURN OUTPUT-DATE


For further information directly related to Year 2000 issues, please contact Year2000@mitre.org

Information is provided by the MITRE Y2K Team
Last modified: Thursday, 14-Feb-2008 09:21:05 EST