× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Thanks, Joel.

For converting character strings to numbers, IBM Toronto's Barbara Morris wrote
an elegant and very fast RPG IV subprocedure, GETNUM, that converts a character
string to a 30/9 packed number.  It handles digit separators, signs, and the
decimal point.

It is better than atoi because it handles non-integers; it is better than atof
because it has none of the precision problems inherent in floating point
numbers.

I found a copy at

http://www.as400pro.com/TipsRPG2.htm#5

I used it as the basis of the c2n2 subprocedure in my RPG IV CGI Tool Kit
library, CGIDEV2.

Mel Rothman
IBM eServer Custom Technology Center (eCTC), Rochester, Minnesota
http://www-1.ibm.com/servers/eserver/iseries/service/ctc/
http://www.easy400.ibm.it/en


"Joel R. Cochran" wrote:
>
> Very Cool Mel...
>
> If it is always numbers, below is a 'de-formatting' routine I wrote to strip
> all text characters out of a string and return the number... I use it so
> that the user can enter phone numbers, Social Security Numbers, zipcodes,
> etc. in any format and all I store in the DB is the number itself.  #CtoN is
> a Character to Numeric, so you could replace it with 'atoi'.  It may not be
> the cleanest but it is functional.
>
> Joel
>
> >-----Original Message-----
> >From: Mel Rothman [mailto:mel@rothmanweb.com]
> >Sent: Thursday, December 20, 2001 9:32 AM
> >To: rpg400-l@midrange.com
> >Subject: Re: Deleting blanks in a field
> >
> >An RPG IV approach:
> >
> >/free
> >  fieldb = %triml(fielda);
> >  i = %scan(' ':%trimr(fieldb));
> >  dow i > 0;
> >   fieldb = %replace('':fieldb:i:1);
> >   i = %scan(' ':%trimr(fieldb):i);
> >  enddo;
> >  *inlr = *on;
> >
> >Mel Rothman
>
>      H NOMAIN
>       *--------------------------------------------------------------------
>       * (#StripNum) Takes a character string and returns only embedded #s
>       *             only returns Integers
>       *
>       * To Use: #StripNum(Character field to convert)
>       *--------------------------------------------------------------------
>       /COPY servicelib/qrpglesrc,pr_strip
>       /COPY servicelib/qrpglesrc,pr_cton
>       *--------------------------------------------------------------------
>      P #StripNum       B                   EXPORT
>
>       *--------------------------------------------------------------------
>      d #StripNum       PI            30P 0
>      d  Char                         30    VALUE
>
>      d in              S              1    dim(30)
>      d out             S                   like(in) dim(%elem(in))
>
>      d  WrkChar        S             30
>      d  WrkNum         S             30P 0
>      d  i              S              2  0 inz(0)
>      d  j              S              2  0
>
>      d  numbers        C                   CONST('0123456789')
>       *--------------------------------------------------------------------
>      c                   eval      Char = %triml(Char)
>
>      c                   movea     Char          in
>      c                   eval      j = 1
>
>      c                   for       i=1 to 30
>      c                   testn                   in(i)                75
>      c                   if        *in75 = *on
>      c                   eval      out(j) = in(i)
>      c                   eval      j = j + 1
>      c                   endif
>      c                   endfor
>
>      c                   movea     out           wrkChar
>      c                   eval      wrkNum = #CtoN(wrkChar)
>
>      c                   Return    WrkNum
>       *--------------------------------------------------------------------
>      P #StripNum       E
> _______________________________________________


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.