fhg
Volume 7, Number 19 -- May 16, 2007

Old Programs Can Learn to Behave Themselves

Published: May 16, 2007

by Ted Holt

As far as I know, nothing disastrous has ever come of a truncation error in one of my programs. Nevertheless, I'm embarrassed when someone points out that a total figure does not equal the sum of the column of numbers above it. RPG's EVAL opcode generates a hard error if high-order numeric truncation occurs. We can use the MONITOR opcode to trap EVAL's truncation errors. But what about all those programs that use antique op codes like ADD, SUB, MULT, and DIV?

You can easily make those op codes raise errors upon truncation. Let's see how it's done. Here's an extremely sophisticated program that generates a truncation error.

C                   move      *on           *inlr                 
C                   z-add     995           SomeNumber        3 0 
C                   add       10            SomeNumber            
C                   return

The final value of SomeNumber is five, of course. The program continues along without the slightest concern that 1000 of something has been obliterated.

The solution is to add the TRUNCNBR keyword with a value of *NO to the H specs.

H truncnbr(*no)                                                  
                                                                 
C                   move      *on           *inlr                
C                   z-add     995           SomeNumber        3 0
C                   monitor                                      
C                   add       10            SomeNumber           
C                   on-error                                     
C                   move      *hival        SomeNumber           
C                   endmon                                       
C                   return

Without the MONITOR, the ADD operation generates messages MCH1210 (Receiver value too small to hold result) and RNQ0103. (The target for a numeric operation is too small to hold the result C G D F.)

I wouldn't advise anyone to automatically add this keyword to all the old programs in their shop, because too many programs depend on truncation. A good example is the use of constants like 100.0001 to convert dates from one format to another. For those of you who don't know this trick, multiplying a six-digit number by 100.0001 and storing the result in a six-digit number converts YYMMDD to MMDDYY. Also, multiplying a six-digit number by 10000.01 converts MMDDYY to YYMMDD. Now that you know this trick, don't use it.



                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Sponsored By
HELP/SYSTEMS

SEQUEL can be used for
virtually ALL business intelligence functions
on the System i, including:

                                                    · Executive Dashboards
                                                    · Graphical Query & Reporting
                                                    · Drill-Down Data Analysis
                                                    · Multi-Platform Database Support
                                                    · E-Mail Report and File Distribution
                                                    · Secure Web Access

SEQUEL is the single solution for all
your business intelligence needs.

www.helpsystems.com


Senior Technical Editor: Ted Holt
Technical Editors: Howard Arner, Joe Hertvik, Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Brian Kelly, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

Bsafe:  Enterprise security for System i and Linux systems
WorksRight Software:  ZIP code, area codes, Canadian postal codes, CASS certification, and more
COMMON:  Join us at the Annual 2008 conference, March 30 - April 3, in Nashville, Tennessee


IT Jungle Store Top Book Picks

The System i Pocket RPG & RPG IV Guide: List Price, $69.95
The iSeries Pocket Database Guide: List Price, $59.00
The iSeries Pocket Developers' Guide: List Price, $59.00
The iSeries Pocket SQL Guide: List Price, $59.00
The iSeries Pocket Query Guide: List Price, $49.00
The iSeries Pocket WebFacing Primer: List Price, $39.00
Migrating to WebSphere Express for iSeries: List Price, $49.00
iSeries Express Web Implementer's Guide: List Price, $59.00
Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00
WebFacing Application Design and Development Guide: List Price, $55.00
Can the AS/400 Survive IBM?: List Price, $49.00
The All-Everything Machine: List Price, $29.95
Chip Wars: List Price, $29.95

 

The Four Hundred
Aldon Acquired by Marlin Equity Partners

Some Thoughts on i5 Spending Patterns

IBM Sees Green in Going Green in Data Centers

Children's Foundation Blossoms from Sirius Computer

The Linux Beacon
Red Hat to Push Desktop Linux with Intel Partnership

RHEL 5: How's It Going?

IBM Sees Green in Going Green in Data Centers

As I See It: Education--the Other Dysfunction

Four Hundred Stuff
Look, Ma, 5250 App Access from Outlook, Google

LANSA Upgrades Modernization Tool

RJS Unveils New Forms, PDF Solutions for System i

NGS Makes DB2/400 Data Accessible from MS Office

Big Iron
Unisys Ports OS 2200 Mainframe Operating System to Xeons

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
May 12, 2007: Volume 9, Number 19

May 5, 2007: Volume 9, Number 18

April 28, 2007: Volume 9, Number 17

April 21, 2007: Volume 9, Number 16

April 14, 2007: Volume 9, Number 15

April 7, 2007: Volume 9, Number 14

March 31, 2007: Volume 9, Number 13

The Windows Observer
Patch Tuesday Yields Seven Critical Patches for 19 Flaws

Microsoft Moves Forefront as Security Market Changes

Q&A with HP's Paul Miller: The X64 Server Biz

Microsoft Taps Packeteer for Branch Office Server

The Unix Guardian
IBM Lengthens and Broadens AIX Support on Power Iron

Sun Backs QuickTransit for Sparc to X64 Migration

IBM Sees Green in Going Green in Data Centers

As I See It: Education--the Other Dysfunction

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

THIS ISSUE SPONSORED BY:

Patrick Townsend & Associates
Help/Systems
Guild Companies



TABLE OF CONTENTS
Groovy: A Powerful Scripting Language for Java Developers on System i

Old Programs Can Learn to Behave Themselves

Another Way to Retrieve i5 System Storage Space

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
SBMJOB

How to calculate the last day of the month

iSeries Career training ideas

Authority to IFS

User profile for webserver instances





 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement