Warning: Declaration of TCB_Menu_Walker::walk($elements, $max_depth) should be compatible with Walker::walk($elements, $max_depth, ...$args) in /home/nicklit/www/www/wp-content/plugins/thrive-visual-editor/inc/classes/class-tcb-menu-walker.php on line 620

Warning: session_start(): Cannot start session when headers already sent in /home/nicklit/www/www/wp-content/plugins/userpro/includes/class-userpro.php on line 222
squish out blanks in a string using RPG - Nick Litten is IBM-i, AS400 iSeries RPG Programmer and Nerd

squish out blanks in a string using RPG

IBM i

Oct 29

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.

Copy *SRC to IFS (CPYSRC2IFS)

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

Bottom
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:

CPYSRC2IFS FILE(LITTENN/QRPGLESRC)
MBR(*ALL)
IFSDIR('/home/my-ifs-folder')
TIMESTAMP(*YES)

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);
  EndDo;
Endsr; 

Works like a treat….

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

Follow

About the Author

IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Alpha Nerd 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 in the words of the most interesting man in the world: Stay thirsty my friend.