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.
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
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;
Now we need to tell BOB that this will be compiled as a module. Make sure this line is in the Rules.mk file:
We can compile this, and it will create a module called SIMPLEMOD:
Create the module
Once it's deployed and compiled you should see a module in your project library:
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
EXPORT SYMBOL('GETSYSTEMNAME')
ENDPGMEXP
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):
SIMPLESRV.SRVPGM: SIMPLESRV.BND SIMPLEMOD.MODULE
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:
Now we need to update the Rules.mk to tell BOB how to build this binding directory:
Creating a Binder Directory
And that's it!
For reals.
Next let's do a video recap of where we are now and how we got there...