• Subject: RE: Testing for first non-blank character
  • From: "Kahn, David [JNJFR]" <DKahn1@xxxxxxxxxxxxx>
  • Date: Thu, 9 Sep 1999 15:32:24 +0200

Roger and Julian are right. This technique is roughly 10 times faster than
CHECK (if efficiency is a concern). However, there are some bugs in Roger's
pseudo-code. We're looking for the first NON-blank character so the test
should be <> blank. The shuffle should be move followed by movel, not movel
followed by move.

CHECK does not alter the field being tested, whereas the Julian/Roger method
destroys the source field. However, if the movel were to specify 'pad with
blanks' the source field will end up left aligned rather than simply
mangled, which may be an added bonus. In fact left aligning the source field
may enable Roger (Boucher) avoiding having to do the substring in the first
place, depending on why exactly he's doing it.

A corrected RPG/III rendering of Roger's pseudo-code is shown below. This
version both gives the original position of the 1st non-blank character and
left aligns the 15 byte source field. If the field is needed in it's
original condition it must be saved first. If the final value of IX is 16
then the source field was and is blank.

     C                     DO   15        X       30 
     C                     MOVELSRCSTR    TSTSTR  1  
     C           TSTSTR    IFNE *BLANK               
     C                     LEAVE                     
     C                     ENDIF                     
     C                     MOVE SRCSTR    TGTSTR 14  
     C                     MOVELTGTSTR    SRCSTR 15 P
     C                     ENDDO                     

If left aligning is all that's required JD Edwards thoughtfully supply you
with a canned subroutine to do this - C0040. This is more than 100 times
slower than the Julian/Roger technique, although to be fair it can do a lot
more than simply left justify.

Dave Kahn
Johnson & Johnson International (Ethicon) France
Phone : +33 1 55 00 3180
Email :  dkahn1@jnjfr.jnj.com (work)
           dkahn@cix.co.uk      (home)


-----Message d'origine-----
De: Roger Pence [mailto:rp@rogerpence.com]
Date: 09 September 1999 02:52
À: MIDRANGE-L@midrange.com
Objet: Re: Testing for first non-blank character


> Does anybody have a brilliant little piece of RPGIII code to test for the
> first non-blank character in a right-justified (sorry, JDE stuff)
character
> field so that I can substring from that position to the end of the field?
I
> really don't want to use a data structure and test each character if I
don't
> have to... I have my pride <g>.

Many years ago, Julian Monypenny showed me this clever technique. It uses
two moves to continually shift off each left most position of the source
string. The key to the technique is to have a work field 1 byte shorter than
the string you're parsing.  Julian benchmarked this against several other
methods and this one was wayyyy faster. Sorry for the pseudo code, but
you'll get the idea.

Const srcStrLen = 60
srcStr LEN( srcStrLen )
tgtStr  LEN( srcStrLen - 1 )
tstStr  LEN( 1 )

for x = 1 to srcStrLen
    * move leftmost char of source string to work value
    MoveL srcStr to tstStr
    * test it for blanks
    if tstStr = *BLANK
        do something
        * if you choose to break out of the loop here, x = position of first
blank character in source string
    endif
    * next two lines shift off current leading character of source string
    movel srcStr tgtStr
    move tgtStr  srcStr
next x
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-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.