squish out blanks in a string using RPG 

 October 29, 2010

By  NickLitten

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’


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

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

Get In Touch

I’m always looking for awesome input, feedback and critique!


Snug CBD

 20% Discount

I have partnered with SNUG CBD givING you Organic CBD
20% discount code "NL20"