Two Programmers talking about IBM i Service Programs

This is an excerpt from an email conversation I had with a dear old friend of mine a decade ago. Toby Schofield was a great guy and a terrific programmer (sadly missed) but was very focused on old style RPG programming (he was a JBA programmer) and this lesson is a sample of a long conversation we had discussing service programs and how they work. Hope it helps somebody!

A service program is basically a little RPG thing you define all of you sub-procedures in. Sort of looks like an RPG program that just contains lots and lots of subroutines… but they are not subroutines they are sub-procedures. 

You can tell it's a service program because the H-Spec will say ‘NOMAIN’ and this literally means it has no MAINLINE CODE it’s just a list of sub-procedures.

Obviously, if you are using a service program in your RPG program you need to tell your RPG program to go and use that *SRVPGM to get its subprocedure list. You can either do that by adding it to your compile parm:

CRTPGM PGM('myprogram') BNDSRVPGM((TOBYSRVPGM))

or be much neater and use a Binding Directory.

Then just use your H spec:

H BNDDIR('@PROJEX')

In this example I will show you how I use the binding directory I created for Projex4i.

Two Programmers talking about IBM i Service Programs 1

A binding directory is thing that has a list of service programs in it. you can add lots of them. you would use WRKBNDIRE to look at all the entries in a binding directory:

So, here you can see I have 4 service programs in my Projex4i binding directory.

Each of those service programs can have lots of sub-procedures in it. Or just one. It’s your call.

Look at SRVPGM(@SRVCORE) for example:

DSPSRVPGM SRVPGM(@SRVCORE)

Service program . . . . . . . . . . . . : @SRVCORE
Library . . . . . . . . . . . . . . . : PROJEX4I
Owner . . . . . . . . . . . . . . . . . : NLITTEN
Service program attribute . . . . . . . : RPGLE
Detail . . . . . . . . . . . . . . . . . : *PROCEXP

#CAPITALISE
#CENTER
#CHECKCOMMAND
#CLEANCHEVRON
#CLEANIFSDOCUMENT
#CLEANIFSFOLDER
#CLEANIFSURL
#CLEANOBJECTNAME
#CLEANWHACK
#DISPLAY
#DUMPCALLSTACK
#FILEFMTNAME
#FILEINFO
#FINDCALLER
#GENRANDOM
#GETIBMILPAR
#GETIBMISERIAL
#GETIBMISYSNAME
#COMMANDLINE
#GETIBMIVERSION
#GETPROJEXDAYS
#GETPROJEXKEY
#GETPROJEXSTATUS
#GETSYSTEMVALUE
#INTERACTIVE
#LEANBACKWARD
#LEANFORWARD
#LOWERCASE
#MBRTEXT
#QUOTE
#REGISTERPROJEX
#RUNCOMMAND
#SCANREPLACE
#SEARCHINDEX
#SPLITSTRING
#SQUISH
#SQUISHSINGLE
#UNDERSCOREIT
#UPPERCASE
#VALID8EMAIL

For example – Note that this service program contains a sub-procedure called ‘#Interactive’ it could be called anything I just like to use #something so I know its one of my sub-procedures. Some people argue that using special characters is un-necessary noise. But I am not a number, I am a free man!

So, in any program that defines this binding directory in its H-SPEC will have automatic access to all those sub-procedures from its RPG (or incidentally CL commands).

So, whenever you have repeatable code – you define it as a subprocedure then you can use it everywhere.

Procedures are as slick right? I’m sure you will agree.

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