COMMAND Statement

Purpose

The COMMAND statement (abbreviated as CMD) allows batch jobs to issue MVS system commands, JES2 commands, or JES3 commands during job execution. This provides a way to automate operator actions that would otherwise require manual intervention, such as mounting tapes, starting processes, modifying system parameters, or displaying system status.

Key Benefit:

The COMMAND statement enables automation of operator tasks directly from JCL, reducing the need for manual intervention during batch job execution and allowing jobs to interact with the operating system environment.

Basic Syntax

Simple Format

jcl
1
2
3
// COMMAND 'system-command' // or // CMD 'system-command'

The command must be enclosed in single quotes and can be any valid MVS, JES2, or JES3 command.

Syntax Variants

jcl
1
2
3
4
// COMMAND PREFIX=xx 'system-command' // COMMAND REL=JES3 'system-command' // COMMAND REL=JES2 'system-command' // COMMAND REL=SYSTEM 'system-command'

Command Timing

PlacementExecution Timing
Before first EXECExecuted when the job is selected for execution
Between job stepsExecuted after the previous step completes and before the next step begins
After last stepExecuted after the last step completes, during job termination

Parameters

ParameterDescription
PREFIX=xxSpecifies a prefix to be used with the command (e.g., PREFIX=$)
REL=SYSTEMIndicates that the command is an MVS system command
REL=JES2Indicates that the command is a JES2 command
REL=JES3Indicates that the command is a JES3 command

Usage Examples

Display System Information

jcl
1
2
3
4
//SYSINF JOB (ACCT#),'OPERATOR',CLASS=A // COMMAND 'D A,L' /* Display active jobs */ //STEP1 EXEC PGM=IEFBR14 // COMMAND 'D T' /* Display time and date */

This job displays a list of active jobs before executing STEP1, then displays the current time and date after STEP1 completes.

Modify System Resources

jcl
1
2
3
4
5
6
//MODRES JOB (ACCT#),'OPERATOR',CLASS=A // COMMAND 'S CICSRGN' /* Start CICS region */ //STEP1 EXEC PGM=CICSPROC // COMMAND 'F CICSRGN,CEMT PERFORM STATISTICS' //STEP2 EXEC PGM=CLEANUP // COMMAND 'P CICSRGN' /* Stop CICS region */

This job starts a CICS region, performs a process, requests statistics, and then stops the CICS region, all automated within JCL.

Control JES Resources

jcl
1
2
3
4
5
//JESCTL JOB (ACCT#),'OPERATOR',CLASS=A // COMMAND REL=JES2 '$P PRT1' /* Pause printer 1 */ //STEP1 EXEC PGM=PRTMAINT // COMMAND REL=JES2 '$T PRT1,F=STD3' /* Change form */ // COMMAND REL=JES2 '$S PRT1' /* Start printer 1 */

This job controls a JES2 printer by pausing it, executing maintenance, changing the form type, and then restarting the printer.

Dynamic Allocation Control

jcl
1
2
3
4
5
//DEVCTL JOB (ACCT#),'OPERATOR',CLASS=A // COMMAND 'MOUNT TAPE01,VOL=123456,UNIT=TAPE' //STEP1 EXEC PGM=TAPEDUMP // COMMAND 'UNLOAD TAPE01' //STEP2 EXEC PGM=REPORT

This job issues commands to mount a tape before processing and unload it afterward, automating tape handling operations.

Security Considerations

  • Authorization Required: Jobs that use COMMAND statements typically need special authorization
  • Restricted Commands: Some commands may be disallowed or restricted based on security settings
  • Command Validation: Security products like RACF, ACF2, or Top Secret validate command permissions
  • Audit Logging: Commands issued via JCL are typically logged for security audit purposes
  • Potential Impact: Commands can affect system-wide resources, so proper controls are essential

Security Configuration

Security for COMMAND statements is typically controlled through:

  • RACF OPERCMDS class profiles
  • ACF2 command limiting controls
  • Top Secret command authorization settings
  • Installation-specific command exits

Common Use Cases

  1. Application Environment Setup: Starting or configuring application regions before processing
  2. Resource Management: Allocating or freeing system resources dynamically during job execution
  3. Automated Operations: Performing operator tasks without manual intervention
  4. Status Monitoring: Displaying system information at specific points in the job
  5. Scheduled Maintenance: Performing system maintenance activities during batch windows
  6. Disaster Recovery: Issuing commands to configure resources during recovery scenarios

Best Practices

  1. Use Comments to document the purpose of each command
  2. Specify REL= parameter explicitly for clarity and to avoid ambiguity
  3. Plan for command failure by including error handling in the job
  4. Use descriptive jobnames for jobs containing system commands
  5. Consider security implications of every command issued
  6. Limit command usage to necessary operations only
  7. Test commands thoroughly in non-production environments
  8. Document command dependencies between jobs and systems

Limitations

  • Command Length: Limited to approximately 124 characters
  • Response Processing: Command responses appear in the system log, not the job log
  • Error Handling: Limited ability to detect and respond to command failures
  • Timing Considerations: No guarantee of precise timing when commands are executed
  • Conditional Execution: Cannot conditionally issue commands based on command responses
  • Security Restrictions: May be limited by installation security policies

Troubleshooting

IssuePossible CausesSolutions
Command not executed
  • Security authorization insufficient
  • Syntax error in command
  • Check security profiles for command authority
  • Verify command syntax is correct
Command response not visible
  • Responses go to system log, not job log
  • Command issued to wrong subsystem
  • Check SYSLOG or console logs for responses
  • Specify correct REL= parameter
JCL error on COMMAND statement
  • Missing quotes around command
  • Invalid command syntax
  • Ensure command is enclosed in single quotes
  • Check JCL syntax for COMMAND statement
Command rejected by system
  • Command not valid in current system state
  • Resource not available
  • Check system status before issuing command
  • Add prerequisite steps to ensure proper state

Debugging Tips

  • Test commands interactively at console before using in JCL
  • Monitor SYSLOG during job execution to see command responses
  • Use the TYPRUN=SCAN JOB parameter to validate JCL without executing commands
  • Add extra display commands to show system state before and after critical commands
  • Implement command verification steps that check if commands had the desired effect

JES2 vs JES3 Considerations

FeatureJES2JES3
Command PrefixTypically $ (e.g., $D I)Typically * (e.g., *I,J=jobname)
Command StructureUsually more conciseOften more verbose with commas
Command ValidationJES2 command validationJES3 command validation
Alternative Method/*$command syntax//*command syntax

Alternatives to COMMAND

  • JES2 Command Format: /*$command - alternative for JES2 commands
  • JES3 Command Format: //*command - alternative for JES3 commands
  • CNTL/ENDCNTL Statements: For more complex command sequences
  • Started Tasks: For extensive operator command sequences
  • Automation Tools: Products like CA OPS/MVS, IBM System Automation

Related Concepts