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



Could be that duplicate blanks are valid. Also, could be that any
character you translate to could be valid, so translating and then
looking for the character you translated to might not be viable.

Here's a quick and dirty look at a procedure that removes a character
from a field. A robust solution would be to place the procedure in a
service program with string handling procedures and have it accept
varying length input.

The actual "replace" portion occurs in the DoU loop in the procedure.
The loop continues until the search argument is not found in the input
at which time the On-Error section of the Monitor block gains control
and shuts the loop dosn.

Gary Guthrie


D RmvChar         Pr            30                                      
D                               30    Value                             
D                                1    Value                             
                                                                        
D MyFld           S             30    Inz('RABBIT PACK, 6PC. WINE
TOOLKIT')
                                                                        
 /Free                                                                  
                                                                        
      MyFld = RmvChar( MyFld : ',' ) ;                                  
      MyFld = RmvChar( MyFld : '.' ) ;                                  
      Dsply MyFld ;                                                     
                                                                        
      *InLR = *On ;                                                     
                                                                        
 /End-Free                                                              
                                                                        
P RmvChar         B                                                   
D RmvChar         PI            30                                    
D  Input                        30    Value                           
D  Char                          1    Value                           
                                                                      
D NotFound        S               N   Inz( *Off )                     
                                                                      
 /Free                                                                
                                                                      
      DoU NotFound ;                                                  
        Monitor ;                                                     
          Input = %Replace( '' : Input : %Scan( Char : Input ) : 1 ) ;
        On-Error ;                                                    
          NotFound = *On ;                                            
        EndMon ;                                                      
      EndDo ;                                                         
                                                                      
      Return Input ;   
                       
 /End-Free             
                       
P RmvChar         E    



Bob Cozzi wrote:
> 
> Tracy,
> 
> If you have the RPG ToolKit for OS/400 you can do it in two lines of
> code.
> If you don't you can get the FindReplace procedure, out of my article on
> this topic at
> http://www.mcpressonline.com/mc?1@46.DRG8acAs5B1.104752@.6ae52ffe
> 
> If you don't have the toolkit or the FindReplace procedure, you can
> still do what you want in just 4 lines of code:
> 
> Here's some example D specs for the data...
> 
>      D input           S             30A   Inz('RABBIT PACK, 6PC. WINE
> TOOLKIT')
>      D nPos            S             10I 0
> 
> First get rid of the garbage and replace them with blanks.
> 
>      C     ',.':'  '     xlate     input         input
> 
> Now get rid of the duplicate blanks..
>      C                   eval      input = FindReplace('  ':' ':Input)
> 
> In otherwords:
> 
>      C     ',.':'  '     xlate     input         input
>      C                   eval      input = FindReplace('  ':' ':Input)
> 
> If you need to do it with raw RPG IV, its almost as easy.
> Just replace the FindReplace line with the following:
> 
>      C                   eval      nPos = %scan('  ':Input:nPos)
>      C                   dow       nPos > 0
>      C                   eval      input = %Replace(' ':Input:nPos:2)
>      C                   eval      nPos = %scan('  ':Input:nPos)
>      C                   enddo


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.