CNTL/ENDCNTL Statements

Purpose

The CNTL (Control) and ENDCNTL (End Control) statements create a control group that contains program control statements or operator commands. These statements provide a structured way to include multiple commands, parameters, or control statements within JCL, serving as a container for information that will be passed to a program or the system during execution.

Key Benefit:

CNTL/ENDCNTL provides an organized structure for including multiple commands or program-specific control statements directly within JCL, which enhances readability and maintainability of complex job streams.

Basic Syntax

CNTL/ENDCNTL Structure

jcl
1
2
3
4
5
6
//name CNTL // command-1 // command-2 ... // command-n // ENDCNTL

In this structure:

  • name is a user-defined label for the control group
  • command-1 through command-n are program control statements or system commands
  • Commands must start in column 3 (after // and a space)
  • The ENDCNTL statement marks the end of the control group

DD Statement Reference

jcl
1
//ddname DD CNTL=*.name

To reference the control group, a DD statement uses the CNTL parameter with a backward reference (*.name) to the labeled CNTL statement.

Usage Examples

IDCAMS Control Statements

jcl
1
2
3
4
5
6
7
8
9
10
11
//MYJOB JOB (ACCT#),'ADMIN',CLASS=A //* //DELSTEP EXEC PGM=IDCAMS //SYSIN DD CNTL=*.DELCNTL //SYSPRINT DD SYSOUT=* //* //DELCNTL CNTL DELETE MY.OLD.DATASET PURGE DELETE MY.TEMP.DATASET PURGE SET MAXCC=0 // ENDCNTL

This example uses CNTL/ENDCNTL to provide control statements to the IDCAMS utility, instructing it to delete multiple datasets.

System Commands Group

jcl
1
2
3
4
5
6
7
8
9
10
11
//CMDJOB JOB (ACCT#),'OPERATOR',CLASS=A //* //STEPA EXEC PGM=IEFBR14 //* //CMDCNTL CNTL COMMAND 'D A,L' COMMAND 'D ASM' COMMAND 'D GRS,C' // ENDCNTL //* //CMDS DD CNTL=*.CMDCNTL

This example uses CNTL/ENDCNTL to group multiple system display commands that will be issued during job execution.

SQL Statements for DB2

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//DB2JOB JOB (ACCT#),'DBA',CLASS=A //* //RUNSQL EXEC PGM=DSNTEP2,PARM='ALIGN(MID)' //STEPLIB DD DSN=DB2.LOADLIB,DISP=SHR //SYSTSPRT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSUDUMP DD SYSOUT=* //SYSTSIN DD CNTL=*.SQLCNTL //* //SQLCNTL CNTL DSN SYSTEM(DB2P) RUN PROGRAM(DSNTEP2) PLAN(DSNTEP12) - LIB('DB2.RUNLIB') SELECT * FROM SYSIBM.SYSTABLES WHERE CREATOR = 'USER1'; SELECT COUNT(*) FROM USER1.CUSTOMER; END // ENDCNTL

This example shows how to use CNTL/ENDCNTL with DB2 statements to execute SQL queries through batch processing.

Sort Utility Control

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//SORTJOB JOB (ACCT#),'USER',CLASS=A //* //STEP1 EXEC PGM=SORT //SORTIN DD DSN=MY.INPUT.FILE,DISP=SHR //SORTOUT DD DSN=MY.OUTPUT.FILE,DISP=(NEW,CATLG), // SPACE=(CYL,(10,5)),UNIT=SYSDA //SYSIN DD CNTL=*.SORTCNTL //SYSOUT DD SYSOUT=* //* //SORTCNTL CNTL SORT FIELDS=(1,10,CH,A,11,5,PD,D) INCLUDE COND=(21,4,CH,EQ,C'DEPT') OPTION EQUALS // ENDCNTL

This example demonstrates using CNTL/ENDCNTL to provide sort control statements to the SORT utility program.

Common Applications

Program/UtilityCNTL Usage
IDCAMSDELETE, DEFINE, REPRO, and other Access Method Services commands
IEBGENERData conversion and formatting control statements
SORTSort field definitions, include/exclude conditions, and options
DB2SQL statements and DSN commands
FTPFTP commands and transfer specifications
COMMANDGroups of system or subsystem commands

Usage Details

Placement Rules

  • CNTL statement can appear anywhere in the JCL after the JOB statement
  • CNTL groups are often placed after the step that references them
  • Multiple CNTL groups can be defined in a single job
  • Each CNTL statement must have a matching ENDCNTL
  • Control statements within CNTL/ENDCNTL are not processed by JCL, but passed to the program

CNTL vs. Inline Data

CNTL/ENDCNTLDD * or DD DATA
Can be referenced by multiple DD statementsUsed by a single DD statement
JCL syntax rules apply to statementsFree-form data without JCL syntax constraints
Each line starts with // (columns 1-2)No // prefix required for data lines
Better for system commands and standard control statementsBetter for arbitrary data or non-standard formats

Advantages and Benefits

  1. Reusability - A single CNTL group can be referenced by multiple DD statements
  2. Organization - Provides structured grouping of related commands or statements
  3. Maintainability - Control statements are kept separate from program execution steps
  4. Readability - Clearly identifies command groups in complex JCL
  5. Consistency - Ensures the same commands are used across multiple references
  6. JCL Syntax Checking - Control statements follow JCL syntax rules

Limitations

  • Line Format - Each line must follow JCL statement format rules
  • Character Set - Limited to JCL-supported character set
  • Line Length - Subject to JCL line length restrictions
  • No Variable Substitution - JCL symbolic parameters are not processed within CNTL groups
  • Not All Programs Support It - Some programs may require DD * or DD DATA instead

Best Practices

  1. Use Meaningful Labels for CNTL statements to indicate their purpose
  2. Add Comments to explain complex control statement groups
  3. Place Related CNTL Groups Together for better organization
  4. Consider Separating Long CNTL Groups into multiple, logically grouped CNTL blocks
  5. Position CNTL Statements after the steps that reference them when possible
  6. Check Program Documentation to ensure CNTL is supported for the specific application
  7. Use Consistent Indentation for control statements to improve readability

Troubleshooting

IssuePossible CausesSolutions
JCL error on CNTL statement
  • Missing ENDCNTL statement
  • Invalid syntax in control statements
  • Add matching ENDCNTL statement
  • Check JCL syntax for all statements in CNTL group
Program doesn't recognize statements
  • Program requires different input format
  • Control statements not following program syntax
  • Check program documentation for required input format
  • Consider using DD * instead of CNTL if needed
CNTL reference not found
  • Incorrect label in CNTL=*.name reference
  • CNTL label not defined in job
  • Verify the label matches between CNTL and DD reference
  • Ensure CNTL statement is defined before it's referenced
Command syntax errors
  • Invalid commands or parameters
  • Program-specific syntax requirements not met
  • Check program documentation for correct command syntax
  • Validate commands in program-specific documentation

Debugging Tips

  • Use MSGLEVEL=(1,1) to see expanded JCL with control statements
  • Check program output for error messages related to control statements
  • Test control statements directly (without CNTL) to verify syntax
  • Consult program-specific documentation for control statement requirements
  • Use TYPRUN=SCAN to validate JCL syntax without execution

JES2 vs JES3 Considerations

  • CNTL/ENDCNTL functionality is identical in both JES2 and JES3 environments
  • No significant differences in syntax or behavior between JES versions
  • Both support backward references to CNTL groups using the same format

Related Concepts