cl400 2
cl400 2
cl400 2
pdf
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 following 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)
Mandatory declaration of procedure variables when variables are used. 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
Commands used to control processing within the CL procedure.
Built-in functions
%SUBSTRING (%SST), %SWITCH, and %BINARY (%BIN)
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.
Declaring a Variable
In its simplest form, the Declare CL Variable (DCL) command has the following
parameters:
DCL &OBJ (TYPE) LEN(10)
*
CHAR for variables containing character data
A LEAVE command without a label will leave the innermost active DO group.
Specifying a label allows the processing to break out of one or more enclosing
groups.
The following illustrates use of the LEAVE command:
DO_1:
DO_2:DOWHILE &LGL
DO_3:
DOFOR &INT FROM(0) TO(99)
.
.
.
IF (&A *EQ 12) THEN(LEAVE DO_1)
.
. /* Not processed if &A equals 12
*/
.
IF (&A *GT 12) LEAVE
.
.
/* Not processed if &A greater than 12 */
.
ENDDO
.
.
.
IF (&A *LT 0) (LEAVE DO_1)
.
. /* Not processed if &A less than zero
*/
.
ENDDO
THEN(CHGVAR &INT 0)
(DOUNTIL (&INT *EQ 0))
- 1)
&LGL 1)