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.

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.

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

Creating and Binding 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.

We need to create a file, containing the service program definition like this:

SIMPLESRV.bnd

STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('SIMPLEV1')

EXPORT SYMBOL('GETSYSTEMNAME')

ENDPGMEXP
SIMPLESRV.bnd

Update the Rules.mk file

Now we need to add the .srvpgm definition to the Rules.mk file to tell BOB how to create a service program and to attach 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

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.

Creating a Binder Directory

Create a folder to hold your binding directories. I called mine binding-directories but you can call it whatever you want.

Then copying in an .ibmi.json and a Rules.mk file - we will edit the Rules.mk file to reference our new binding directory when we write it.

SIMPLESRV.bnddir

Here we going to have a delete, create and then add an entry for our new service program. If you add more service programs in the future, you would come back and add the new service programs to the OBJ parameter:

!DLTOBJ OBJ(&O/&N) OBJTYPE(*BNDDIR)
CRTBNDDIR BNDDIR(&O/&N) TEXT('Simple Services Binder')
ADDBNDDIRE BNDDIR(&O/&N) OBJ((*LIBL/SIMPLESRV *SRVPGM))
SIMPLESRV.bnddir

Now we need to update the Rules.mk to tell BOB how to build this binding directory:

Creating a Binder Directory

SIMPLEBND.BNDDIR: SIMPLEBND.BNDDIR
Rules mk for SIMPLEBND.BNDDIR

And that's it!

For reals.

Next let's do a video recap of where we are now and how we got there...

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