IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to check for an existing file


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
amalraj_ece

New User


Joined: 16 Jul 2006
Posts: 21
Location: delhi

PostPosted: Sat Mar 15, 2008 12:46 am
Reply with quote

How I could code a job to check to see if a file exists. If it does, I want to copy it to a new file. If it doesn't, I want to create an empty version of the same file.
Back to top
View user's profile Send private message
die7nadal

Active User


Joined: 23 Mar 2005
Posts: 156

PostPosted: Sat Mar 15, 2008 1:10 am
Reply with quote

Try IDCAMS command,

Code:
//STEP001 EXEC PGM=IDCAMS         
//SYSPRINT DD SYSOUT=*             
//SYSIN    DD *                   
 LISTCAT ENT('DSNAME')     
//                                 


If the RC = 4 then the file does not exist, if 0 then it exists. You can copy this file or create an empty file based on this RC.
Back to top
View user's profile Send private message
ch.prashant

New User


Joined: 16 Sep 2006
Posts: 27
Location: Hyderabad

PostPosted: Sat Mar 15, 2008 5:39 am
Reply with quote

You can find if the file exists or not then you can use condition code and create a file.

Code:

//JS0015B  EXEC  PGM=IEFBR14,COND=(4,NE,JS0015A)                       
//*********************************************************************
//*         THIS STEP RUNS IF FILE1 IS EMPTY.                           
//*PURPOSE  :  CREATES EMPTY FILES.                                     
//*********************************************************************
//DD1      DD  DSN=ECA311T.GVISIA.EDSHLL,                 
//             DISP=(,CATLG,DELETE),                                     
//             UNIT=DISK,                                               
//             SPACE=(TRK,(50,50),RLSE),                               
//             RECFM=FB,LRECL=800
Back to top
View user's profile Send private message
amalraj_ece

New User


Joined: 16 Jul 2006
Posts: 21
Location: delhi

PostPosted: Sun Mar 16, 2008 12:55 pm
Reply with quote

Creating an empty file and checking the existance of the file is fine, but hw can I code a copy step?. If the file is not existing then it will through JCL error. I'm getting problem here only

Note:
I'm trying for creating a new version of a GDG
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Sun Mar 16, 2008 1:30 pm
Reply with quote

amalraj_ece wrote:
I'm getting problem here only
Hello,

Please show the JCL used & the error message you got. Better suggestions will pour in.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sun Mar 16, 2008 1:58 pm
Reply with quote

I do not know for what reason I got interested icon_cool.gif

here is a job stream tested

Code:
****** ***************************** Top of Data **********************
000001 //ENRICO@A JOB (H001),'Z1',NOTIFY=ENRICO,
000002 //             CLASS=A,MSGCLASS=X,MSGLEVEL=(1,1)
000003 //* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
000004 //*            DSN=ENRICO.MF.JCLLIB(Z1)
000005 //* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
000006 // JCLLIB      ORDER=(ENRICO.MF.JCLLIB)
000007 //* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
000008 //*
000009 //Z       EXEC PGM=ZCLEANUP
000010 //SYSPRINT  DD SYSOUT=*
000011 //*
000012 //AMS     EXEC PGM=IDCAMS
000013 //*
000014 //NEWDS     DD DISP=(NEW,CATLG),DSN=ENRICO.MF.NEW,
000015 //             UNIT=SYSDA,
000016 //             SPACE=(CYL,(1,1)),DCB=(RECFM=FB,LRECL=80)
000017 //DUMMY     DD DUMMY,
000018 //             DCB=(RECFM=FB,LRECL=80)
000019 //*
000020 //SYSPRINT  DD SYSOUT=*
000021 //*
000022 //SYSIN     DD *
000023   PRINT INDATASET(ENRICO.MF.EXISTS) COUNT(1)
000024   IF LASTCC = 0 THEN -
000025      REPRO INDATASET(ENRICO.MF.EXISTS) OUTFILE(NEWDS)
000026   ELSE DO
000027      SET MAXCC = 0
000028      REPRO INFILE(DUMMY) OUTFILE(NEWDS)
000029   END
000030 //*
000031 //AMS2    EXEC PGM=IDCAMS
000032 //*
000033 //NEWDS     DD DISP=(NEW,CATLG),DSN=ENRICO.MF.NEW2,
000034 //             UNIT=SYSDA,
000035 //             SPACE=(CYL,(1,1)),DCB=(RECFM=FB,LRECL=80)
000036 //DUMMY     DD DUMMY,
000037 //             DCB=(RECFM=FB,LRECL=80)
000038 //*
000039 //SYSPRINT  DD SYSOUT=*
000040 //*
000041 //SYSIN     DD *
000042   PRINT INDATASET(ENRICO.MF.NXISTS) COUNT(1)
000043   IF LASTCC = 0 THEN -
000044      REPRO INDATASET(ENRICO.MF.EXISTS) OUTFILE(NEWDS)
000045   ELSE DO
000046      SET MAXCC = 0
000047      REPRO INFILE(DUMMY) OUTFILE(NEWDS)
000048   END
****** **************************** Bottom of Data ********************



edited to change involved into interested ( see eggs and bacon )
Back to top
View user's profile Send private message
amalraj_ece

New User


Joined: 16 Jul 2006
Posts: 21
Location: delhi

PostPosted: Fri Apr 04, 2008 1:45 am
Reply with quote

Hi Enrico,
Your solution is the perfect one and it is working fine for me

Thanks for your help!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top