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

How to check whether dataset exists or not


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ibmmainframesyntel

Active User


Joined: 26 Feb 2007
Posts: 126
Location: Chennai

PostPosted: Mon Feb 26, 2007 7:18 pm
Reply with quote

How to check wether dataset exists or not .

i have to execute my job.

It may contains 3 or two input file.

so, before executing the above step, I have to check wether the dataset exists or not, so that I can override my PROC according to that
either 2 or 3 input file.
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Mon Feb 26, 2007 8:07 pm
Reply with quote

Ask yourself, how would you do this in TSO (TSO, not ISPF) if you needed to? The method would be the same.
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Mon Feb 26, 2007 9:35 pm
Reply with quote

LISTDSI & SYSDSN are the methods for you.

O.
Back to top
View user's profile Send private message
deepak.vl

New User


Joined: 17 Feb 2007
Posts: 38
Location: Hyderabad

PostPosted: Mon Feb 26, 2007 11:52 pm
Reply with quote

Have a step which tries to read the dataset, for which you want to check whether it exists.
Have 2 steps after this, one to execute if the step 1 fails and other when step 1 is successful.
Control the execution of Steps 2 & 3 by using either a COND or an IF-ELSE.
Something like this...

STEP1 EXEC ..... --> (will try to read the dataset)
STEP2 EXEC ......COND=(0,EQ) --> (this will assume there are 3 datasets)
STEP3 EXEC ......COND=(0,NE) --> (this will assume there are 2 datasets)

Thanks,
Deepak
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Tue Feb 27, 2007 12:00 am
Reply with quote

Hello,

If step1 "tries to read" and the dataset does not exist, there will not be a recurn-code issued - the job will fail with a jcl error with the information that the dataset does not exist.

Please refer back to the post from superk. You need to verify existence before a step is executed with a dd statement that references the dataset which may or may not exist..
Back to top
View user's profile Send private message
deepak.vl

New User


Joined: 17 Feb 2007
Posts: 38
Location: Hyderabad

PostPosted: Tue Feb 27, 2007 12:08 am
Reply with quote

dick scherrer wrote:
Hello,

If step1 "tries to read" and the dataset does not exist, there will not be a recurn-code issued - the job will fail with a jcl error with the information that the dataset does not exist.

Please refer back to the post from superk. You need to verify existence before a step is executed with a dd statement that references the dataset which may or may not exist..


Oops!!!! you r rite Dick....
Can you please elaborate on 'verify existence before a step is executed'. How exactly can we do that.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Tue Feb 27, 2007 1:11 am
Reply with quote

Hi Deepak,

It is not elegant, but the way i used to check for a dataset (in batch) was to run an IDCAMS/LISTCAT for the dataset in question. If the LISTCAT is successful, IDCAMS sets a zero RC. If the LISTCAT fails, it is non-zero. Testing the return code would be like your suggestion above. The only real difference is that i specify the dsn to a utility and not to a DD statement.

After years of this, i decided that i would make sure the file(s) were always on the system. If there was no data, the file would only have an end-of-file and raise the AT END condition on the first read.

I liked this approach better than doing some kind of dance to use or not use a file that may or may not be cataloged.
Back to top
View user's profile Send private message
deepak.vl

New User


Joined: 17 Feb 2007
Posts: 38
Location: Hyderabad

PostPosted: Tue Feb 27, 2007 8:33 am
Reply with quote

Thanks Dick
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Tue Feb 27, 2007 9:18 am
Reply with quote

You're welcome icon_smile.gif
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Tue Feb 27, 2007 7:13 pm
Reply with quote

Sigh.

So much for trying to get someone to think through the problem and arrive at a solution for themself.

We can't keep spoon-feeding everyone, folks.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Tue Feb 27, 2007 9:11 pm
Reply with quote

Actually, my mission with that last bit of info was to "air" my preference that "checking for existence" need not be an issue if the design ensures that is an e-o-f when there is no data for the file. It is at least as easy to ensure there is an empty file as it is to check for existence and code around that (IMHO).

