Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to check for an existing file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
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    Post subject: How to check for an existing file
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    Post subject:
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    Post subject:
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    Post subject:
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

Senior Member


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

PostPosted: Sun Mar 16, 2008 1:30 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10211
Location: italy

PostPosted: Sun Mar 16, 2008 1:58 pm    Post subject: Reply to: How to check for an existing file
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    Post subject: Thanks Enrico
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    IBMMAINFRAMES.com Support Forums -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORTJOIN - Copy Matched and Unmatched... Steve Ironmonger DFSORT/ICETOOL 5 Tue Jan 17, 2017 4:26 pm
No new posts Copy RECFM =VB TO FB file with RECL =... sahil41352 DFSORT/ICETOOL 3 Wed Dec 28, 2016 11:29 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 7 Fri Nov 18, 2016 1:48 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us