
Condition & Operator
Conditional Statements
Using IF & ELSE Command
This command is used to branch the flow of logic under some condition
Syntax:
IF COND(LOGICAL EXPRESSION) THEN (CL COMMANDS)
CONDITION MUST BE LOGICAL EXPRESSION
Example:
IF COND(&RESP *EQ 5) THEN CALL (PGM(A))
IF (&A=2) THEN
CALL PGM1
ELSE
CALL PGM2
Operators
Arithmetic & Logical Operators
-
Arithmetic
+ Add
* Multiply
- Subtract
/ Divide
-
Logical
*AND And
*OR Or
*NOT Not
Relational Operators
The Relational Operators that can be used in logical expressions can be
< *LT LESS THAN
= *EQ EQUAL
> *GT GREATER THAN
<= *LE LESS THAN OR EQUAL TO
!< NOT *LT NOT LESS THAN
!> NOT *GT NOT GREATER THAN
>= *GE GREATER THAN OR EQUAL TO
= *NE NOT EQUAL TO
Ex : IF COND(&RESP *EQ 5) THEN CALL PGMA
Character string operators
-
The Character string Operators that can be used can be
*BCAT |> Blank insertion with concatenation
*TCAT |< Blank truncation with concatenation
*CAT || Concatenation
Example : Result
String1 *CAT String2 |String1|String2|
A|B| | | *CAT String2 |A|B|String2
A|B|C|D *BCAT String2 |A|B|C|D|String2
A| | | | *BCAT String2 |A| | String2
Group Statement
DO-ENDO
-
Lets you process a group of commands
-
Commands between Do & Enddo form a group
-
Example:
DO
. .
ENDDO
Example:
IF (&A = &B) THEN (DO)
CALL PGMA
CHGVAR &A (&B+1) GROUP
SNDPGMMSG
ENDDO
GOTO Command
-
Flow of CL programs can be changed unconditionally using this command
-
Label should follow this COMMAND
SYNTAX : GOTO LABEL
Example
IF (&A > 0) THEN GOTO FINAL
ELSE
CALL PGMA
--
--
FINAL: ENDPGM