|
Barbara's code was interesting. My #cton() will handle decimals and negative signs but not dollar signs or any of the oddballs like ',' for decimal places and such. This is a great example of flexible, truly reusable code. Thanks Mel, Joel -----Original Message----- From: Mel Rothman [mailto:mel@rothmanweb.com] Sent: Thursday, December 20, 2001 10:40 AM To: rpg400-l@midrange.com Subject: Re: Deleting blanks in a field 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 > _______________________________________________ _______________________________________________ This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@midrange.com To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/cgi-bin/listinfo/rpg400-l or email: RPG400-L-request@midrange.com Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
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.