[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading numeric fields from XML files



From your description of the problem I see you have only digits. If that is the case, the easiest chek is to "%CHECK" your field against '0123456789', if spaces are allowed you should "%TRIM" before.

%DEC will provide you a complete check (like 2 decimal points) using MONITOR

You should validate, even if you know the data was generated by a program and it must be clean.
______________________________________________________________________________________
gh1@xxxxxxxxxxxxxxxxxxxx wrote:

Thank you, I'll keep that in mind. Do you know of performance differences in either, or do you think it would be best to always use the atoll() function? Also, since we are on v5r2 and could use the %dec() bif, is there a benefit to using one over the other?

I did notice a couple of caveats to the atoi() function that I didn't have time to add yesterday.
1) It doesn't 'error' out if you pass it invalid numeric data (could be good or bad)
2) It does partial translation if there is an embedded character in your string (example; '5A55' becomes 55)

Even though neither Scott nor I included it in our code samples you should definitely do some sort of test on the string to be sure there is valid data in it.

Glenn Hopwood
Sr Programmer/Analyst
Electric Mobility
856-468-1000 x2545
Inactive hide details for Scott Klement <sk@xxxxxxxxxxxxxxxx>Scott Klement <sk@xxxxxxxxxxxxxxxx>

Sender: Scott Klement <sk@xxxxxxxxxxxxxxxx>

Hi Glenn,

> * Prototype of a c-function used to convert alpha to integer
> D atoi            pr            10i 0 extproc('atoi')
> D   str                           *   value options(*string)


GIF image