Inside Cobol #47 (COBOL and the Year 2000)
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 by 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.
As I recall, on the HP we had COBOL 68, COBOL 74, COBOL 85, and then the 89 addendum to the 85 standard. There was supposed to be a COBOL 93 I believe, but it has now turned into COBOL 2000, and will be way to 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 round about process. For our purposes we are going to look at the only native COBOL function that I am aware of that returns the 4 digit year, and that is 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, so in Figure 2 you will see how to use the CURRENT-DATE function, as well as a most of the other, older COBOL date/time constructs. Figure 3 show’s 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 is up in the air, but I think we might have a discussion on MACROS in COBOL, always a personal favorite. Don’t forget, if your tips make it into The Wire, you get a free 3000 News Wire hat.
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  COBOL TIME  COBOL JULIAN DAY  COBOL DAY-OF-WEEK  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]