
Introduction to CL Programming
Why write a CL program.
-
A CL program consists of a series of CL commands that you can compile and run as a group.
-
You can write CL programs that directly access system level operations.
How to create a CL Program.
-
Type all the needed CL commands into a source member.
-
Compile the CL program, creating a program object
Advantage of CL Program
-
CL programs are written to control the flow of work in a job
-
Compiled CL program leads to faster execution
-
CL provides programming language constructs like
Arithmetic operators
Logical Operators
Handling Screens
Db I/O opearations
-
No syntax checking done at runtime but at compile time
Rules To declare variable
-
Variable names should begin with ‘&’ followed by as many as 10 characters
-
Character string (Max 9999 chars)
-
Packed decimal (15 digits with as many as 9 decimal positions)
-
Logical value (0 or 1)
Declare Variables and Files
Variables
-
Parameters used in CL programs can be expressed as variables, constants or expressions
-
This should precede all commands except PGM Command
-
The variable declared should start with ‘&’
Syntax: DCL VAR(&variable-name)
Example:
DCL VAR(&NAME1) TYPE (*CHAR) LEN(10)
DCL VAR(&TELE) TYPE (*DEC) LEN(2 0) VALUE(10)
Syntax :
DCL VAR(variable name) TYPE *DEC LEN(LENGTH) VALUE (initial-value)
*LGL
*CHAR
File
-
Files may have one or more record formats and fields within it.
-
During CL program compilations, all fields and records are implicitly defined by DCL statements.
-
They are automatically available for use in CL Programs
Example:
DCLF FILE(lsslib/filea)