If you cannot change all of your applications and data before the year 2000 you can leave your data alone and change your application to interpret 2-digit years as 4-digit years. This type of technique is generally referred to as windowing. With this technique you can take a 2-digit year and determine a 4-digit year based on a predefined 100-year window. For example, given the window 1940 to 2039:
There are two ways to do windowing in ILE COBOL. You can perform the windowing yourself with the aid of the ILE COBOL intrinsic functions, or you can let ILE COBOL perform the windowing by changing your numeric or character dates into date data items.
If you want to do the windowing yourself, ILE COBOL provides a set of century window Intrinsic Functions, which allow 2-digit years to be interpreted in a 100-year window (because each 2-digit number can only occur once in any 100-year period). You select the period, give the Intrinsic Function a 2-digit year, or a date or day with a two-digit year, and the Intrinsic Function will return the appropriate value with a 4-digit year in that 100-year window.
The ILE COBOL compiler provides three century window intrinsic functions: YEAR-TO-YYYY, DAY-TO-YYYYDDD, and DATE-TO-YYYYMMDD. The YEAR-TO-YYYY Intrinsic Function takes a 2-digit year and returns a 4-digit year in a specified 100-year window. The other two Intrinsic Functions take a date that contains a 2-digit year and returns a date with a 4-digit year in a specified 100-year window. For the DAY-TO-YYYYDDD Intrinsic Function, the date taken is a 5-digit number with a format like that of the ACCEPT FROM DAY statement. Similarly, the DATE-TO-YYYYMMDD Intrinsic Functions takes a 6-digit number with a format like that of the ACCEPT FROM DATE statement.
Form more information about the century window Intrinsic Functions, refer to the WebSphere Development Studio: ILE COBOL Reference.
In order for ILE COBOL to perform the windowing for you, you must change your character or numeric dates into date data items. In the code fragment below there are two numeric items that represent dates. The code is going to display a message if the current date is past the expiration date.
01 my-dates. * expiration-date is year 1997, month 10, day 9 05 expiration-date PIC S9(6) VALUE 971009 USAGE PACKED-DECIMAL. * current-date-1 is year 2002, month 8, day 5 05 current-date-1 PIC S9(6) VALUE 020805 USAGE PACKED-DECIMAL. IF current-date-1 > expiration-date THEN DISPLAY "items date is past expiration date" END-IF.
In the above code even though 2002 is greater than 1997, the numeric values 020805 is not greater than 971009, so the IF will evaluate to FALSE, and the DISPLAY statement will not be run. However, by changing the numeric dates to date data items the DISPLAY statement will run. Notice that the size (in bytes) of both expiration-date and current-date-1 has not changed:
01 my-dates. * expiration-date is year 1997, month 10, day 9 05 expiration-date FORMAT DATE "%y%m%d" VALUE "971009" USAGE PACKED-DECIMAL. * current-date-1 is year 2002, month 8, day 5 05 current-date-1 FORMAT DATE "%y%m%d" VALUE "020805" USAGE PACKED-DECIMAL. IF current-date-1 > expiration-date THEN DISPLAY "items date is past expiration date" END-IF.
The advantage of the short-term solution is that you need to change only a few programs, and you do not need to change your databases. This approach is cheaper, quicker, and easier than the long-term solution.
However, you can use the century window Intrinsic Functions to convert your databases or files from 2-digit year dates to 4-digit year dates. You can do this by reading in the 2-digit year dates, interpreting them to get 4-digit years, and then rewriting the data into a copy of the original that has been expanded to hold the 4-digit year data. All new data would then go into the new file or database.
This approach buys you only a few years, depending on the application. You still must eventually change all date programs and databases.
You cannot use the century window forever because a 2-digit year can only be unique in a given 100-year period. Over time you will need more than 100 years for your data window--in fact, many companies need more than 100 years now.
The reason that the century window buys you more time is that you know in any given section of ILE COBOL code whether you are trying to figure out if a date is old (the date is in the past) or if a due date has not yet been reached (the date is in the future). You can then use this knowledge to determine how to set your century window.
There are limitations, though. For example, the century window cannot solve the problem of trying to figure out how long a customer has been with your company, if the time-span is greater than 100 years and you only have 2-digit years in your dates. Another example is sorting. All of the records that you want to sort by date must have 4-digit year dates. For these problems and others, you need to use ACCEPT statements, Intrinsic Functions, or ILE date services which return a 4-digit year.
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.