Appendix B: Decimal Data Errors


Decimal data is at the heart of most business applications. Floating point and binary numbers are not as incorporated into business applications as decimal data. With the possible exception of the banking industry, floating point and binary fields are not widely used to calculate amounts, quantities, dollars, etc. in the vast majority of business applications. This appendix describes decimal data errors and shows how the system handles decimal data errors when the FIXNBR(*ZONED) and the FIXNBR (*INPUTPACKED) option is specified when an RPG source file member is compiled.

DECIMAL DATA OVERVIEW

There are two forms of decimal data:

  • Zoned decimal data — Occupying 1 byte for every digit declared.

  • Packed decimal data — Occupying approximately 1 byte for every two digits declared.

The AS/400 is strict when it comes to valid decimal data. The predecessor of the AS/400, the System/38, had no mechanism to handle invalid decimal data. RPG programs written for System/38 had to completely control the handling of invalid decimal data messages or they stopped running.

Because much of the data contained on the AS/400 has been "migrated" from other systems such as the System/36, the capability to easily handle invalid decimal data has become a requirement. The capability to handle decimal data errors is easier with RPG IV than with previous versions of RPG.

Decimal data errors occur during program runtime when a packed or zoned decimal field contains data that is invalid. An example of invalid data can be a zoned decimal field containing blanks or the letters 'ABCD'. This is clearly not valid numeric data and causes a decimal data error to be generated.

Fix Decimal Data Errors

The AS/400 RPG IV compiler provides an option to ignore decimal data errors. The CRTBNDRPG and CRTRPGMOD commands support the FIXNBR parameter as follows:

       FIXNBR(*NONE | *ZONED | *INPUTPACKED) 

The default option, FIXNBR(*NONE), causes decimal data errors to generate an exception/error. In this situation, the default RPG exception/error handling routine is called when an error occurs. If the *PSSR subroutine is specified in the RPG program, that subroutine is called when the exception/error occurs. The default of FIXNBR(*NONE) is appropriate when processing AS/400 database files containing valid numeric data.

The FIXNBR(*ZONED) option causes decimal data errors within zoned decimal numeric fields to be corrected. This is performed by the underlying AS/400 system licensed internal code (SLIC). When an RPG program is run, the AS/400 system prefers to use packed decimal fields. This means that binary fields and zoned fields, declared within an RPG IV program, are internally mapped to packed decimal fields. Except when decimal data errors are detected, this mapping is transparent to the RPG program.

Using FIXNBR(*ZONED) causes the SLIC to test the zoned decimal fields during this translation. If the zoned decimal field contains all blanks, for example, the blanks are converted to zeros. This special case is the most common type of decimal data error. The process of fixing zoned decimal fields containing blanks is known as blank transparency.

In another situation, when a zoned decimal field contains non-numeric data, the SLIC ignores the top half of each byte (the zone), except for the right-most byte. The right-most byte contains the sign of the number. If the sign is invalid, it is set to positive.

The bottom half of each byte (the digit) is tested for a value of 0 through 9. If the digit portion of the byte is not 0 through 9, the byte is set to zero (i.e., X'F0'). Note that the original zoned decimal field, however, is not converted. Only the targeted (and often temporary) packed decimal field receives the translated value.

Typically, FIXNBR(*ZONED) is used in programs with zoned decimal input fields or data structures that contain numeric subfields.

Because data structures, by default, are initialized to blanks, decimal data errors can occur. To correct the decimal data error that occurs frequently in data structures, the INZ keyword can be specified. This initializes each data structure subfield to the default initial value based on the field's data-type. The FIXNBR(*ZONED) keyword can virtually eliminate the most common form of decimal data errors.

The FIXNBR(*INPUTPACKED) option causes decimal data errors within packed decimal input fields, read from the database, to be corrected. This is performed by the underlying AS/400 system licensed internal code (SLIC). When an RPG program is run and a record is read, the system checks packed input fields for invalid packed decimal data. If there is a decimal data error, the system sets the field's value to zero.




The Modern RPG IV Language
The Modern RPG IV Language
ISBN: 1583470646
EAN: 2147483647
Year: 2003
Pages: 156
Authors: Robert Cozzi

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net