Sie sind auf Seite 1von 4

System iNetwork Head Nav Subscribe Log In Contact Us Advertise User login Username: * Password: * Request new password

Search Primary links Forums Archives Code Blogs Podcasts Webcasts e-Learning Guides Newsletters About Us Contact Us About the Network Tech Editor Profiles Editorial Calendar Writers Kit Advertise Join Network Categories RPG Programming Other Languages Application Development Database/SQL Availability Security Systems Management Networking IT Mgmt/Careers Site Links Solutions Store Events UK Centre Jobs System iPortal Home Content Find Decimal Data Errors Article ID: 56974Posted July 24th, 2008 in RPG Programming Database/SQL By:Scott Klement I often get questions about finding and fixing bad data in files. Predominantly, the bad data leads to the dreaded "decimal data error," and folks want to know how to write programs that can identify which fields of which records in a file have bad decimal data. This article presents a programming technique that helps you locate decimal data errors in a file. Many ways to code something like this exist, but my favorite technique for detec ting decimal data errors is by reading data directly into an RPG data structure. For example, consider the following code: FITMMAST F FITEMOUT D dsInfo D RRN IF IF E E ds 397 400i 0 K DISK K DISK BLOCK(*YES) INFDS(dsInfo) RENAME(ITMMASTF:ITEMOUTF)

D InRec D OutRec D errMsg /free

ds ds s

80a

likerec(ITMMASTF:*INPUT) likerec(ITEMOUTF:*INPUT) varying

setll *start ITMMAST; read ITMMASTF InRec; dow not %eof(ITMMAST); ... do something with the record ... read ITMMASTF InRec; enddo; The preceding code reads through the entire ITMMAST file. (ITMMASTF is the name of the record format of the ITMMAST file.) The interesting part is that it reads each record directly into a data structure named InRec. The code accomplishes t his by specifying InRec in the result field of the READ opcode. Reading an externally defined file directly ossible in V5R2. In that release, the READ, des can read directly into a data structure EREC, but only if the record format name is into a data structure first became p CHAIN, READE, READP, and READPE opco if the structure is defined with LIK used instead of the file name.

In V5R3, some of these restrictions were relaxed a bit. You can now use EXTNAME data structures as well as LIKEREC data structures, and you can use the file nam e instead of the record format name, provided that your file has only one record format. Anyway, the fact that the READ opcode reads directly into a data structure is us eful because the system copies the entire record, as a block of bytes, directly from the file into my data structure. This behavior is different from traditiona l file access; RPG's traditional access would read one field at a time. This new behavior is useful for finding decimal data errors, because the system doesn't even look at the value in the decimal fields--it simply copies them byte for byt e from the file to your program. Now that you have the records in your program, you can test them to see if there's any problem. For example: FITMMAST F FITEMOUT D dsInfo D RRN D InRec D OutRec D errMsg /free setll *start ITMMAST; read ITMMASTF InRec; dow not %eof(ITMMAST); monitor; OutRec = InRec; IF IF E E ds 397 ds ds s 400i 0 likerec(ITMMASTF:*INPUT) likerec(ITEMOUTF:*INPUT) varying K DISK K DISK BLOCK(*YES) INFDS(dsInfo) RENAME(ITMMASTF:ITEMOUTF)

80a

OutRec.Price = InRec.Price; OutRec.Weight = InRec.Weight; OutRec.Height = InRec.Height; OutRec.Length = InRec.Length; OutRec.Width = InRec.Width; OutRec.Depth = InRec.Depth; // (or use eval-corr in V5R4) write ITEMOUTF OutRec; on-error 907; errMsg = 'Decimal data error on record ' + %char(RRN); // show message to user endmon; read ITMMASTF InRec; enddo; *inlr = *on; /end-free This sample program reads each record from the ITMMAST file. The records that ha ve no errors are copied to the ITEMOUT file. The records that do have errors are not copied; instead, a message is prepared to tell the user which RRN of the fi le had bad data. (The sample code creates this message in the errMsg variable. I 've left it as an exercise for the reader to figure out how to display the messa ge to the user.) How does the program detect the error? It detects the error while copying the da ta from the ITMMAST file record to the ITEMOUT file record. The program starts b y copying the whole record by doing OutRec = InRec. Then, it copies each numeric field (individually) from InRec to OutRec. If one of those fields contains inva lid decimal data, the system produces an RPG status 907 error as the data is rea d from the InRec structure. When that happens, my program catches the error (by using the MONITOR statement to trap status 907) and then reports the problem to the user. If you prefer to know which field has bad data, you might code it a little diffe rently, like this: OutRec = InRec; monitor; OutRec.Price = InRec.Price; on-error 907; errMsg = 'Error in PRICE field on record ' + %char(RRN); // show message to user endmon; monitor; OutRec.Weight = InRec.Weight; on-error 907; errMsg = 'Error in WEIGHT field on record ' + %char(RRN); // show message to user endmon; . . . and so forth, for all the numeric fields . . . Good luck! Bookmark/Search this post with: Login to post comments Email this page Printer-friendly version Relate d Links

The Quest for Application Flexibility Read and Write LOBs from an RPG Pointer Field JDBC from RPG with Multiple Result Sets Tips for Programming and Development, Part 2 Tips for Programming and Development, Part 1 ProVIP Sponsors ProVIP Sponsors

Featured Links End-to-End Visibility in SOA Performance - Live Web Seminar Cross-Platform SOA Performance Management: Working Double? Sponsored Links Trevor Perry selects WebSmart PHP & Nexus Portal for KMR Systems - See Why! Barcode400 - Fully integrate & automate your labeling process. snap your back-end applications into any other application. FREE Paper: From WDSC to RDi - Making Software Change Easier with MKS. Footer Site Links Home Subscribe Now Advertise Contact Us Feedback Terms & Conditions Trademarks P rivacy Policy Copyright Penton Media

Das könnte Ihnen auch gefallen