• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Handling Oversized Numbers Gracefully

    October 13, 2004 Hey, Ted

    These MCH1210 errors are driving me nuts. We run packaged software and a lot of the database fields are bigger than we need them to be. I often use smaller fields on displays and reports in order to save room. Then one day, for some reason, a field has a bigger value than I expected and an EVAL command blows up with MCH1210 (the target for a numeric operation is too small to hold the result). Is there any way in all this new-fangled RPG stuff to tell the system to print hash marks and keep on trucking?

    –Dave

    RPG has no such logic, but you can handle this situation yourself with little trouble. Since you want to display or print hash marks, you must define output fields as character data rather than as numeric data. You’ll have to use the %EDITC and %EDITW functions within your programs to edit the fields (that is, apply decimal points, currency symbols, minus signs, commas, and the like). And you need a routine that can decide whether an edited number can fit into the space you’ve allowed for it.

    The following example contains such a routine, which I call FmtNum (Format Numeric). It requires two parameters: an edited numeric value and the number of bytes into which the edited numeric value is to fit.

    H dftactgrp(*no) actgrp(*new)
    
    D FmtNum          pr           256    varying
    D  EditedNum                   256    varying value
    D  Size                         10u 0         value
    
    D Column01        s              6a
    D Column02        s              4a
    D OrderQty        s              7p 0
    D Balance         s             11p 2
    
     /free
         evalr Column01 = FmtNum(%editc(Balance: 'J'):
                                 %size(Column01));
         evalr Column02 = FmtNum(%editc(OrderQty: '4'):
                                 %size(Column02));
         *inlr = *on;
     /end-free
     * ===========================================================
    P FmtNum          b
    D FmtNum          pi           256    varying
    D  EditedNum                   256    varying value
    D  Size                         10u 0         value
    D
     * local variables
    D TrimmedNum      s            256    varying
    D FillChar        s            256    inz(*all'#')
    
     /free
        if Size = *zero;
            return *blanks;
        endif;
    
        if Size > %size(FillChar);
           return *blanks;
        endif;
    
        TrimmedNum = %triml(EditedNum);
        if %len(TrimmedNum) <= Size;
           return TrimmedNum;
        endif;
    
        return %subst(FillChar:1:Size);
     /end-free
    
    P FmtNum          e
    


    In this example, OrderQty and Balance represent database fields and/or calculated variables. Column01 and Column02 represent fields on a display or report. Since there are two values to be copied into output fields, the main routine calls FmtNum twice, each time passing the edited numeric value and the size of the variable into which the edited value is to be placed. If the receiving variable is too small to hold the significant portion of the edited numeric value (that is, the portion of the edited numeric value without leading blanks), FmtNum returns enough hash marks to fill up the receiving variable. Notice that I used the EVALR op code in the main calculations in order to right-adjust the numeric values.

    You could use the MONITOR, ON-ERROR, and ENDMON op codes to handle arithmetic overflow, but you would have to place such a structure around every EVAL. I much prefer the FmtNum subprocedure.

    –Ted

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    ARCAD Software

    [Webinar] Synchronous IBM i and non-IBM i Deployments
    April 13 at 12 p.m. ET

    Do you need to automate and synchronize deployments across ALL your environments and applications?

    Many backend IBM i applications have off-platform components, such as an API layer, or Web front-end. To ensure your application stays reliable, artifacts must be deployed securely and in-sync.

    In our Webinar, learn how to orchestrate all your deployments, multi-platform and multi-cloud, using DROPS by ARCAD Software:

    – One single console to deploy across multiple endpoints – IBM i, Windows, Linux, IBM z, on prem or cloud

    – Real-time visibility of application status, from anywhere

    – Deployment plans and one-click-deploy

    – Rollback on error

    Simplify and secure your application delivery.

    Register Now

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    BOSaNOVA and Wyse Look to the High End of Thin Clients IBM Completes i5 Squadrons with 64-Way Model 595

    Leave a Reply Cancel reply

Content archive

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

Recent Posts

  • LANSA Developing Business Intelligence Tool
  • Blazing The Trail For VTL In The Cloud
  • Data De-Dupe Gives VTL Customers More Options
  • Four Hundred Monitor, March 29
  • The Big Spending On IT Security Is Only Going To Get Bigger
  • IBM Tweaks Some Power Systems Prices Down, Others Up
  • Disaster Recovery: From OS/400 V5R3 To IBM i 7.4 In 36 Hours
  • The Disconnect In Modernization Planning And Execution
  • Superior Support: One Of The Reasons You Pay The Power Systems Premium
  • IBM i PTF Guide, Volume 25, Number 13

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