× 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.


  • Subject: RE: BIF to trim leading 0's
  • From: boldt@xxxxxxxxxx
  • Date: Mon, 12 Mar 2001 10:12:51 -0500
  • Importance: Normal


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
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.