iSeries EXTRA: Ending those Decimal Data Error Blues

The OS/400 V5R2 version of the RPG compiler features many enhancements related to file I/O operations. We've found a useful way to leverage the fact that V5R2 allows you to specify a data structure (DS) as the result field of an I/O operation such as READ or UPDATE.

Prior to V5R2, we could do this only for program-described files. (Remember those?) This new extension provides some interesting possibilities. For one thing, it can provide a performance benefit, especially for batch jobs that process multiple records with many fields. Normally with RPG programs an I/O operation such as a READ requires the compiler to move each field individually from the file buffer to its storage location. You may have noticed this behavior when stepping though a program in debug. If you press F10 (step) on, say, a READ operation, the debugger "leaps" off to the I-specs and subsequent step operations work their way painfully through field after field-this behavior occurs even if all of the files fields are described in an externally described DS. However, using this new support, when a DS is specified as the result field, all of the fields are filled with a single move operation. This is more efficient than a series of individual moves.

Another advantage of this support is that it provides more options for detecting and resolving invalid data items that may exist in our files. With a normal type of READ, if any data validity problems exist in the file (such as decimal data errors), the READ operation fails because each field is being "touched." When reading into a DS, the individual fields arent touched during the READ operation, hence no error.

As soon as the program tries to use the field containing the invalid data, you still get a decimal data error, so how is this useful? Suppose that we were to combine this new I/O support with the MONITOR operation that was added at V5R1 (see "RPG MONITOR is a Flexible Facility"). Now we have an effective method to detect and add program logic to report and potentially fix those errors.

Let's examine an example. Suppose MyFile contains three numeric fields that we need to move to display fields. If all of the numeric data were valid, the following code would work:

IBM Systems Magazine is a trademark of International Business Machines Corporation. The editorial content of IBM Systems Magazine is placed on this website by MSP TechMedia under license from International Business Machines Corporation.