CL programs and Procedures |
CL programs and Procedures
We can write CL commands as a source statement in a CLP or CLLE source member and can create a CL program or CL procedure out of it.
A CL program is the set of CL source statements that are then compiled either to OPM program (original program model) or ILE module (Integrated Language Environment) that can be bound into programs made up of modules written in CL programs or other languages.
Advantages of CL programs and procedures
Types of CL programs and procedures
There are four types of CL programs and procedures namely
- Procedure
- Module
- Program
- Service program
CL procedure
A CL procedure is a set of self-contained HLL statements that performs a particular function and returns to the caller. It begins with PGM and ends with ENDPGM.
CL module
A CL module is the object that gets created when HLL statements get compiled using an ILE compiler. A CL module is created using the CL command CRTCLMOD (Create CL Module). A module must be bound into a program to run.
A CL module consists of two parts User-written procedure and the program entry procedure generated by the CL compiler. In HLL like RPG, a single module can contain multiple procedures.
CL program
A CL program is created from the CL commands source statements.
The OS supports two types of programs.
- ILE program
- OPM CL program
ILE programs
An ILE program is an IBM i object that consists of one or more modules. Modules cannot be run until they are bound into the programs. The programs must have an entry procedure. A CL compiler generates an entry procedure in each module it creates.
OPM CL programs
An OPM CL program is created using the CL command CRTCLPGM (Create CL program).
Service program
A service program is an IBM i object that contains one or more modules. We can run programs that are not bound to service programs and do not call any service program procedure. However, we cannot run any service program procedure unless that service program is bound to a program.
In order to call procedures in a service program, We must first export the procedure name. A service program can be created using the CL command CRTSRVPGM (Create Service Program).
A program has only one entry point. However, a service program can have multiple entry points. We cannot call the service program directly. We can call procedures in a service program in another program or the service program.