Midrange News for the IBM i Community


Posted by: John Dowling
Milford, Ma
Data conversion
has no ratings.
Published: 01 Aug 2012
Revised: 23 Jan 2013 - 4109 days ago
Last viewed on: 23 Apr 2024 (4372 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.

Data conversion Published by: John Dowling on 01 Aug 2012 view comments(4)

I have a file with numeric data defined as alpha.  I am converting it to numeric, I am using arrays to process the data. Here is my problem.

  I get the error "the target for a numeric operation is too smal to hold the result"

 

the code in question is  Numb(cnt)  =  %dec(Alpha(Cnt):9:2)

 

Cnt  = 1, the array Numb is 9.2 dim(24)  the array Alpha is 9  dim(24)

Alpha(cnt) = '010606490'  it should convert to 0106064.90 (decimal point should be implied).

 

any thoughts.  I converted 499 records before it read this one

 

thanks

 

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

COMMENTS

(Sign in to Post a Comment)
Posted by: neilrh
Premium member *
Jackson, MI
Comment on: Data conversion
Posted: 11 years 8 months 22 days 10 hours 25 minutes ago

The decimal point is not implied, if it's not there then the assumption is that the data is an integer representation.  You either need to scan/check the input field for the decimal point and insert it yourself.  OR monitor with on-error trap to catch the garbage and then do something to audit that you could not handle that piece of data.

Posted by: BrianR
Premium member *
Green Bay, WI
Comment on: Data conversion
Posted: 11 years 8 months 22 days 9 hours 51 minutes ago

You don't need arrays to handle the conversion.  If the decimal point is never present in the source field (always implied), then this should also work (numberfield is defined as dec(9,2)):

Monitor;

numberfield = %dec(alphafield:9:0) / 100;

Endmon;

Posted by: neilrh
Premium member *
Jackson, MI
Comment on: Data conversion
Posted: 11 years 8 months 21 days 19 hours 10 minutes ago

The only reason I can see for needing arrays is that there are 24 values per input record that need to be converted in this way.

Posted by: BrianR
Premium member *
Green Bay, WI
Comment on: Data conversion
Posted: 11 years 8 months 21 days 15 hours 22 minutes ago
Edited: Thu, 02 Aug, 2012 at 10:47:38 (4283 days ago)

Oops, I didn't read the post closely enough.  For some reason, I thought the arrays were used to break up a single value into individual digits, so never mind about the array comment.