1

In the following JCL, the HFS path /u/woodsmn/jjk does not exist. It raises a JCL error and does not run the COPYHFS step, nor any other steps. I want it to detect the missing file, and run the FAILIND step.

I suspect MVS raises a JCL error and completely ignores any COND conditions that might apply. I was hoping it raise some failure step condition code and behave that way.

How can I re-write this to execute steps when a PATH does not exist?

//WOODSMN1 JOB (1111),MSGLEVEL=(1,1),CLASS=A,MSGCLASS=H,       
//  USER=WOODSMN,REGION=1M                                     
//COPYHFS EXEC PGM=IKJEFT01                                    
//INHFS  DD PATH='/u/woodsmn/jjk',                             
//          PATHOPTS=(ORDONLY),RECFM=VB,LRECL=255,BLKSIZE=32760
//OUTMVS DD DSN=WOODSMN.TESTDS1,                               
//          DISP=(NEW,CATLG,DELETE),                           
//          SPACE=(TRK,(1,1)),                                 
//          DCB=(LRECL=80,RECFM=FB,BLKSIZE=8080)               
//SYSTSPRT DD SYSOUT=*                                         
//SYSTSIN  DD *                                                
OCOPY INDD(INHFS) OUTDD(OUTMVS) CONVERT(NO)                    
/*                                                             
//*                                                            
//NETVIEW EXEC PGM=IEFBR14,COND=(0,EQ,COPYHFS)                 
//*                                                            
//SUCCIND EXEC PGM=IEBGENER,REGION=1M,COND=(0,EQ,NETVIEW)  
//SYSPRINT DD SYSOUT=*                                     
//SYSUT1 DD *                                              
Attempt to put file succeeded                              
/*                                                         
//SYSUT2 DD PATHOPTS=(ORDWR,OTRUNC,OCREAT),PATHMODE=SIRWXU,
//  PATHDISP=(KEEP,DELETE),                                
//  PATH='/u/woodsmn/TESTDS.SUCCESS'                       
//SYSIN DD DUMMY                                           
//*                                                        
//FAILIND EXEC PGM=IEBGENER,REGION=1M,COND=(0,GT,NETVIEW)  
//SYSPRINT DD SYSOUT=*                                     
//SYSUT1 DD *                                              
Attempt to put file failed                                 
/*                                                         
//SYSUT2 DD PATHOPTS=(ORDWR,OTRUNC,OCREAT),PATHMODE=SIRWXU,
//  PATHDISP=(KEEP,DELETE),                                
//  PATH='/u/woodsmn/TESTDS.FAIL'                          
//SYSIN DD DUMMY                                           
//
Woodsman
  • 901
  • 21
  • 61
  • 1
    If all you want to do is test if a dataset exists use a utility and check the return code. You can not check if a dataset exist in JCL. For MVS Datasetsyou could use idcams. From memory with in JES3 you get a JCL error before the job starts. In JES2 the job fails at the start of the step. Can you tell us which version of JES you are using – Bruce Martin Jun 13 '21 at 07:55

2 Answers2

2

Use BPXBATCH to execute a shell command to test the existence of your directory.

//EXIST001 EXEC PGM=BPXBATCH,PARM='SH test -e /u/woodsmn/jjk'
//STDOUT   DD  SYSOUT=*
//STDERR   DD  SYSOUT=*

You may have to get a bit more exotic and use the STDPARM DD to pass a `set -o errexit' to get the return code to work exactly as you wish.

cschneid
  • 10,237
  • 1
  • 28
  • 39
  • Thanks to both of you for your thoughtful answers. The reason for the dataset check is because, in part, I want to make sure the Netview step completes. I don't know how to get condition codes back into USS. – Woodsman Jun 13 '21 at 18:05
  • I also want to copy the HFS file into an MVS dataset. Am I better off doing it in a script somehow? – Woodsman Jun 13 '21 at 20:12
  • 1
    @Woodsman depending on your environment and what your overall goal is, you might be better off doing the whole thing in a script. Different IT shops have different rules. There are many inputs into what constitutes what is considered best in a given context. – cschneid Jun 13 '21 at 23:17
  • 1
    You can also use `test` to check for the presence of a classic data set, I've found this very useful. `'SH test -e //''MYTSOID.SOME.DATA.SET'''` – zarchasmpgmr Jun 15 '21 at 00:09
1

Two things to change:

Firstly, run IKJEFT1B instead of IKJEFT01, because the former will end when a command in SYSTSIN ends with a non-zero returncode, and that return code will become the step return code.

Secondly, allocate the z/OS UNIX file with the ALLOC command just before the OCOPY. ALLOC will return with RC=12 if it cannot allocate the file (for whatever reason).

So, your first step should look like this:

//COPYHFS  EXEC PGM=IKJEFT1B                                    
//OUTMVS   DD DSN=WOODSMN.TESTDS1,                               
//            DISP=(NEW,CATLG,DELETE),                           
//            SPACE=(TRK,(1,1)),                                 
//            DCB=(LRECL=80,RECFM=FB,BLKSIZE=8080)               
//SYSTSPRT DD SYSOUT=*                                         
//SYSTSIN  DD *                                                
  ALLOC F(INHFS) PATH('/u/woodsmn/jjk') -                               
        PATHOPTS(ORDONLY) RECFM(V B) LRECL(255) BLKSIZE(32760)

  OCOPY INDD(INHFS) OUTDD(OUTMVS) CONVERT(NO)                    
/*                                            

You can then test the return code from the COPYHFS step as usual. (And btw, you don't need that NETVIEW step, but instead test the return code from the COPYHFS step directly.)

IKJEFT1B, as well as IKJEFT01, and the third variation IKJEFT1Aare described in Appendix A. Executing the terminal monitor program in the manual z/OS TSO/E Customization.

phunsoft
  • 2,674
  • 1
  • 11
  • 22
  • I liked your solution too, but I already went with BPXBATCH. I wish I could mark both as valid answers. – Woodsman Jun 15 '21 at 02:24