No matter how hard you try, keeping bad data out of the database is next to impossible. Many shops have had that point painfully driven home as they revamped their software and database files for Y2K. When stored in alpha or numeric fields, dates are as susceptible to corruption as is any other type of data.
Anand Veluri has written a utility that finds bad date values in database files: Retrieve Format Errors (RTVFMTERRS). It can handle the usual date formats, such as YMD, MDY, DMY, and Julian, as well as a host of others. The utility is written in CL and COBOL and requires a COBOL compiler, but because most readers of MC dont have a COBOL compiler, I have translated the program into RPG. However, the RPG version doesnt support all the date formats that the original COBOL version supports.
RTVFMTERRS consists of four source members, which are listed in Figure 1. You must compile the first threeRTVFMTERRS, RTVFMTERRC, and RTVFMTSCANbut the fourth, RTVFMTSMPL, is a template from which a date verification program is generated.
How It Works
RTVFMTERRS has four parameters: Qualified file name, Member name, Field name, and Date format. In the first two parameters, you tell which file contains the data to be verified. In the third parameter, key the name of the field as it is named in the files external definition. In the last parameter, key a code to indicate the format in which the date should be stored.
The CL program creates three program-described work files in QTEMP if they dont already exist in one of the libraries on the library list. Two of the work files hold source code; the third stores data about invalid dates. The CL program copies the template source code into one of the work files. Program RTVFMTSCAN reads this source code and updates it with the names of the file and field being tested for validity. The updated source is then placed into the second work file.
At this point, the CL program calls the COBOL or RPG compiler to compile the generated source code into QTEMP. If the compilation is successful, the temporary program runs, loading data about invalid dates into the third work file.
The last step is to print the work file. Doing this gives you a report that identifies, by relative record number, all records containing invalid date values. (Figure 2 shows an example of this report.)
Differences Between the Versions
The RPG rendition of the utility is not an exact translation of Anands COBOL version. There are several minor differences in the command definition and CL program, none of which is worth noting here.
The only important difference is in the date formats that the utility supports. Figure 3 lists the 52 format codes supported by the COBOL version. This version supports the usual date formats, such as YMD, MDY, DMY, and Julian. In addition, you can validate edited date fields and partial date fields (e.g., date fields with only year and month portions).
When I developed the RPG version, I did not attempt to support all these formats. Instead, I opted to support the formats that were acceptable with the TEST op code. I also added an additional format, a four-digit field in MMYY format, to illustrate how you can add support for other formats to the RPG version.
Figure 4 shows a portion of the date verification routine. Notice the format code in columns 1 through 5 of the calculation specs; the generated program ignores any lines that do not match the format code keyed in the Format parameter. To support another date format, add the necessary lines of code to the RTVFMTSMPL member and put the date format abbreviation in columns 1 through 5 of each line. You can also condition other specificationssuch as C-specs that lie outside this subroutine, D-specs, or entire subproceduresin the same way, although I didnt do so in this example.
Ready for Clean Data?
The source code for this utility is available from the Midrange Computing Web site at www.midrangecomputing.com/mc/. Be sure to use either the COBOL version or the RPG version in its entirety. Do not mix portions of each.
Armed with the report from RTVFMTERRS, you can begin to fix invalid date values and track how theyve been entering your database. You can also use this utility to verify that your Y2K-ready software is performing as it should.
Member Type Description
RTVFMTERRS CMD Command interface
RTVFMTERRC CLP Command-processing program
RTVFMTSCAN CBL Generates COBOL source code to verify date fields
RTVFMTSMPL CBL Template for generating COBOL source code
Figure 1: RTVMTERRS uses these four source members.
Library File Member Field Format RelRecNo ErrType FieldValue
-QGPL XACTS *FIRST XDATE YMD 0000000005 M-ERROR 951301
Figure 2: The report identifies invalid dates by relative record number.
C first two digits of four-digit year
D two-digit day
F one-digit century flag (0=19xx, 1=20xx)
JUL three-digit Julian date (without year)
M two-digit month
X separator character
Y last two digits of four-digit year
C
CY
CYJUL
CYM
CYMD
CYXD
CYXJUL
CYXM
CYXMXD
D
DCY
DM
DMCY DMY
DXCY
DXM
DXMXCY
DXMXY
DXY
DY
DYM
F
FY
FYJUL
FYM
FYMD FYXD
FYXJUL
FYXM
FYXMXD
JUL
M
MCY
MD
MDCY
MDY
MXCY
MXD
MXDXCY
MXDXY
MXY
MY
MYD
Y
YD
YDM
YM
YMD
YXD
YXJUL
YXM
YXMXD
Figure 3: The COBOL version supports 52 date formats.
xxxxx *** Put calcs to verify fields of each format in the following
xxxxx *** section. Place the format ID in columns 1-5. Each routine
xxxxx *** should turn on indicator 08 if the date is invalid.
YMD C *ymd test (d) FIELDSNAME 08
DMY C *dmy test (d) FIELDSNAME 08
MDY C *mdy test (d) FIELDSNAME 08
JUL C *jul test (d) FIELDSNAME 08
YMD0 C *ymd0 test (d) FIELDSNAME 08
DMY0 C *dmy0 test (d) FIELDSNAME 08
MDY0 C *mdy0 test (d) FIELDSNAME 08
JUL0 C *jul0 test (d) FIELDSNAME 08
CMDY0C *cmdy0 test (d) FIELDSNAME 08
MY C movel FIELDSNAME ###month 2
MY C move FIELDSNAME ###year 2
MY C move 000100 ###datemdy 6
MY C movel ###month ###datemdy
MY C move ###year ###datemdy
MY C *mdy0 test (d) ###datemdy 08
Figure 4: Columns 1 through 5 add support for more date formats.
LATEST COMMENTS
MC Press Online