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
Toby's RPG Snippet to Scan Replace is mental but sexy - Nick Litten is IBM-i, AS400 iSeries RPG Programmer and Nerd

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

IBM i

Jul 19

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

Amazingly, 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=0;
 Pos=%scan(' ':SernDS);
 If Pos<>0;
    Pos=(Pos-1);
    Len=(15-(Pos-1));
    SernD2=%replace(%subst(SernDS:1:Pos):SernD2:Len);
 Endif;

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.

Cheers

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?

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.