I agree that it would be excellent if there was a way to get folks to do some research/attempt, explain what they've researched/tried, and then post where they are stuck, Then we could help.

Answers are sometimes nice, but becoming self-sufficient is far more valuable.

We can only hope.
Back to top
View user's profile Send private message
ibmmainframesyntel

Active User


Joined: 26 Feb 2007
Posts: 126
Location: Chennai

PostPosted: Thu Mar 01, 2007 8:33 pm
Reply with quote

Code:

//SCHECK1 EXEC PGM=IDCAMS,
// COND=(4,LT)
//SYSIN DD *
LISTCAT ENTRIES('NUMGL.MIDAS.NUD.MAININD')
IF MAXCC=8 THEN SET MAXCC=4
//SYSPRINT DD SYSOUT=*
//SYSABEND DD SYSOUT=X,HOLD=YES
//*
Maxcc=04-dataset does not existing.....
Maxcc=00 dataset existing


Above jcl,we can come to to knw weather it is exixting or not.....

but my requirements is

to find the dataset in the PROC according to the symbolic parameter..

It will be like this......
Exec procname,MIDAS=ww,NUD=rr
Inside the proc
Code:

//SCHECK1 EXEC PGM=IDCAMS,
// COND=(4,LT)
//SYSIN DD *
LISTCAT ENTRIES('NUMGL.&MIDAS..&NUD..MAININD')
IF MAXCC=8 THEN SET MAXCC=4
//SYSPRINT DD SYSOUT=*
//SYSABEND DD SYSOUT=X,HOLD=YES
//*
Maxcc=04-dataset does not existing.....
Maxcc=00 dataset existing
Back to top
View user's profile Send private message
ibmmainframesyntel

Active User


Joined: 26 Feb 2007
Posts: 126
Location: Chennai

PostPosted: Thu Mar 01, 2007 8:34 pm
Reply with quote

superk wrote:
Ask yourself, how would you do this in TSO (TSO, not ISPF) if you needed to? The method would be the same.


plz explain it clearly........
Back to top
View user's profile Send private message
ibmmainframesyntel

Active User


Joined: 26 Feb 2007
Posts: 126
Location: Chennai

PostPosted: Thu Mar 01, 2007 8:43 pm
Reply with quote

hi people.........
give a good solution........
it will be more helpful for me....

can we use symbolic parameter in the control statement
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Thu Mar 01, 2007 8:47 pm
Reply with quote

ibmmainframesyntel wrote:
can we use symbolic parameter in the control statement


No. Symbolic parameters can only be used by the JCL. A program will not know how to resolve the variables.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Mar 01, 2007 8:49 pm
Reply with quote

ibmmainframesyntel wrote:
superk wrote:
Ask yourself, how would you do this in TSO (TSO, not ISPF) if you needed to? The method would be the same.
plz explain it clearly........
Finally got to reading instead of asking?
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Thu Mar 01, 2007 8:50 pm
Reply with quote

The best thing for you to do is, of course, use a PARM:

Code:

//STEPXXXX EXEC PGM=XXX,PARM='NUMGL.&MIDAS..&NUD..MAININD'


and then have the program XXX run the LISTCAT command:

Code:

LISTCAT ENTRIES('resolved entry name passed from PARM')
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Mar 01, 2007 8:51 pm
Reply with quote

ibmmainframesyntel wrote:
hi people.........
give a good solution........
it will be more helpful for me....
can we use symbolic parameter in the control statement
Give a good question, we'll be able to be more helpful for you...
Is this related to the current subject or are you starting another thread?
Back to top
View user's profile Send private message
ibmmainframesyntel

Active User


Joined: 26 Feb 2007
Posts: 126
Location: Chennai

PostPosted: Fri Mar 02, 2007 6:39 pm
Reply with quote

superk wrote:
The best thing for you to do is, of course, use a PARM:

Code:

//STEPXXXX EXEC PGM=TTT,PARM='NUMGL.&MIDAS..&NUD..MAININD'


and then have the program TTT run the LISTCAT command:

Code:

LISTCAT ENTRIES('resolved entry name passed from PARM')


please explain it clearly............

i am not getting exactly.........
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Fri Mar 02, 2007 7:33 pm
Reply with quote

Let me try to illustrate:

Let's say your job looks like this:

Code:

//MYJOB JOB (...),...                             
//*                                                     
//JS01     EXEC MYPROC,MIDAS='A',NUD='B'               
//*                                                     


and the PROC MYPROC looks like this:

Code:

//MYPROC   PROC MIDAS=,NUD=                                         
//*                                                                 
//SCHECK1  EXEC PGM=IEFBR14,PARM='NUMGL.&MIDAS..&NUD..MAININD'     
//*                                                                 


Now, sumbit the job, and look at the output in JESJCL. Notice how the variables in the JCL have been properly resolved:

Code:

XXSCHECK1  EXEC PGM=IEFBR14,PARM='NUMGL.&MIDAS..&NUD..MAININD'       
XX*                                                                   
//*                                                                   
IEFC653I SUBSTITUTION JCL - PGM=IEFBR14,PARM='NUMGL.A.B.MAININD'


So, whatever program/utility you choose to use in STEP SCHECK1 will receive the proper value via the PARM statement.

Unless you see that "IEFC653I SUBSTITUTION JCL" message, then the variables are not being resolved by the Internal Reader.
Back to top
View user's profile Send private message
ibmmainframesyntel

Active User


Joined: 26 Feb 2007
Posts: 126
Location: Chennai

PostPosted: Thu Mar 08, 2007 8:34 pm
Reply with quote

In the PROC

//MYPROC PROC MIDAS=,NUD=
//*
//SCHECK1 EXEC PGM=IEFBR14,PARM='NUMGL.&MIDAS..&NUD..MAININD'
//*

using IEFBR14,what u are doing?

After this if the dataset is not found what it will be?

weather it will be JCLERROR or RC=08

let me knw

thank you
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Thu Mar 08, 2007 9:26 pm
Reply with quote

Hello,

IEFBR14 is just an example in this case to demonstrate the symbolic parameter substitution. Instead of IEFBR14 you would use your own program (TTT to continue the example above).

From the dataset name constructed from the constants and the variables, create the LISTCAT control statement shown above.

When you execute the IDCAMS step, you will get a return code not a JCL error.
Back to top
View user's profile Send private message
ibmmainframesyntel

Active User


Joined: 26 Feb 2007
Posts: 126
Location: Chennai

PostPosted: Fri Mar 09, 2007 10:12 am
Reply with quote

Ok..

hw to mention the the listcat entries...

LISTCAT ENTRIES('resolved entry name passed from PARM')


I don't knw...

pls tell me....

the output of the program will have the expanded dataset name
by substituting the symbolic parameters..

that i got itt.

but hw i mention the output in LISTCAT(' ')

let me knw...
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Fri Mar 09, 2007 10:26 am
Reply with quote

Hello,

In your program that recieves the parm info, define an output file with a length of 80. In the jcl for running the program inclulde a DD statement for this file and it will have DISP=(,CATLG,DELETE). Place this output file on dasd and use it as input to a following IDCAMS step.

In your working-storage create an 01 LISTCAT-CTL that has fillers set up with the constant LISTCAT control info. In that same 01, declare a field where you will move the complete dsn.

Once you have the control statement in working-storage, write the 80-byte output record from that LISTCAT control statement.

Good luck and let us know if you would like anyh other info.
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 -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts batch SFTP job using AOPBATCH unable ... All Other Mainframe Topics 7
No new posts Using Multiple IFTHEN and WHEN condit... SYNCSORT 12
No new posts Check if CICS is online in JCL CICS 10
No new posts Reading Empty Dataset DFSORT/ICETOOL 5
No new posts Mainframe Dataset Binary or ASCII Mainframe Interview Questions 4
Search our Forums:

Back to Top