How to execute MVS or JES2 commands in Batch

There are times where you may need to execute MVS or JES2 commands in batch using a JCL job. In this article I will show you 3 different ways of doing this.

The examples below show the JCL required to execute the MVS command D A,L and the JES2 command $D SPOOL. Naturally, you can execute any other MVS or JES2 commands other than the ones in the examples.

Method 1:

//USER01TS JOB (),'EXAMPLE',NOTIFY=&SYSUID,CLASS=A,MSGLEVEL=(1,1),
// MSGCLASS=X
//*
//MVS  COMMAND 'D A,L'
//JES  COMMAND '$D SPOOL'
//STEP1 EXEC PGM=IEFBR14
Notes:
  • For the commands to be executed you need to reply Y to the WTO message: “IEFC166D REPLY Y/N TO EXECUTE/SUPPRESS COMMAND”
  • The output from the commands is not stored in the job log

 

Method 2:

/*$VS,'D A,L'
/*$VS,'$D SPOOL'
//USER01TS JOB (),'EXAMPLE',NOTIFY=&SYSUID,CLASS=A,MSGLEVEL=(1,1),
// MSGCLASS=X
//* 
//STEP1 EXEC PGM=IEFBR14 
Notes:
  • The commands are automatically executed
  • The output from the commands is not stored in the job log

 

Method 3:

//USER01TS JOB (),'EXAMPLE',NOTIFY=&SYSUID,CLASS=A,MSGLEVEL=(1,1),
// MSGCLASS=X
//SDSF  EXEC PGM=SDSF
//ISFOUT DD SYSOUT=*
//CMDOUT DD DSN=USER01.COMMAND.OUTPUT,
//          DISP=(,CATLG,DELETE),
//          DCB=(RECFM=FBA,LRECL=133,BLKSIZE=0),
//          SPACE=(CYL,(1,1)),UNIT=SYSDA
//ISFIN  DD *
  SET CONSOLE BATCH
  SET DELAY 600
  /D A,L
  /$ D SPOOL
  PRINT FILE CMDOUT
  ULOG
  PRINT
  PRINT CLOSE
/*
// 
Notes:
  • The commands are automatically executed
  • The output from the commands is stored in CMDOUT

 

4 Comments

  1. Method 3 was very handy ! Suitable for collecting documentations (displays and command outputs) in big environments.

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.