Midrange News for the IBM i Community


Posted by: Bob Cozzi
Rogue Programmer
Cozzi Productions, Inc.
Chicagoland
Test for numeric overflow
has no ratings.
Published: 01 Nov 2012
Revised: 23 Jan 2013 - 2493 days ago
Last viewed on: 20 Nov 2019 (3840 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Test for numeric overflow Published by: Bob Cozzi on 01 Nov 2012 view comments(3)

Wow! I can't believe the number of numeric overflow operations found in legacy code that is converted to /Free syntax.

This is when you have a target variable that is (for example) defined as 7p2 and the code moves a value to that field that is larger than 5-digits, such as: 99999.00 + 1.00

So much legacy code.... So I'm using the ChkDecOvr()  (check for decimal overflow) subprocedure to first validate if it will fit and then if it won't take an alternate course of action; rather than just blow up. Or I could wrap the code in MONITOR/on-error groups.

 

/free
    if chkDecOvr( sales * qty : %len(ordTot) : %decPos(ordTot));
       // Value too big to fit in target variable!
    else;
       ordTot = sales * qty; // We're good.
    endif;
/end-free

 

Anyway, we've added ChkDecOvr() to the COZTOOLS runtime.

 

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS