THEN Statement

Purpose

The THEN statement is an essential part of JCL conditional processing. It follows an IF statement and marks the beginning of a block of JCL statements that will be executed when the IF condition evaluates to true.

Syntax

jcl
1
2
3
4
5
//[name] IF (condition) THEN // statements to be executed if condition is true [// ELSE // statements to be executed if condition is false] // ENDIF

Key Points

  • THEN is always required after an IF statement
  • It must appear on the same statement line as the IF
  • It introduces the statements to be executed when the condition is true
  • The THEN block continues until an ELSE or ENDIF statement is encountered

Examples

Basic IF/THEN Structure

jcl
1
2
3
4
// IF RC = 0 THEN //STEP2 EXEC PGM=GOODRUN //PRINT DD SYSOUT=A // ENDIF

IF/THEN/ELSE Structure

jcl
1
2
3
4
5
// IF STEP1.RC < 8 THEN //STEP2 EXEC PGM=REGULAR // ELSE //STEP2 EXEC PGM=RECOVER // ENDIF

Nested IF/THEN

jcl
1
2
3
4
5
6
7
8
// IF &SYSDAY = 'FRIDAY' THEN // IF &SYSTIME > '17:00' THEN // SET BACKUP='FULL' // ELSE // SET BACKUP='INCR' // ENDIF //STEP1 EXEC PGM=BACKUP,PARM='&BACKUP' // ENDIF

Notes

  • The THEN keyword must appear on the same JCL statement as the IF condition
  • The statements controlled by the THEN clause must follow on subsequent lines
  • JCL statements in the THEN block can include any valid JCL, including EXEC, DD, and SET statements
  • If the condition is false, execution skips to the ELSE clause or ENDIF statement
  • The name field in the IF/THEN statement is optional and is typically omitted
  • No special continuation is needed for the THEN keyword

Common Mistakes

  • Putting THEN on a separate line (must be on the same line as IF)
  • Forgetting the corresponding ENDIF statement
  • Incorrect nesting of multiple IF/THEN blocks
  • Using END instead of ENDIF to close the block

Related Concepts

Related Pages