IDCAMS IF-THEN-ELSE statement structure
IF {LASTCC | MAXCC} {operator} {numeric value} THEN {command} | DO
{command set}
END
[ELSE {command} | DO
{command set}
END]
- COND, THEN, and COMMAND must be in same line (hyphen can be used if it’s too long)
- ELSE and COMMAND must be in same line (hyphen can be used if it’s too long)
- Following the THEN keyword or the optional ELSE keyword, either a single command or a block of commands enclosed in a DO/END pair may be coded.
- If COMMAND is a command set, then a DO is required immediately after the THEN/ELSE keyword in the same line.
- Null Commands: if a THEN keyword or ELSE keyword in an IF-THEN-ELSE structure is not followed by an AMS functional command, or does not include a continuation character indicating that a functional command follows on the next line, then a null THEN or ELSE clause is assumed.
Sample 1
IF MAXCC EQ 0 THEN DO
SET MAXCC = 7
END
ELSE DO
END
Sample 2
IF LASTCC = 0 -
THEN -
REPRO ...
/*THIS IS A COMMENT LINE*/
ELSE -
PRINT ...
Sample 3
IF LASTCC = 0 THEN REPRO ...
ELSE PRINT ...
Sample 4
IF LASTCC = 0 THEN -
DELETE 'SOME.DATASET.NAME'
ELSE SET MAXCC = 0
Sample 5
IF LASTCC = 0 THEN -
DEFINE CLUSTER ( NAME('INFP.INF.RPG0002') -
RECORDSIZE(80 80) -
SPANNED -
REUSE -
CYLINDERS(1 1) -
NONINDEXED )