You're currently on IBMSystemsMags Archive. Click Here to view our new website


Dumping Subroutines: Breaking Up Is Hard To Do, Or Is It?

Dear Subroutine,

I think it’s time we split up. It’s not you; it’s me. It’s just that we’re not compatible any longer. We’ve grown apart. But we had a nice run, didn’t we? Of course we can still be friends. I’ll call you.

First of all, if you’re reading this and you code in RPGLE, you fall into one of two categories. You either use subprocedures exclusively, or you use subroutines and don’t see much use for a procedure. If you’re the latter, I know how you feel. I used to use subroutines extensively, but thanks to local subprocedures, subroutines are a thing of the past.

Before RPG & DB2 Summit in March 2012, I experimented in my code with subprocedures but mainly stuck with subroutines. Why? Because I wasn’t too familiar with them. I didn’t realize all of the benefits to be gained from a subprocedure. I tried using return values but couldn’t get them to work, so I believed it wasn’t possible in RPGLE. When I saw that it could be done at the conference, I resolved to learn how to do it.

The benefits of using local subprocedures include:

  • The ability to pass values in the form of variables, constants or literals
  • The ability to pass by reference or by value
  • Local variables and structures that only exist in the scope of a local procedure
  • Return values that allow you to assign a variable to a subprocedure or use it in a conditional block

Using these four tools will revolutionize the way you write code even if you’re still coding fixed-format RPG.

Brian Lannoye is a programmer at Masters Gallery Foods Inc., in Plymouth, Wis. He’s been working there as a programmer on the IBM i platform since June 2010. Brian regularly attends WMCPA meetings and is currently working toward a bachelor’s degree at Lakeland College Online.



2019 Solutions Edition

A Comprehensive Online Buyer's Guide to Solutions, Services and Education.

New and Improved XML-INTO

Namespace support makes the opcode a viable option

Authenticating on the Web

The finer points of OpenRPGUI, Part 1

The Microphone is Open

Add your voice: Should IBM i include open-source RPG tools?

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store
IBMi News Sign Up Today! Past News Letters