Service programs can be written in a variety of languages, including RPG, COBOL, C, and C++. They can also be used to provide an interface to external resources, such as databases or web services.

  • Provide reusable code: Service programs allow developers to write code once and reuse it in multiple applications, reducing code duplication and improving maintainability.
  • Encapsulate complex logic: Service programs can be used to encapsulate complex business logic or algorithms, making it easier to manage and maintain.
  • Improve performance: Service programs can be optimized and compiled into machine code, making them faster and more efficient than equivalent code written in other programming models.
  • Flexibility: Service programs can be written in a variety of languages and can be used to provide a wide range of functions and services.

We have three components to setup for our service program, the service program itself, a binding directory and the binder language that tells the system what procedures the service program is sharing with the world.

Let's look at defining a simple *SRVPGM in Visual Studio Code for IBM i

Service Program - simplesrv.srvpgm

I'm starting this one by creating a folder called "services" and adding that folder name to the root/Rules.mk file. Then copying in an .ibmi.json and a Rules.mk file - we will edit the Rules.mk file to reference our new service program when we write it.

Now we can write a very simple SQL RPGLE service program to do something like return the ibm i system name.

HINT - we could do this is a single bound RPG program rather than a MODULE and ILEPGM but for clarity I'm going to do the longer format module and ILEPGM. If we want to make a bound program we would have simply changed the name of our source file from .sqlrpgle to .pgm.sqlrpgle

We create our module source code for this service program with an .sqlrpgle extension. I have called mine SIMPLEMOD-Simple_Service_Program.sqlrpgle

SIMPLEMOD-Simple_Service_Program.sqlrpgle

**free
ctl-opt nomain;

dcl-proc getsystemname export;
  dcl-pi getsystemname;
    systemname char(8);
  end-pi;

  exec sql
    VALUES CURRENT SERVER INTO :systemname ;

  return;

end-proc;
SIMPLEMOD-Simple_Service_Program.sqlrpgle

Now we need to tell BOB that this will be compiled as a module. Make sure this line is in the Rules.mk file:

SIMPLEMOD.MODULE: SIMPLEMOD-Simple_Service_Program.sqlrpgle

We can compile this, and it will create a module called SIMPLEMOD:

Create the module

VS Code and Service Programs 1

Once it's deployed and compiled you should see a module in your project library:

module created

Now let's create the service program, using this module. 

To do this we need to add a new file with the extension .bnd This is the Binder Source language that defines what the service program is going to do. This definition will tell BOB to perform the crtsrvpgm command.

Update the Rules.mk file

Now we need to add the .srvpgm definition to the Rules.mk file to tell BOB to create a service program from the binder language and the module (or multiple models):

SIMPLEMOD.MODULE: SIMPLEMOD-Simple_Service_Program.sqlrpgle

SIMPLESRV.SRVPGM: SIMPLESRV.BND SIMPLEMOD.MODULE
rules mk for service programs

SIMPLESRV.bnd

The binder language definition tells the system which procedures will be exported from the service program. In other words, which procedures will be exported or made available for use for programs that want to use this service program.

SIMPLESRV.bnd
STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('SIMPLEV1')
  EXPORT SYMBOL('GETSYSTEMNAME')
ENDPGMEXP

HINT - remember to also add your services folder to the root Rules.mk file so the compiler knows to look in there and process its Rules.mk file.

And that's it!

Or is it?

Of course, it's not - we want to create a binding directory so that RPG programs can use that binding directory to find our new service program.

But let's dive into this during the next lesson...

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