Eight years ago, myself and a guy from Cleveland migrated some S/34 applications to the IBM S/38. One of the most common problems we had was decimal data errors occurring when running the S/38 programs. At the time, we decided to compile all the migrated code with IGNDECERR(*YES). Several months later, bizarre field values began showing up in some of the files. It was then I learned that blanks in unpacked numeric fields were not treated like zeros (as they are on the S/36 and prior S/3x computers). Fortunately for me, the guy from Cleveland was left with the task of finding and correcting the data errors.
There is a similar problem on the AS/400. Migrated S/36 code works fine as long as the files are only read and updated by S/36 programs. However, as soon as native AS/400 languages are used, the decimal data error raises its ugly head. S/36 DFU has a lot to do with the problem. Any file with unpacked numeric fields defined, that has records added via S/36 DFU, will have blanks stored in these fields if the operator does not key in a value.
To start, we decided to externally define our files before writing native programs. There were several reasons for doing this. For one, the S/36 programs still work fine on externally defined files, and it didn't make sense to write native programs using program described files. We began writing native code (and fix programs for the bad data) after the files referenced by the program were externally defined.
I finally wrote a generic command, FIXDECERR one Sunday afternoon after having spent several hours tracking down another decimal data error problem. I'd spent many more hours on previous occasions writing file-dependent decimal data error fix programs (I'd even established a naming convention for them!). Since we have several accounts that migrated from the S/36, and many more that will, we needed this command for these customers. Requiring each of them to buy a commercial program for this purpose did not make sense and writing fix programs had become frustrating.
FIXDECERR should normally be used as a one-time fix for files that contain invalid numeric data. After the fields in error are found, whatever is causing the problem should be corrected so it does not happen again. FIXDECERR does have other redeeming qualities. If you're getting data from outside sources, FIXDECERR can be used to check the integrity of this information.
FIXDECERR works on any externally defined file as long as the record length is under 4096 bytes, and there are less than 300 fields defined per record. The command has an option to list fields in error along with the relative record number of the offending data. (See 1 for a sample listing.)
FIXDECERR works on any externally defined file as long as the record length is under 4096 bytes, and there are less than 300 fields defined per record. The command has an option to list fields in error along with the relative record number of the offending data. (See Figure 1 for a sample listing.)
The update option has three values, *NONE, *INZDGT and *INZFLD.
The effects of specifying *INZDGT or *INZFLD are the same on packed data. Any invalid data in a packed field results in the field being initialized to zeros. Unpacked signed decimal fields will have invalid digits replaced with zeros if *INZDGT is specified, and if *INZFLD is specified, any digit in error will cause the field to be initialized to zeros. When *NONE is specified, fields will not be updated, regardless of errors or data type.
The two parameters that follow the update option identify which types of fields to check. Specifying *NO next to the corresponding data type indicates that no field with this data type is to be checked, updated or listed.
As with any program of this nature, be careful. I would suggest using the list option with no updating when you first use the program. Verify from the report that the fields listed are in error before running the job with the *INZFLD or *INZDGT update options. *INZDGT is probably the only update option you should use. This will retain the value of signed decimal fields (replacing blanks with zeros). I shouldn't have to say this, but please make sure you have a current backup of the file before you use one of the update options.
To install The FIXDECERR system, key the source code in Figures 2-6 and compile each source member according to the instructions at the bottom of each figure.
Good luck with your conversions!
Stamp Out Decimal Data Errors
Figure 1 Sample report of decimal errors (unable to show)
Stamp Out Decimal Data Errors
Figure 2 Command FIXDECERR
FIXDECERR: CMD PROMPT('Fix Decimal Data Errors') PARM KWD(FILE) TYPE(QUAL1) MIN(1) PROMPT('File to + check') PARM KWD(MBR) TYPE(*NAME) DFT(*FIRST) + SPCVAL((*FIRST)) EXPR(*YES) PROMPT('Member') PARM KWD(LSTERR) TYPE(*CHAR) LEN(4) RSTD(*YES) + DFT(*YES) VALUES(*YES *NO) EXPR(*YES) + PROMPT('List fields in error') PARM KWD(UPDOPT) TYPE(*CHAR) LEN(7) RSTD(*YES) + DFT(*NONE) VALUES(*NONE *INZFLD *INZDGT) + EXPR(*YES) PROMPT('Field update option') PARM KWD(CHKSIGNED) TYPE(*CHAR) LEN(4) RSTD(*YES) + DFT(*YES) VALUES(*YES *NO) EXPR(*YES) + PROMPT('Check signed decimal') PARM KWD(CHKPACKED) TYPE(*CHAR) LEN(4) RSTD(*YES) + DFT(*YES) VALUES(*YES *NO) EXPR(*YES) + PROMPT('Check packed decimal') QUAL1: QUAL TYPE(*NAME) LEN(10) MIN(1) EXPR(*YES) QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) + SPCVAL((*LIBL)) EXPR(*YES) + PROMPT('Library')
Stamp Out Decimal Data Errors
Figure 3 CL program DEC001CL
DEC001CL: + PGM PARM(&QF &MBR &LSTERR &UPDOPT &CHKSIGNED &CHKPACKED) DCL VAR(&CHKPACKED) TYPE(*CHAR) LEN(4) DCL VAR(&CHKSIGNED) TYPE(*CHAR) LEN(4) DCL VAR(&EXTDEF) TYPE(*CHAR) LEN(1) DCL VAR(&FILNAM) TYPE(*CHAR) LEN(10) DCL VAR(&LIB) TYPE(*CHAR) LEN(10) DCL VAR(&LSTERR) TYPE(*CHAR) LEN(4) DCL VAR(&MBR) TYPE(*CHAR) LEN(10) DCL VAR(&QF) TYPE(*CHAR) LEN(20) DCL VAR(&UPDOPT) TYPE(*CHAR) LEN(7) /* Break qualified name */ CHGVAR VAR(&FILNAM) VALUE(%SST(&QF 1 10)) CHGVAR VAR(&LIB) VALUE(%SST(&QF 11 10)) /* Check for file and member existence */ CHKOBJ OBJ(&LIB/&FILNAM) OBJTYPE(*FILE) MBR(&MBR) MONMSG MSGID(CPF9801) EXEC(DO) SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('File' *BCAT + &FILNAM *BCAT 'not found in' *BCAT &LIB) MSGTYPE(*ESCAPE) RETURN ENDDO MONMSG MSGID(CPF9810) EXEC(DO) SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Library' *BCAT + &LIB *BCAT 'not found') MSGTYPE(*ESCAPE) RETURN ENDDO MONMSG MSGID(CPF9815) EXEC(DO) SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Member' *BCAT + &MBR *BCAT 'not found') MSGTYPE(*ESCAPE) RETURN ENDDO /* Verify that the file is externally described */ CLRPFM FILE(QTEMP/FILEATR) MONMSG MSGID(CPF0000) DSPFD FILE(&LIB/&FILNAM) TYPE(*BASATR) OUTPUT(*OUTFILE) + OUTFILE(QTEMP/FILEATR) OVRDBF FILE(FILEATR) TOFILE(QTEMP/FILEATR) CALL PGM(DEC001RG) PARM(&EXTDEF) IF COND(&EXTDEF *NE 'Y') THEN(DO) SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('File' *BCAT + &FILNAM *BCAT 'is not externally described') MSGTYPE(*ESCAPE) RETURN ENDDO /* Output the file field definitions */ CLRPFM FILE(QTEMP/FILEFFD) MONMSG MSGID(CPF0000) DSPFFD FILE(&LIB/&FILNAM) OUTPUT(*OUTFILE) OUTFILE(QTEMP/FILEFFD) OVRDBF FILE(FILEFFD) TOFILE(QTEMP/FILEFFD) OVRDBF FILE(DATAIN) TOFILE(&LIB/&FILNAM) MBR(&MBR) CALL PGM(DEC001RGA) PARM(&CHKSIGNED &CHKPACKED &UPDOPT &LSTERR) ENDPGM
Stamp Out Decimal Data Errors
Figure 4 RPG program DEC001RG
FFILEATR IP E DISK * C *ENTRY PLIST C PARM ATFLS
Stamp Out Decimal Data Errors
Figure 5 Printer file DEC001P1
A R HEADINGS SKIPB(6) A 1DATE EDTCDE(Y) A 14TIME EDTWRD(' . . ') A 26'File:' A WHFILE 10A O 32 A 47'Update Option:' A USUPOP 7A O 62 A 77'Check S/P:' A USSIGN 4A O 88 A USPACK 4A O 93 A 122'Page:' A 129PAGNBR EDTCDE(3) A SPACEA(1) A 1'FIXDECERR' A 24'Format:' A WHNAME 10A O 34 A 47'Length:' A WHRLEN 5S 0O 55EDTCDE(3) A 77'Text:' A WHTEXT 50A O 83 A SPACEA(2) A 11'Field' A 23'Start' A 30'Length' A 38'Field' A SPACEA(1) A 3'Record' A 11'Name' A 23'Pos.' A 30'Bytes' A 38'Type' A 45'Value' A 77'Description' A SPACEA(2) * A R DETAIL SPACEA(1) A RECNO 8S 0O 1EDTCDE(3) A FLDNAM 10A O 11 A FLDBEG 5S 0O 23EDTCDE(3) A FLDLEN 5S 0O 31EDTCDE(3) A FLDTYP 1A O 40 A FLDHEX 30A O 45 A FLDDSC 50A O 77
Stamp Out Decimal Data Errors
Figure 6 RPG program DEC001RGA
FDATAIN UP F 4096 DISK KINFDS INFDS FFILEFFD IF E DISK FDEC001P1O E 99 PRINTER * E REC 4096 1 Input record E REX 4096 1 Sav Rec/Hex Dsp E HX 30 1 Hex Value E TABHEX 1 16 2 0ATABCHA 1 Hex Cnv Tbl * IDATAIN NS I 14096 REC IINFDS DS * Relative Record # I B 397 4000RECNOX * Field information IFLDINF DS 300 I 1 50FLDBEG I 6 100FLDLEN I 11 11 FLDTYP I 12 61 FLDDSC I 62 71 FLDNAM * Convert array to field for printer file I DS I 1 30 HX I 1 30 FLDHEX * Constants I '1' C ON I '0' C OFF *===================================================== C *ENTRY PLIST C PARM USSIGN 4 C PARM USPACK 4 C PARM USUPOP 7 C PARM USLSER 4 * C MOVE OFF ERRREC 1 C Z-ADDRECNOX RECNO 80 C MOVELREC REX * C 1 DO S X 50 C X OCUR FLDINF C EXSR CHKNUM C END * C USUPOP IFNE '*NONE' C ERRREC ANDEQON C EXCPTUDATA C END *===================================================== C CHKNUM BEGSR * Validate Numeric Data * ERRPOS is on if indiviudal position is in error * and is off for the next position test * ERRFLD is on when any error occurs in the filed test * and is off when the next field is tested C Z-ADDFLDBEG ST 50 C MOVE OFF ERRFLD 1 * C 1 DO FLDLEN Y 50 C MOVELREC,ST WKD 1 C MOVE OFF ERRPOS 1 * C FLDTYP IFEQ 'P' C EXSR VALPCK C END * C FLDTYP IFEQ 'S' C EXSR VALDEC * Initialize field position to zero - Signed decimal only C USUPOP IFEQ '*INZDGT' C ERRPOS ANDEQON C MOVELOFF REC,ST C END C END * C ERRPOS IFEQ ON C MOVE ON ERRFLD C END * C ADD 1 ST C END * Initialize field to zeros and calculate hex value C ERRFLD IFEQ ON C MOVE ON ERRREC C Z-ADD1 H 50 C Z-ADDFLDBEG ST 50 C MOVEL*BLANKS HX * C 1 DO FLDLEN Y C MOVEAREX,ST HEXCNV 1 C EXSR HEXCNX C H IFLE 30 C MOVEAHEXCHA HX,H C END C ADD 2 H * C USUPOP IFEQ '*INZFLD' C FLDTYP ANDEQ'S' C MOVELOFF REC,ST C END * C USUPOP IFNE '*NONE' C FLDTYP ANDEQ'P' C MOVELX00 REC,ST * C Y IFEQ FLDLEN C MOVELX0F REC,ST C END C END * C ADD 1 ST C END C END * Print Error Report C USLSER IFEQ '*YES' C ERRFLD ANDEQON C *IN99 IFEQ ON C WRITEHEADINGS C MOVE OFF *IN99 C END C WRITEDETAIL C END C ENDSR *===================================================== C VALDEC BEGSR * Validate single signed numeric characters (WKD) C WKD IFGT '9' C WKD ORLT '0' * Test digit portion first C MOVELWKD CNVDIG 1 C EXSR CNVDIX * C DIGIT IFGT 9 C MOVE ON ERRPOS C END * Test zone portion next C MOVELWKD CNVZON 1 C EXSR CNVZOX * C ZONE IFNE 15 Sign + C ZONE ANDNE13 Sign - C MOVE ON ERRPOS C END * Sign valid on last character only C ZONE IFEQ 13 C Y ANDNEFLDLEN C MOVE ON ERRPOS C END C END C ENDSR *===================================================== C VALPCK BEGSR * Validate packed numeric characters (WKD) * Test zone portion first C MOVELWKD CNVZON 1 C EXSR CNVZOX * C ZONE IFGT 9 C MOVE ON ERRPOS C END * Test digit portion next C MOVELWKD CNVDIG 1 C EXSR CNVDIX * Not last digit must be value 0-9 C Y IFNE FLDLEN C DIGIT ANDGT9 C MOVE ON ERRPOS C END * Last digit must be sign value C Y IFEQ FLDLEN C DIGIT ANDNE13 Sign - C DIGIT ANDNE15 Sign + C MOVE ON ERRPOS C END C ENDSR *===================================================== C HEXCNX BEGSR * Convert character to hex value (Display purposes) C MOVEL*BLANKS HEXCHA 2 C MOVELHEXCNV CNVZON C EXSR CNVZOX * C ZONE LOKUPTABHEX TABCHA 50 C 50 MOVELTABCHA HEXCHA * C MOVELHEXCNV CNVDIG C EXSR CNVDIX * C DIGIT LOKUPTABHEX TABCHA 50 C 50 MOVE TABCHA HEXCHA C ENDSR *===================================================== C CNVDIX BEGSR * Convert digit portion of character to number C Z-ADD0 DIGIT 20 C TESTB'4' CNVDIG 50 C 50 DIGIT ADD 8 DIGIT C TESTB'5' CNVDIG 50 C 50 DIGIT ADD 4 DIGIT C TESTB'6' CNVDIG 50 C 50 DIGIT ADD 2 DIGIT C TESTB'7' CNVDIG 50 C 50 DIGIT ADD 1 DIGIT C ENDSR *===================================================== C CNVZOX BEGSR * Convert zone portion of character to number C Z-ADD0 ZONE 20 C TESTBOFF CNVZON 50 C 50 ZONE ADD 8 ZONE C TESTBON CNVZON 50 C 50 ZONE ADD 4 ZONE C TESTB'2' CNVZON 50 C 50 ZONE ADD 2 ZONE C TESTB'3' CNVZON 50 C 50 ZONE ADD 1 ZONE C ENDSR *===================================================== C *INZSR BEGSR C BITOF'01234567'X00 1 C BITOF'01234567'X0F 1 C BITON'4567' X0F * Initialization - Get field definitions C READ QWHDRFFD 40 C *IN40 DOWEQOFF C WHFLDT IFEQ 'S' C USSIGN ANDEQ'*YES' C WHFLDT OREQ 'P' C USPACK ANDEQ'*YES' C ADD 1 S 50 C S OCUR FLDINF C MOVELWHFLDE FLDNAM C MOVELWHFLDT FLDTYP C Z-ADDWHFLDB FLDLEN C Z-ADDWHIBO FLDBEG C MOVELWHFTXT FLDDSC C END C READ QWHDRFFD 40 C END C WRITEHEADINGS C ENDSR *===================================================== ODATAIN E UDATA O REC 4096 ** 000 011 022 033 044 055 066 077 088 099 10A 11B 12C 13D 14E 15F
LATEST COMMENTS
MC Press Online