Click here for HP sponsor message

Readying COBOL for Year 2000

By Shawn M. Gordon


The Year 2000 problem has turned into the hottest topic in data processing in the last year or so, and has caused an amazing resurgence of interest in COBOL. The college near my house has dropped Pascal and added COBOL in the last year, and it’s mostly due to this situation. All this interest isn’t due to COBOL’s inate ability to deal with dates or the Year 2000. As a matter of fact, there is no way to declare a date type variable in COBOL. The interest lies in the fact that most of the year 2000 code problems reside in COBOL code. So my topic this this month is how can you get 4 digit years in COBOL to make your code Year 2000 compliant.

Figure 1

  01 FULL-CURRENT-DATE.



     03 F-DATE.


        05 F-YEAR       PIC 9(4).

        05 F-MONTH      PIC 99.

        05 F-DAY        PIC 99.

     03 F-TIME.

        05 C-HOUR       PIC 99.

        05 C-MINUTES    PIC 99.

        05 C-SECONDS    PIC 99.

        05 C-SEC-HUND   PIC 99.

     03 C-TIME-DIFF.

        05 C-GMT-DIR    PIC X.

        05 C-HOUR       PIC 99.

        05 C-MINUTES    PIC 99.



Figure 2

     MOVE FUNCTION CURRENT-DATE TO
FULL-CURRENT-DATE.
     DISPLAY 'COBOL CURRENT-DATE [' FULL-CURRENT-DATE ']'.

     DISPLAY 'COBOL CURR-DATE    [' CURRENT-DATE ']'.

     DISPLAY 'COBOL TIME-OF-DAY  [' TIME-OF-DAY ']'.

     ACCEPT C-DATE FROM DATE.
     DISPLAY 'COBOL DATE         [' C-DATE ']'.
     ACCEPT C-TIME FROM TIME.
     DISPLAY 'COBOL TIME         [' C-TIME ']'.
     ACCEPT C-DAY FROM DAY.
     DISPLAY 'COBOL JULIAN DAY   [' C-DAY ']'.
     ACCEPT C-WEEK FROM DAY-OF-WEEK.
     DISPLAY 'COBOL DAY-OF-WEEK  [' C-WEEK ']'.

     DISPLAY SPACES.
     CALL INTRINSIC 'DATELINE' USING DATE-BUFF.
     DISPLAY 'DATELINE           [' DATE-BUFF ']'.

     CALL INTRINSIC 'CLOCK' GIVING I-TIME.
     CALL INTRINSIC 'FMTCLOCK' USING I-TIME, Z-TIME.

     DISPLAY 'CLOCK/FMTCLOCK     [' Z-TIME ']'.
     CALL INTRINSIC 'CALENDAR' GIVING I-CAL.
     CALL INTRINSIC 'FMTCALENDAR' USING I-CAL, Z-CAL.

     DISPLAY 'CALENDAR/FMTCAL    [' Z-CAL ']'.
     CALL INTRINSIC 'FMTDATE' USING I-CAL, I-TIME, DATE-BUFF.

     DISPLAY 'FMTDATE            [' DATE-BUFF ']'.

Figure 3

COBOL CURRENT-DATE [1997120610342000-0500]
COBOL CURR-DATE    [12/06/97]
COBOL TIME-OF-DAY  [07:34:20]
COBOL DATE         [971206]
COBOL TIME         [07342090]
COBOL JULIAN DAY   [97340]
COBOL DAY-OF-WEEK  [6]

DATELINE           [SAT, DEC  6, 1997,  7:34 AM]

CLOCK/FMTCLOCK     [ 7:34 AM]
CALENDAR/FMTCAL    [SAT, DEC  6, 1997]
FMTDATE            [SAT, DEC  6, 1997,  7:34 AM]
        
As I recall, on the HP we had COBOL 68, COBOL 74, COBOL 85, and then the 89 addendum to the 85 standard. I believe there was supposed to be a COBOL 93, but it has now turned into COBOL 2000, and it will be way too late to help with any Year 2000 coding issues. It wasn’t until the 89 addendum that there was a native way to deal with 4 digit years. Prior to that the only way to do it was with the DATELINE intrinsic, and to pull the year out of the middle of the string.

When the 89 addendum added the FUNCTION keyword, it also added a large number of date handling routines. As a matter of fact, you can now natively do date math within COBOL. The problem is that it’s a rather roundabout process. For our purposes we are going to look at the only native COBOL function I am aware of that returns the four-digit year – the CURRENT-DATE function. If you look at Figure 1, you will see a definition of the record structure that the CURRENT-DATE function will return.

There are a number of native constructs for getting various date and time information from COBOL. In Figure 2 you will see how to use the CURRENT-DATE function, as well as most of the other, older COBOL date/time constructs. Figure 3 shows the output of all these functions. As you can see, most situations can be easily handled within COBOL. The only thing I would like to see is a century date returned as well as the Julian date that is currently in place.

Next month I plan on discussing macros in COBOL, always a personal favorite. Don’t forget, if your tips make it into The Wire, you get a free 3000 Always Online hat. Send them to me at smga@compuserve.com, or fax them to the NewsWire at 512.331.3807.


Copyright 1998, The 3000 NewsWire. All rights reserved.