Parts of a CL procedure

While each source statement entered as part of a CL procedure is actually a CL command, the source can be divided into the basic parts used in many typical CL procedures.

PGM command
PGM PARM(&A)

Optional PGM command beginning the procedure and identifying any parameters received.

Declare commands
(DCL, DCLF, COPYRIGHT, DCLPRCOPT)

Mandatory declaration of procedure variables when variables are used, and optional definition of the size of the subroutine stack. The declare commands must precede all other commands except the PGM command.

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 procedure.

Built-in functions
Start of change%SUBSTRING (%SST), %SWITCH, %BINARY (%BIN), %ADDRESS (%ADDR), %OFFSET (%OFS)End of change

Built-in functions and operators used in arithmetic, relational or logical expressions.

Program control commands
CALL, RETURN

CL commands used to pass control to other programs.

Procedure control commands
CALLPRC, RETURN

CL commands used to pass control to other procedures.

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 procedure may refer to other objects that must exist when the procedure is created, when the command is processed, or both. In some circumstances, for your procedure to run successfully, you may need:
Related tasks
Access objects in CL programs
Work with files in CL procedures
Control flow and communicate between programs and procedures
Related information
Create Physical File (CRTPF) command
Create Logical File (CRTLF) command
Create Display File (CRTDSPF) command
Declare File (DCLF) command
Call (CALL) command
Call Bound Procedure (CALLPRC) command