Page 1 of 1

How do i code to check if a file exist?

PostPosted: Sun Jun 22, 2008 1:25 pm
by smilingclouds
Hi,

Im learning basics of JCL and i would like to know how to code for the following :

if file not received from external source, the file is created in the job in a step. But if the file is recd,the step will give me JCL error. So how to avoid this?
I need to have something like that job should process if a file is recd and even if its not recd.

Please help.

Re: How do i code to check if a file exist?

PostPosted: Sun Jun 22, 2008 3:30 pm
by MrSpock
Why not allocate the dataset with a DISPosition of MOD,CATLG? That way, if the dataset is missing, the job will catalog a new one, and if it already exists, then nothing else will happen.

Re: How do i code to check if a file exist?

PostPosted: Sun Jun 22, 2008 9:50 pm
by dick scherrer
Hello,

If this file is to be read into the later step and the system is not sms-managed, simply allocating the file will not create an "empty" file - it will create a file that can cause an abend when read.

If your process need to read an empty file when there is no data rec'd, i'd suggest doing as Mr Spock says using IEBGENER or SORT and a DUMMY input file. The following should do what you want when you change the dcb info to your values:
//GENR     EXEC PGM=IEBGENER                                     
//SYSUT1   DD DUMMY,DCB=(RECFM=FB,LRECL=80)                     
//SYSUT2   DD DSN=MY.TEST.EMPTY,DISP=(,CATLG),   
//            DATACLAS=DCDFAULT,SPACE=(TRK,1)                   
//SYSOUT   DD SYSOUT=*                                           
//SYSPRINT DD SYSOUT=*                                           
//SYSIN    DD DUMMY