A very high percentage of AS/400 software systems were not designed to handle the change of the century. In fact, Gartner Group estimates that, without corrective measures, 90 percent of all applications and systems will be affected by the year 2000 date change by 1999, producing unknown or erroneous results. It also estimates that addressing the year 2000 date change will cost as much as $600 billion. (Yes, you read that right. That's billion with a b.)
The problem exists primarily because most business systems have dates stored in six-digit formats and are not capable of handling the change of the century. These systems will interpret the two-digit year 00 as 1900, not 2000. As a result, many programs will crash and burn on or before January 1, 2000, if they are left unchanged.
If you think that you can wait until 1998 or 1999 to start thinking about the problem, you could be in big trouble. The magnitude of the problem can be mind-boggling. Many systems have routines that calculate projected dates or follow-up dates in the future. These routines could begin to have problems long before the year 2000.
So, are you planning to retire in the next three years, or are you thinking about job security? The fact that you are still reading tells us that you will not be shuffling off to Leisure World anytime soon. But since you are an AS/400 programmer, not all of this is gloom and doom. The introduction of RPG IV includes the ability to work with the date data type. Careful implementation of this new technology can offer some pretty significant shortcuts that will take your software well into the 21st century.
Data fields may now be designated as date data types when they are defined in DDS or RPG IV definition specifications. Along with this new data type, we have been introduced to a series of new operation codes that were designed to help us manipulate dates. Routines that use a series of moves or math routines to switch the format of dates from month-day-year to year-month-day are a thing of the past. As you'll see, complicated routines to increment or decrement dates are now unnecessary, too.
The date data type allows you to store your data in a number of six- and eight-digit date formats (see 1), all of which include the century. The date separator is automatically stored with your data, making the field lengths appear to be either six, eight, or ten characters. In other words, if you print or look at your data on the screen, you will see your date fields in the date format you defined with the separator characters already in place. The number and style of the separator character that appears depend upon the date format chosen.
The date data type allows you to store your data in a number of six- and eight-digit date formats (see Figure 1), all of which include the century. The date separator is automatically stored with your data, making the field lengths appear to be either six, eight, or ten characters. In other words, if you print or look at your data on the screen, you will see your date fields in the date format you defined with the separator characters already in place. The number and style of the separator character that appears depend upon the date format chosen.
Date fields are entirely interchangeable. Moving a date stored in the *ISO format to a date field that has been defined with a *MDY date format requires only a simple move operation.
One of the good things about the date data type is that, regardless of the date format chosen, DB2/400 stores the new date data type fields in only 4 bytes on disk, which happens to be the same amount of storage required to store a six-digit date in packed format. So, as you convert your six-digit date fields from numeric or packed data types to the new date data types, you won't notice an increase in DASD use.
You may find that there is no longer a reason to store dates in your database in year-month-day format just to get the key sequence you want. Date fields are stored and compared based upon their chronological value, so you may even want to store the dates in month-day-year format. Doing so means that you will not need to convert the date when you print it on a report. You can compare a date stored in month-day-year format to a date stored in Julian date format, or any of the other supported date formats, without performing any kind of conversion and still get your desired results. As a matter of fact, you don't even need to use an edit code or an edit word when printing dates.
Before you run off to reformat all of your date fields into month-day-year format, however, you need to be aware that the six-digit date fields (*YMD, *MDY, and *DMY) cover only the years from 1940 to 2039. This should be ample for most transaction dates but may be unacceptable in systems that perform some type of forecasting function or that record birth dates, which could easily be prior to 1940.
The reason for this anomaly is the way IBM employed its date windowing algorithms as they apply to the six-digit date. The system automatically assumes that, when this format is used, the two-digit years between 40 and 99 are for the 20th century, and the years between 00 and 39 belong in the 21st century. Consequently, the system-defined *LOVAL for a date field differs depending upon the date format chosen. If a date is defined with the eight-digit *ISO format type, *LOVAL is going to be 0001-01-01. If a date field is defined with the six-digit *YMD format, *LOVAL is going to be 40/01/01.
One thing that makes working with date data types relatively painless is the operation codes that have been introduced in RPG IV. Four new operation codes (as illustrated in 2) allow you to perform a variety of date manipulation functions. These operation codes are designed to work with the date, time, and time-stamp data types that are part of the DB2/400 database.
One thing that makes working with date data types relatively painless is the operation codes that have been introduced in RPG IV. Four new operation codes (as illustrated in Figure 2) allow you to perform a variety of date manipulation functions. These operation codes are designed to work with the date, time, and time-stamp data types that are part of the DB2/400 database.
Date fields are very particular about data validity. If you define a field as a date data type, the system expects to see a valid date in that field. If there is any question about the content of the data you're going to place in a date field, you should use the TEST operation code described in 2 to check the field prior to placing it in the date field. If you think you can just leave zeros in a date field, forget it. The system will insist that you allow only valid dates in a field defined with a date data type.
Date fields are very particular about data validity. If you define a field as a date data type, the system expects to see a valid date in that field. If there is any question about the content of the data you're going to place in a date field, you should use the TEST operation code described in Figure 2 to check the field prior to placing it in the date field. If you think you can just leave zeros in a date field, forget it. The system will insist that you allow only valid dates in a field defined with a date data type.
You knew it sounded too good to be true, didn't you? The bad news is that V3R1 doesn't support the date data type for display files or printer files. Why, you ask? We wish we knew. But it really is not much of an obstacle, as you will see.
We put together a simple RPG IV program that tests dates keyed at a workstation by using two of the new date operation codes. The display file in 3 has a six-digit numeric field called date. Two messages are used to reflect whether the date keyed is valid or not. The program in 4 first tests the date field to see if it's a valid date based on the *MDY format specified in factor 1 of the TEST operation code. We could have made the date field alphanumeric, but the system would have insisted that the date keyed include the date separator characters before it would be considered valid. You can see an example of the output from our simple program in 5.
We put together a simple RPG IV program that tests dates keyed at a workstation by using two of the new date operation codes. The display file in Figure 3 has a six-digit numeric field called date. Two messages are used to reflect whether the date keyed is valid or not. The program in Figure 4 first tests the date field to see if it's a valid date based on the *MDY format specified in factor 1 of the TEST operation code. We could have made the date field alphanumeric, but the system would have insisted that the date keyed include the date separator characters before it would be considered valid. You can see an example of the output from our simple program in Figure 5.
If the date keyed is valid and function key F5 is pressed, the Subtract Duration (SUBDUR) operation code is used to subtract one month from the date. If the date test is passed and function key F6 is pressed, the Add Duration (ADDDUR) operation code is used to increment the date by one day. In both examples of these operation codes, the value to be added or subtracted is specified in factor 2 as well as the duration interval. Valid duration intervals for date data types are *D (days), *M (months), and *Y (years). You'll notice that we had to move the date field to a field defined with a date type before performing the ADDDUR or SUBDUR operations. While TEST may be performed on fields that are not defined with a date data type, that's not the case with the ADDDUR, SUBDUR, or Extract (EXTRCT) operations.
Entering the new millennium is going to be an "E-ticket ride" for most of us in data processing. But if you plan carefully and far enough ahead, you just may avoid many of the pitfalls that your counterparts are certain to experience. Proper use and implementation of the new date data type will help ease your pain.
Doug Pence is the founder and Ron Hawkins is the research and development manager of Computer Processing Unlimited, Inc., in San Diego, California. They are the authors of Power RPG III, published by Midrange Computing. Doug Pence can be reached by E-mail at
REFERENCE
AS/400 ILE RPG/400 Reference (SC09-1526, CD ROM QBKAQE00).
Are You Ready to Play the Dating Game?
Figure 1: RPG IV Date Data Types
Are You Ready to Play the Dating Game?
Figure 2: RPG IV Operation Codes for Date and Time Manipulation
Are You Ready to Play the Dating Game?
Figure 3: The DATESDF Display File
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A DSPSIZ(24 80 *DS3) A R FORMAT1 A CF03 A CF05 A CF06 A 1 36'Date Test' A DSPATR(HI) A 9 35'Date:' A DATE 6D 0B 9 41 A 98 ERRMSG('You keyed a Valid Date!') A 99 ERRMSG('Invalid Date!') A 23 2'F3=Exit' A COLOR(BLU) A 23 13'F5=Subtract a month' A COLOR(BLU) A 23 36'F6=Add a day' A COLOR(BLU)
Are You Ready to Play the Dating Game?
Figure 4: The DATESRG Program
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+ FDATESDF CF E Workstn D Workdate S D Datfmt(*MDY) C DOU *Inkc = *on C EXFMT Format1 C MOVEA '00' *In(98) C *MDY TEST(D) Date 99 C IF *In99 * Test failed, date is invalid. Display error message C ITER C ENDIF * If no function keys were pressed, just send the message C *Inke IFEQ *off C *Inkf ANDEQ *off C EVAL *In98 = *on C ITER C ENDIF C MOVE Date WorkDate C SELECT * If F5 was pressed, decrement date and redisplay screen C WHEN *Inke = *on C SUBDUR 1:*M WorkDate * If F6 was pressed, increment date and redisplay screen C WHEN *Inkf = *on C ADDDUR 1:*D WorkDate C ENDSL C MOVE WorkDate Date C ENDDO C EVAL *Inlr = *onAre You Ready to Play the Dating Game?
Figure 5: Example of the DATESRG Program
LATEST COMMENTS
MC Press Online