ENDIF Statement

Purpose

The ENDIF statement marks the end of an IF/THEN/ELSE conditional block in JCL. It is required to terminate every IF statement and indicates where normal sequential execution of JCL statements resumes.

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] //[name] ENDIF

Key Points

  • ENDIF is required to close every IF/THEN block
  • Each ENDIF is paired with the closest preceding unmatched IF
  • JCL execution resumes sequentially after the ENDIF statement
  • The name field in ENDIF is optional and typically omitted

Examples

Basic IF/THEN/ENDIF Structure

jcl
1
2
3
4
// IF RC = 0 THEN //STEP2 EXEC PGM=GOODRUN // ENDIF //STEP3 EXEC PGM=NEXTSTEP

IF/THEN/ELSE/ENDIF Structure

jcl
1
2
3
4
5
6
// IF STEP1.RC < 8 THEN //STEP2 EXEC PGM=NORMALPROC // ELSE //STEP2 EXEC PGM=ERRORPROC // ENDIF //STEP3 EXEC PGM=CLEANUP

Nested IF with ENDIF

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 /* End of inner IF */ //STEP1 EXEC PGM=BACKUP,PARM='&BACKUP' // ENDIF /* End of outer IF */

Notes

  • Every IF statement must have a corresponding ENDIF statement
  • ENDIF statement pairs with the most recently unpaired IF statement
  • In nested IF structures, each inner IF must be closed with its own ENDIF before the outer IF is closed
  • The name field in the ENDIF statement is optional and is typically omitted
  • Normal sequential execution of JCL statements resumes after the ENDIF
  • Comments can be added after the ENDIF keyword using standard JCL comment syntax

Common Mistakes

  • Omitting the ENDIF statement (required to close every IF)
  • Incorrect nesting of ENDIF statements (must match IF statements in reverse order)
  • Using END instead of ENDIF (not valid in JCL)
  • Placing JCL statements between an ELSE and its ENDIF on the same line

Related Concepts

Related Pages