Although each source statement that is
entered as part of a CL source program is actually a CL command, the
source can be divided into the basic parts that are used in many typical
CL source programs.
- PGM command
- PGM PARM(&A)
Optional PGM command beginning
the source program and identifying any parameters received.
- Declare commands
- (DCL, DCLF, COPYRIGHT, DCLPRCOPT)
Mandatory
declaration of program or procedure variables when variables are used,
and optional definition of the size of the subroutine stack. DCLPRCOPT
also provides the ability to override compiler processing options
specified on the CL command used to invoke the CL compiler. The declare commands must precede all other commands except
the PGM command.
- INCLUDE command
- CL command to embed additional CL source commands at compile time.
- CL processing commands
- CHGVAR, SNDPGMMSG, OVRDBF, DLTF, …
CL commands
used as source statements to manipulate constants or variables (this
is a partial list).
- Logic control commands
- IF, THEN, ELSE, DO, ENDDO, DOWHILE, DOUNTIL, DOFOR, LEAVE,
ITERATE, GOTO, SELECT, ENDSELECT, WHEN, OTHERWISE, CALLSUBR, SUBR,
RTNSUBR, ENDSUBR
Commands used to control
processing within the CL program or procedure.
- Built-in functions
- %SUBSTRING (%SST), %SWITCH, %BINARY (%BIN), %ADDRESS (%ADDR),
%OFFSET (%OFS)
Built-in functions and operators used
in arithmetic, relational or logical expressions.
- Program control commands
- CALL, RETURN, TFRCTL
CL commands
used to pass control to other programs.
- Procedure control commands
- CALLPRC
CL command to pass
control to another procedure.
- ENDPGM command
- ENDPGM
Optional End Program command.
The sequence, combination, and extent of these components are determined
by the logic and design of your application.
A CL program or procedure can refer to other objects
that must exist when the program or procedure is created, when the
command is processed, or both. In some circumstances, for your program
or procedure to run successfully, you might need the following objects:
- A display file. Use display files to format information on a device
display. If your procedure uses a display, you must enter and create
the display file and record format by using the Create Display
File (CRTDSPF) command before creating the module. You must
declare it to the procedure in the declare section by using the Declare
File (DCLF) command.
- A database file. Records in a database file can be read by a CL
procedure. If your procedure uses a database file, the file must be
created using the Create Physical File (CRTPF) command
or the Create Logical File (CRTLF) command before
the module is created. You can use Data Description Specifications
(DDS), Structured Query Language (SQL), or interactive data definition
utility (IDDU) to define the format of the records in the file. The
file must also be declared to the procedure in the DCL section using
the Declare File (DCLF) command.
- Other programs. If you use a CALL command, the called program
must exist before running the CALL command. It does not have to exist
when compiling the calling module.
- Other procedures. If you use the CALLPRC command,
the called procedure must exist at the time the Create Bound CL Program
(CRTBNDCL) or Create Program (CRTPGM) command is run.