enskill.com iSeries Training Onsite classes
DVD training
Books
Online e-Learning
Home
Resources
Contact
(c)2002-2008

This page is powered by Blogger. Isn't yours? Bryan's RPG IV Journal


Numeric target too small when using %DEC


Q. I guess I've misinterpreted how %DEC is supposed to work. In the following example, the value in Char4 is 0250, so I was anticipating the same result as a Move operation -- with my numeric result as 4 long, 3 decimal positions. But I get the error "The target for a numeric operation is too small to hold the result."
Num43 = %Dec(Char4:4:3);
Do you have a simple solution?

A. The %DEC function converts a character value to a packed decimal value, but the decimal does not align itself the same way that the Move operation did. The decimal point in the character field is optional, but if it's not there, %DEC will assume you are converting to a whole numeric value, without decimals. In your example, %DEC is trying to convert 0250, not 0.250; ergo, the "too small to hold result" error.

If you want to align the decimals with the attributes of the result, the generic formula is:
NumResult = %Dec(CharSource:%Size(CharSource):0)
/(10**%Decpos(NumResult));
Or, in your example,
Num43 = %Dec(Char4:4:0)/1000;
The RPG IV Reference isn't very clear on this, so your confusion is understandable.


Log of Journal Entries

Use this scrollable blog map to view other journal entries:
Journal Home
It is your responsibility to ensure procedures, techniques, and code used from this website are accurate and appropriate for your installation. No warranty or support is implied or expressed.
E-mail to Bryan Meyers
Privacy and Email Policy
 
AS/400®, eServer, i5/OS, IBM i, Integrated Language Environment®, iSeries, OS/400®, RPG/400®, System i5, VisualAge®, and WebSphere® are trademarks of IBM Corporation. Note: IBM® System i is the latest member of the family of eServer iSeries. This site might refer to System i as System i5, iSeries, or AS/400.
 

If you are having trouble navigating the menu at the top of this page, you may use the following scrollable site map instead:
 

Self-paced DVD Training
DVD: RPG IV for RPG Programmers
DVD: RPG IV Modules, Procedures, and Service Programs
 
In association with Amazon.com
Programming in RPG IV
RPG IV Jump Start
Power Tips for RPG IV
Control Language Programming for the AS/400
VisualAge for RPG by Example
 
International visitors: click hereInternational visitors:
Click here!