HOWTO: Creating an RPGLE Service Program
I was struggling on creating an RPGLE service program for few days. After finally succeeded I have created a basic guide on how to create and use a service program. I hope it would help some of you.
Creating the Module
(H) NOMAIN Header and other required header (e.g. binding)
(F) Declare files (If any)
(D) Declare the procedure prototype (you can write the prototype in /COPY file and copy the prototype into the source file so you can use the same prototypes definition in your program), and module level variables (If any)
(P) Declare the procedure and begin
(D) Declare the procedure interfaces
(D) Declare procedure level variables
(P) End the procedure
A module can contain one or more procedures.
Option 15 ( CRTRPGMOD ) to compile and the output will be in type *MODULE
Creating the Binder Directory (If not already created)
Execute the create binding directory command
Specifying the BNDDIR name and the library.
Creating the Binder Source
Create a source file (if not already created) for the binding sources members (QSRVSRC).
Create BND member, a BND member for every service program (*SRVPGM)
|If your service program is built from multiple modules, the binder source should contain the exports for all modules in that service program.|
STRPGMEXP PGMLVL(*CURRENT) EXPORT SYMBOL(proc1) EXPORT SYMBOL(proc2) EXPORT SYMBOL(proc3) ENDPGMEXP
Where proc1, proc2 and proc3 are the procedures defined in the module.
Another alternative for creating the binder source is to run RTVBNDSRC once the *MODULE is created. It will build entries for all EXPORTed procedures.
Refer to this URL for a guide on how to create a binder source
Creating the Service Program
After creating the module, binding directory and the binder source, we can now create the service program
Execute the create service program command
Adding the Service Program to the Binding Directory
Execute the add binding directory entry command:
Using the Service Program in Your Program
(H) Defined the binding directory and set the default activation group to no.
It is recommend to specify an activation group here. Use the same activation group for all programs if you like, but don’t use the IBM supplied QILE (which is what you’re doing). It’s just nicer to be able to reclaim your own programs without risking reclaiming 3rd party software.
This works very well. When we need to reclaim an activation group to remove the program activations from memory (for whatever reason) we do this:
And it reclaims our programs without touching 3rd party or IBM programs that we don’t want to reclaim.
H BNDDIR('Library-name/Binding-directory') DFTACTGRP(*NO) ACTGRP('activation-group-name')
(F) Files declaration
(D) Declare the prototype of the procedure which is going to be implemented, declare the procedure interfaces variables, and other D specs declarations.
(C) Calculation spec
Compile your code using option 14 ( CRTBNDRPG ).
Done! Good day
|Print article||This entry was posted by jeddx on July 1, 2010 at 6:45 pm, and is filed under HOWTOs. Follow any responses to this post through RSS 2.0. Responses are currently closed, but you can trackback from your own site.|
Comments are closed.