04
Mon, Nov
5 New Articles

Stamp Out Decimal Data Errors

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: