|
The point was that since we have to compile to V3R2 right now, this works. The new BIFS aren't available. So, if you were going to rewrite it, just use the new BIFs. :) Cool thing about ILE, when we do make our customers go to V3R7, we can leave it alone and it will still work. Brad > -----Original Message----- > From: boldt@ca.ibm.com [mailto:boldt@ca.ibm.com] > Sent: Monday, March 12, 2001 9:13 AM > To: rpg400-l@midrange.com > Subject: RE: BIF to trim leading 0's > > > > Brad wrote: > >Here goes. I hope it comes through ok. This is old source > written for > V3R3 > >and could probably updated... > > > >I usually call it like this: > > > >#ZChar(field:%size(field)) > > > > > *//////////////////////////////////////////////////////////////* > > * (#ZChar) Zero Supress A Character Field > * > > * > * > > * This procedure will replace all leading zeros with > blanks. * > > > *//////////////////////////////////////////////////////////////* > > P #ZChar B EXPORT > > > *--------------------------------------------------------------* > > D #ZChar PI 256 > > D text 256 VALUE > > D size 3 0 VALUE > >... > > Brad: You're absolutely right, that code could certainly be updated > to take advantage of features newer than V3R2. First, for simple > zero suppression of numeric values, %CHAR would probably be a better > choice. But lets write a more robust procedure that allows you to > strip ANY arbitrary characters from the left end of a string, not > just zeros: > > =========================================================== > P Strip b > D Strip pi 256a varying > D string 256a const varying > D char 256a const varying options(*nopass) > D i s 10i 0 > D ch s 256a varying inz('0') > /free > // default to '0' if second parm not specified > if %parms >= 2; > ch = char; > endif; > > // locate first char not equal to strip char > i = %check(ch:string); > if i = 0; > return ''; > endif; > return %subst(string:i); > /end-free > P Strip e > =========================================================== > > By default, this strips leading zeros. But if you specify an > optional second parameter to the procedure, you can strip off any > other characters you want. > > Although this is written using the new V5R1 syntax, (and compiled > and tested on a V5R1 machine) this should be easy to rewite to run > on a V4R4 system. > > Examples of use: > Strip('0000123') ===> '123' > Strip('****456':'*') ===> '456' > Strip('$***456':'*$') ===> '456' > > Cheers! Hans > > Hans Boldt, ILE RPG Development, IBM Toronto Lab, boldt@ca.ibm.com > > +--- > | This is the RPG/400 Mailing List! > | To submit a new message, send your mail to RPG400-L@midrange.com. > | To subscribe to this list send email to RPG400-L-SUB@midrange.com. > | To unsubscribe from this list send email to > RPG400-L-UNSUB@midrange.com. > | Questions should be directed to the list owner/operator: > david@midrange.com > +--- > +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
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.