You are on page 1of 17

CL/400

(Control Language/400)
CL/400
Control Language (CL) is the primary
interface to the Operating System.


Introduction to CL/400
CL is a primary interface to the operating
system.
CL can be used as a programming
language,allowing common tasks to be
automated.

Disadvantages of CL programs
CL programs cannot UPDATE,
DELETE or WRITE records into a
database file as other HLL(high level
language) programs like
RPG/400,COBOL/400 etc can do.


CL Program Structure

Declare a CL Variable(DCL)
DCL VAR(&NAME) TYPE( ) LEN( ) VALUE( )

TYPE( ) LEN( ) VALUE( )

*DEC default (15 5) default(0)
max (15 9)
*CHAR default (32) default(b)
max (9999)
*LGL 1 default(0)

Examples for declaring a CL
variable

(1) DCL &A *LGL VALUE(1)

(2) DCL &B *CHAR 5 ABCDb

(3) DCL &C *DEC (6 2) 0543.21

CHGVAR-Arithmetic Calculations
+
CHGVAR VAR(CL-variable) VALUE(operand - operand)
*
/

CHGVAR VAR(&AMT) VALUE(-37.2)
CHGVAR VAR(&COUNT) VALUE(&COUNT + 1)

CHGVAR &AMT ((&PRICE - &DISCOUNT) * &QTY)



Relational and Logical Expressions
Expression: (Operand Operator Operand)
Result of a relational or logical expression: 1 True
or 0 False
Operands: Constant, Variable, Another Expression
Operators Description
< *LT Less Than
= *EQ Equal to
> *GT Greater than


Relational and Logical Expressions
..Cont
Operators Description
<= *LE Less than or equal to
!< *NL Not less than
!> *NG Not Greater than
>= *GE Greater than or equal to
!= *NE Not Equal to
& *AND True if both operands are 1
| *OR True if both or either operand is 1
! *NOT

IF Examples
1.IF COND(&RESP *EQ 5) THEN(CALL PGM(CUSINQ))
IF (&RESP *EQ 5) CALL CUSINQ
2.IF COND(&AMT *GT 10000) THEN(CALL PGMBIG)
ELSE CMD(CALL PGMSMALL)
3.IF (&A *NE &B) RETURN

IF (&A= &B)
ELSE RETURN
4.IF &IN03 RETURN

Nested IF Statements
KEYWORD FORM:
IF COND(&RESP=1) THEN(IF COND(&A=5) THEN(IF +
COND(&B=N) THEN(CALL PGM(PGMA))))
POSITIONAL FORM:
IF (&RESP=1) IF(&A=5) IF(&B=N) CALL PGMA
DO,ENDDO FORM:
IF COND(&RESP=1) THEN(DO)
IF COND(&A=5) THEN(DO)
IF COND(&B=N) THEN(DO)
CALL PGMA
ENDDO
ENDDO
ENDDO


PGMB and/or PGMC and/or
PGMD
IF COND(&A=&B)
THEN(CALL PGM(PGMB))

IF COND(&A=&C)
THEN(CALL PGM(PGMC))

IF COND(&A=&D)
THEN(CALL(PGMD))
T
T
T
F
F
F

PGMB or PGMC or PGMD
.
&A=&B
&A=&C
&A=&D
PGMB
PGMC
PGMD
T
T
T
F
F
F

PGMB or PGMC or PGMD
..cont
IF COND(&A=&B) THEN(CALL PGM(PGMB))
ELSE CMD(IF COND(&A=&C) THEN(CALL
PGM(PGMC)))
ELSE CMD(IF COND(&A=&D) THEN(CALL
PGM(PGMD)))

Do Group
IF COND(&A *GT 100) THEN(DO)
CALL PGM1
CALL PGM2
ENDDO
ELSE CMD(DO)
CALL PGM3
CALL PGM4
ENDDO
CALL PGM5


Branching within a program-GOTO
PGM
START: SNDRCVF RCDFMT(MENU)
.
.
IF (&OPTION=12) GOTO CMDLBL(END)
.
.
GOTO START
END : ENDPGM

You might also like