• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Old Programs Can Learn to Behave Themselves

    May 16, 2007 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

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    RPG & DB2 Summit

    Summit Hands-On Live! Workshop Series
    April 27 – May 20, 2021

    In-Person, Interactive, In-Depth — Online!

    Master critical IBM i development skills at record speed with the Summit’s full-day Hands-On Live! workshops.

    Teaching live online via video meeting, instructors Paul Tuohy, Jon Paris, Susan Gantner, and Mike Pavlak take you deep into the best ways to use your favorite technologies, cementing your knowledge with guided, hands-on labs and personal attention.

    Choose from 7 different workshops to hone your skills.

    • SQL Procedures, Functions & Triggers
    • Intermediate SQL for RPG Developers
    • RPG Procedures & Service Programs
    • Building Modern RPG Applications (2-day workshop!)
    • RDi Quick Start
    • RDi Beyond the Basics
    • Python for RPGers

    Check out the workshop abstracts and prepare to take your productivity to new heights!

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    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

    Lawson Launches QuickStep for Distribution IBM Tweaks i5 515 and 525 User-Based Prices

    Leave a Reply Cancel reply

Volume 7, Number 19 -- May 16, 2007
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

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Why Open Source Is Critical for Digital Transformation
  • mrc Refreshes IBM i Low-Code Dev Tool
  • Unit Testing Automation Hits Shift Left Instead of Ctrl-Alt-Delete Cash
  • Four Hundred Monitor, March 3
  • IBM i PTF Guide, Volume 23, Number 9
  • Doing The Texas Two Step From Power9 To Power10
  • PHP’s Legacy Problem
  • Guru: For IBM i Newcomers, An Access Client Solutions Primer
  • IBM i 7.1 Extended Out To 2024 And Up To The IBM Cloud
  • Some Practical Advice On That HMC-Power9 Impedance Mismatch

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2021 IT Jungle

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.