IBM i e-Book
A Developer’s Guide to Mastering IBM i Concepts
IBM i Index
Integrated Language Environment
Service Program
Introduction
A service program is a collection of available data items and runnable procedures that other ILE programs or service programs can directly and easily access. A service program is similar to a subroutine library or procedure library in many aspects.
The name “service program” refers to the common services that these programs offer that other ILE objects might need.
A service program’s public interface is consisting of the names of the exported procedures and data items that other ILE objects can access. A service program can only export items that are exported from the module objects that make up the service program.
Which processes or data items are known to other ILE objects can be specified by the programmer. Therefore, private, or hidden processes and data within a service program can exist and become unavailable to other ILE objects.
A service program can be updated without requiring the other ILE programs or service programs that use the updated service program. Whether a change is compatible with the current support is up to the programmer who is making the changes to the service program.
Characteristics of an ILE *SRVPGM object:
- To create the *SRVPGM object, one or more modules are copied from any ILE language.
- There is no PEP connected to the service program. A dynamic program call to a service program is not valid as there is no PEP. The PEP of a module is ignored.
- The public interface identifies this service program’s exports, which are available for use by other ILE programs or service programs.
- The procedure and data item names that are exported from the service program are used to generate signatures.
- As long as previous signatures are still supported, service programs can be changed without impacting ILE programs or service programs that utilize them.
- Modules can have debug data.
- It is only possible to export weak data to an activation group. It cannot be included in the exported public interface from the service program.
Create and use the service program:
MODULECALL1:
**Free Dcl-Pr Addition Zoned(5:0); Num1 Zoned(2:0); Num2 Zoned(2:0); End-Pr; Dcl-Pr Subtraction Zoned(5:0); Num1 Zoned(2:0); Num2 Zoned(2:0); End-Pr; Dcl-S Number1 Zoned(2:0) Inz(60); Dcl-S Number2 Zoned(2:0) Inz(20); Dcl-S Output Zoned(5:0); Output = Addition(Number1:Number2); Dsply Output; Output = Subtraction(Number1:Number2); Dsply Output; *Inlr = *On;
MODULE1:
**Free Dcl-Proc Addition Export; Dcl-Pi Addition Zoned(5:0); Num1 Zoned(2:0); Num2 Zoned(2:0); End-Pi; Dcl-S Result Zoned(5:0); Result = Num1 + Num2; Return Result; *Inlr = *On; End-Proc;
MODULE2:
**Free Dcl-Proc Subtraction Export; Dcl-Pi Subtraction Zoned(5:0); Num1 Zoned(2:0); Num2 Zoned(2:0); End-Pi; Dcl-S Result Zoned(5:0); Result = Num1 - Num2; Return Result; *Inlr = *On; End-Proc;
- Create Module MODULECALL1, MODULE1, and MODULE2.
CRTRPGMOD MODULE(DEMOLIB/MODULECALL) SRCFILE(DEMOLIB/QRPGLESRC) CRTRPGMOD MODULE(DEMOLIB/MODULE1) SRCFILE(DEMOLIB/QRPGLESRC) CRTRPGMOD MODULE(DEMOLIB/MODULE2) SRCFILE(DEMOLIB/QRPGLESRC)
- To create a service program SRVPGM1, use the CRTSRVPGM command.
CRTSRVPGM SRVPGM(DEMOLIB/SRVPGM1) MODULE(DEMOLIB/MODULE1 DEMOLIB/MODULE2) EXPORT(*ALL)
- To display a service program, use the DSPSRVPGM command.
DSPSRVPGM SRVPGM(DEMOLIB/SRVPGM1)
- To update a service program, use the UPDSRVPGM command.
- Now bind the service program SRVPGM1 to the calling program CALLPGM1.
CRTPGM PGM(DEMOLIB/CALLPGM1) MODULE(DEMOLIB/MODULECALL) BNDSRVPGM((DEMOLIB/SRVPGM1))