An IBM-i Service Program is a collection of reusable procedures and data items that can be accessed by other Integrated Language Environment (ILE) programs or service programs on the IBM i (AS400/iSERIES) system.
Here are some key points about service programs:
We reference the Service Program Procedures in the calling program. The service program is created and is loaded into memory when the calling program uses one of the service program procedures.
For example, imagine a service program had these procedures in it:
DCL-PROC AddNumbers;
DCL-PI *N INT(10);
NUM1 INT(10);
NUM2 INT(10);
END-PI;
RETURN NUM1 + NUM2;
END-PROC;
DCL-PROC SubtractNumbers;
DCL-PI *N INT(10);
NUM1 INT(10);
NUM2 INT(10);
END-PI;
RETURN NUM1 - NUM2;
END-PROC;
In this example, 'AddNumbers' and 'SubtractNumbers' are procedures within a module that are included in a service program.
A regular program would need to be told that it is using a service program - by adding a BNDDIR or the SRVPGM name to its control specification
We would create this using the CRTSRVPGM command:
CRTSRVPGM SRVPGM(MYLIB/MYSRVPGM) MODULE(MYLIB/MYMODULE) EXPORT(*ALL)
The 'CRTSRVPGM' command creates the service program and specifies that all procedures in the module should be exported.