Toby’s RPG Snippet to Scan Replace is mental but sexy

  • Home
  • /
  • Blog
  • /
  • Toby’s RPG Snippet to Scan Replace is mental but sexy

July 19, 2010

I was recently copied on an interoffice email from a fellow RPG chappie (he’s quite sharp actually despite his funny mockney accent).

Aforementioned Mockney-Coder was modifying a recent program, written by a legacy RPG3 programmer (these creatures are very rare to find in the wild and we have placed them on the endangered species list).

Toby's RPG Snippet to Scan Replace is mental but sexy 1Amazingly, there are still a handful of RPG Programmers out there who still write in RPG3, even though it was upgraded to RPG400 in 1993(?) so if they havent upgraded to RPG400 yet then the chances of getting up to RPGLE and then to RPG/FREE are slim to none.

However, Mockney-Coder is a smart chap and he mentioned a neat little alternative piece of RPG/FREE code that could be used to replace the large subroutines and array handling code chunks needed to perform the same thing in the old fashioned and clunky column based RPG varieties. After all, Variety is the spice of life…

all names have been removed to protect the innocent 😉

Don’t know if you are using /Free or not because I have been hiding a lot lately.

I transposed a Serial Number from a left adjusted alpha field to a zero padded right adjusted field with no Arrays or Data Structures and thought you might find the code use full/Interesting as you do this kind of thing a lot. So the D specs are the same, they are just usually more descriptive/Longer because the code can take longer values so…

RPG Code Snippetd Pos s 2 0 inz(*zero)
 d Len s 2 0 inz(*zero)
 d SernD2 s like(Sernds) inz('000000000000000’)

 Pos=%scan(' ':SernDS);
 If Pos<>0;

This is looking for the First Blank in the Screen Field (SernDS), in this case ‘5000012 ‘ so Pos=8, sub 1 from that to store the last position before the blank.

Len is the remaining positions (position where you want to start overlaying the zeros with ‘5000012’) in SernD2 (Work Field for Chains etc.) which is position 9.

And %Replace is just ‘change this bit of this thing to this instead’.

So, any serial numbers that are stored as ‘1234567859 ‘ will be transposed to 00000123456789 which is handy as this database stores them both ways.


I like this mockney code example – but it gives me a bit of a headache trying to figure it out:

Any simpler examples out there?


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"}

Start your
7-day free trial

Take This Course with ALL ACCESS

Unlock your Learning Potential with instant access to every course and all new courses as they are released.
 [ For Serious Software Developers only ]

IBM i Training For Technology Experts


Successfully Work Remote 

 $ 129.00  $59.00

By adding new skills in information technology, employers will be confident that you have the necessary skills and tools needed to successfully work remotely


Snug CBD

 20% Discount

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