• 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
    VISUAL LANSA 16 WEBINAR

    Trying to balance stability and agility in your IBM i environment?

    Join this webinar and explore Visual LANSA 16 – our enhanced professional low-code platform designed to help organizations running on IBM i evolve seamlessly for what’s next.

    🎙️VISUAL LANSA 16 WEBINAR

    Break Monolithic IBM i Applications and Unlock New Value

    Explore modernization without rewriting. Decouple monolithic applications and extend their value through integration with modern services, web frameworks, and cloud technologies.

    🗓️ July 10, 2025

    ⏰ 9 AM – 10 AM CDT (4 PM to 5 PM CEST)

    See the webinar schedule in your time zone

    Register to join the webinar now

    What to Expect

    • Get to know Visual LANSA 16, its core features, latest enhancements, and use cases
    • Understand how you can transition to a MACH-aligned architecture to enable faster innovation
    • Discover native REST APIs, WebView2 support, cloud-ready Azure licensing, and more to help transform and scale your IBM i applications

    Read more about V16 here.

    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

  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26
  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25

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 © 2025 IT Jungle