CL programming

To program using CL, you must understand the procedures and concepts specific to CL programming.

A CL source program is a set of CL source statements that can be compiled into either an original program model (OPM) program or an Integrated Language Environment® (ILE) module.

A CL program or CL procedure is a group of CL commands that tells the system where to get input, how to process it, and where to place the results. The program or procedure is assigned a name by which it can be called by other procedures or bound into a program and run. As with other kinds of procedures, you must enter, compile, and bind CL source statements before you can run the program or procedure.

When you enter CL commands individually (from the Command Entry display, for instance, or as individual commands in an input stream), each command is separately processed. When you enter CL commands as source statements for a CL program or procedure, the source remains for later modification if you choose; the commands are compiled into a module if you use the ILE compiler. This module remains as a permanent system object that can be bound into other programs and run. Thus, CL is actually a high-level programming language for system functions. CL program or procedure ensure consistent processing of groups of commands. You can perform functions with a CL program or procedure that you cannot perform by entering commands individually, and the CL program or procedure provides better performance at run time than the processing of several separate commands.

Start of changeCL programs and procedures can be used in batch or interactive processing. Certain commands or functions are restricted to either batch or interactive jobs. CL source statements consist of CL commands. You cannot use all CL commands as CL source statements, and you can use some of them only in CL procedures or original program model (OPM) programs. CL source statements can be entered in a database source member or an IFS stream file either interactively from a workstation or in a batch job input stream from a device. To create a program using CL source statements, you must enter the source statements into a database source member or an IFS stream file. You can then create an Integrated Language Environment (ILE) program by compiling the source member into a module and binding the module into a program object.End of change

CL programs and procedures can be written for many purposes, including:

  • To control the sequence of processing and calling of other programs or procedures.
  • To display a menu and run commands based on options selected from that menu. This makes the workstation user's job easier and reduces errors.
  • To read a database file.
  • To handle error conditions issued from commands, programs or procedures, by monitoring for specific messages.
  • To control the operation of an application by establishing variables used in the application, such as date, time, and external indicators.
  • To provide predefined functions for the system operator, such as starting a subsystem or saving files. This reduces the number of commands the operator uses regularly, and it ensures that system operations are performed consistently.

These are some of the advantages in using CL programs and procedures for an application:

  • Because the commands are stored in a form that can be processed when the program or procedure is created, using programs and procedures is faster than entering and running the commands individually.
  • CL programs and procedures are flexible. Parameters can be passed to CL programs and procedures to adapt the operations performed by the program or procedure to the requirements of a particular use.
  • CL programs and procedures can be tested and debugged like other high-level language programs and procedures.
  • CL programs and procedures can incorporate conditional logic and special functions not available when commands are entered individually.
  • CL procedures can be bound with procedures of other languages.

You cannot use CL programs and procedures for the following purposes:

  • To add or update records in database files.
  • To use printer or ICF files.
  • To use subfiles within display files.
  • To use program-described display files.