squish out blanks in a string using RPG

  • Home
  • /
  • Blog
  • /
  • squish out blanks in a string using RPG

October 29, 2010

squish out blanks in a string using RPG

By NickLitten

October 29, 2010

cpysrc2ifs, RPG, snippet, squish

So, as part of an IBM-i project to “rebuild a bunch of source libraries on the development machine” I always think about backups before touching things. Not because I have history of deleting things (while in rampant house keeping mode) and then regretting it later… we would never do that right? cough

So, since I was playing with hundreds of source files, tens of thousands of source members and squillions of lines of code I thought “Wouldn’t it be nice if I could copy all this source code to the IFS for easy referencing with NOTEPAD++?

The answer was YES… in true Projex style this turned into a command and CPYSRC2IFS was born.


Type choices, press Enter.

Source File to be copied . . . . File Name
Library . . . . . . . . . . . *LIBL Name, *LIBL, *CURLIB
Source Member Name . . . . . . . *ALL Name, generic*, *ALL
Type of document to create . . . *TXT Required document format
Path Name ie:/HOME/usrprf . . . *HOME

F3=Exit F4=Prompt F5=Refresh F12=Cancel F13=How to use this display
F24=More keys

I also added several file formats for the source code once it lands in the IFS: *TXT, *PDF, *XML and *HTML

The nature of this command is to enter something like this:


Press enter and let it convert your  IBM I source code in to the type of your choice and copy it to the IFS location  you specified. It’s a great clean backup technique and also an easy way to grab source code that you might want to email to other people.

Cpysrc2ifs command copy ibm i source to the integrated file system ifs


While writing the RPG code to cleanup the source member comments before copying to the windows format file structure in the IBMi integrated File System (IFS), I decided to take each source members comments and (a) remove special characters and (b) compress down to single blank spaces between words and then (c) switch them to a ‘_’ character instead.

After lots of trial and error – I came up with a neat little DO loop to compress down any multiple blank spaces in the description text, contained in variable(ParmString):

// ------------------------------------------------------------- *
// #SQUISH: Truncate out any Cleans
// ------------------------------------------------------------- *
Begsr #Squish;
  Dow %Scan(' ': %TRIMR(ParmString)) > *Zeros;
    ParmString = %Replace( '' : ParmString : %Scan(' ':%TRIMR(ParmString)) : 1);

Works like a treat….

/me puts fingers in front of face and ‘squishes your head’

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips