How do i code to check if a file exist?



JES, JES2, JCL utilities, IDCAMS, Compile & Run JCLs, PROCs etc...

How do i code to check if a file exist?

Postby smilingclouds » Sun Jun 22, 2008 1:25 pm

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.
smilingclouds
 
Posts: 1
Joined: Sun Jun 22, 2008 1:02 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby MrSpock » Sun Jun 22, 2008 3:30 pm

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.
User avatar
MrSpock
Global moderator
 
Posts: 809
Joined: Wed Jun 06, 2007 9:37 pm
Location: Raleigh NC USA
Has thanked: 0 time
Been thanked: 4 times

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

Postby dick scherrer » Sun Jun 22, 2008 9:50 pm

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           
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to JCL

 


  • Related topics
    Replies
    Views
    Last post