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 code optional file in JCL?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1439
Location: Bangalore,India

PostPosted: Mon Apr 02, 2007 10:20 am    Post subject: How to code optional file in JCL?
Reply with quote

Hi All,

Im using -

Code:
SELECT OPTIONAL file-name1 ASSIGN TO IP2FILE


in my cobol program (which is an IP file). Now my query is how to code IP2FILE in my job.
Back to top
View user's profile Send private message

agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 685
Location: Earth

PostPosted: Mon Apr 02, 2007 11:02 am    Post subject:
Reply with quote

Quote:
code IP2FILE in my job.
?? icon_confused.gif
Isn't that a DD name you should give?
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1439
Location: Bangalore,India

PostPosted: Mon Apr 02, 2007 11:12 am    Post subject:
Reply with quote

agkshirsagar,

Code:
//IP2FILE DD DSN=MY.SECOND.FILE,DISP=SHR


Since the file is an optional one, job should not abend whether the file is present physically or not. If I declare in job as above, obviously job abends when the file is not present.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 685
Location: Earth

PostPosted: Mon Apr 02, 2007 12:23 pm    Post subject:
Reply with quote

Are you trying to 'read' that file?
You should check status after first read, it should satisfy AT END after first read. have you checked that?
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1439
Location: Bangalore,India

PostPosted: Mon Apr 02, 2007 12:55 pm    Post subject:
Reply with quote

agkshirsagar,

Quote:
Are you trying to 'read' that file?


Yes, Im using the file for read purpose.

Quote:
check status after first read


But tell me onething...... What do you think happens for a job if a IP file is not present physically? Does it going to run successfully or going to ABEND?

Curious to see your reply for this.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 685
Location: Earth

PostPosted: Mon Apr 02, 2007 1:01 pm    Post subject:
Reply with quote

For optional files when file not present:
If opened in Input mode : AT END at first read.
If opened in I-O mode : Causes file to be created
If opened in EXTEND mode: Causes file to be created.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 685
Location: Earth

PostPosted: Mon Apr 02, 2007 1:05 pm    Post subject:
Reply with quote

What was the abend code you got?
Well, it can be realted to something else than file being delared as OPTIONAL.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1439
Location: Bangalore,India

PostPosted: Mon Apr 02, 2007 2:07 pm    Post subject:
Reply with quote

I just started the coding process (of the program and yet to code the job). Before I could code the job, I wanted to know how we code optional file in the JCL.
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Mon Apr 02, 2007 5:57 pm    Post subject:
Reply with quote

I don't understand how you expect to get an AT END on first (or any) read of a non-existent dataset.
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Mon Apr 02, 2007 8:11 pm    Post subject:
Reply with quote

Hello,

If you specify a dsn in the jcl with disp = old or shr, and the dataset does not exist you will get a jcl error saying "DATA SET NOT FOUND".

The system does not know that the file is optional - only the program does, and it will never even be executed.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1439
Location: Bangalore,India

PostPosted: Tue Apr 03, 2007 9:03 am    Post subject:
Reply with quote

Code:
If you specify a dsn in the jcl with disp = old or shr, and the dataset does not exist you will get a jcl error saying "DATA SET NOT FOUND".


I agree with Dick. Is there a way to avoid an abend? If yes, provide me an example.
Back to top
View user's profile Send private message
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Chennai

PostPosted: Tue Apr 03, 2007 11:19 am    Post subject: Re: How to code optional file in JCL?
Reply with quote

Just try

Code:
//          DISP=(MOD,CATLG,DELETE), 
//          SPACE=(CYL,(5,5),RLSE),   
//          UNIT=SYSDA,               
//          DCB=(LRECL=1800,RECFM=FB)



The job will not abend even if the data set is not present.It will create the data set if the data set is absent and use the data set if it is present.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1439
Location: Bangalore,India

PostPosted: Tue Apr 03, 2007 12:09 pm    Post subject:
Reply with quote

Muthu,

Using MOD is ok. The file gets created if the file is not present physically. This should not happen.

My requirement is to read the file if its exisiting. If its a non existent file, without abending (as well as creating) the file job should run successfully. The file status (i.e., existent or non-existent) should not change before and after the job run.

Hope Im clear with the requirement.
Back to top
View user's profile Send private message
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Chennai

PostPosted: Tue Apr 03, 2007 12:25 pm    Post subject: Re: How to code optional file in JCL?
Reply with quote

Murali,
I will put your requirement with an example.Tell me whether this is what you need.The file is FILE A and program is P1.

Code:
If file A is absent=>Create the file(FILE A) and use the file in the program(P1)
If file A is present=>Use the file(FILEA) in Program P1 and no need of create the file.

Am i correct?

Now if above is requirement ,In Program (P1) code the file(FILEA) as I-O and in JCL code the file(FILE A) with MOD parameter.

Since you code in JCL as MOD ,the file will be used if it is present and created if it is absent.

Within the program since it is I-O you can perform both read as well as write.

Let us know if this can help you,,
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Tue Apr 03, 2007 12:34 pm    Post subject:
Reply with quote

muthuvel has given you a damned good solution to your problem, and also the easiest to implement.

The only alternative I can come up with is that the optional file is always present as empty. The process that creates this optional file would need to have a delete step before creating the real file. I recommend a backup be taken after this point too.

The job that optionally reads this file should at the end of process delete the file, and then create a null version so that the dataset exists once more as empty.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1439
Location: Bangalore,India

PostPosted: Tue Apr 03, 2007 1:17 pm    Post subject:
Reply with quote

Muthu,

Please remeber Il be opening the file READ mode only (no I-0).

Quote:
If file A is present=>Use the file(FILEA) in Program P1 and no need of create the file.


Yes for the above.

Quote:
If file A is absent=>Create the file(FILE A) and use the file in the program(P1)


If file is absent, should NOT create the file and also should not abend the job.
Back to top
View user's profile Send private message
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Chennai

PostPosted: Tue Apr 03, 2007 2:13 pm    Post subject: Re: How to code optional file in JCL?
Reply with quote

Murali
Come on Man... icon_confused.gif

Opening the file in I-O is just an option,you can only read even opening it in I-O.

Quote:
If file is absent, should NOT create the file and also should not abend the job.


If there is no file,then if you want the program to run?then this is the solution,use MOD and create the file and DELETE the file in the end.

To be more specific ,Read the file if record count is zero(meaning the file is empty and created just now) then delete the file in the program else use the file as you wish
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 685
Location: Earth

PostPosted: Tue Apr 03, 2007 2:17 pm    Post subject:
Reply with quote

I never tried coding OPTIONAL file as Murali is doing but this is what manual says-
Quote:
OPTIONAL
You may specify SELECT OPTIONAL only for files opened in the input, I-O, or extend mode.

You must specify SELECT OPTIONAL for those input files that are not necessarily present each time the object program is executed.


Just asking, is there any specific business requirement or it is for Learning?
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Tue Apr 03, 2007 2:18 pm    Post subject:
Reply with quote

Quote:
If file is absent, should NOT create the file and also should not abend the job.

You have a choice, either the file is there in some manner, either by my method or muthuvel's method, or your job don't run.

A simple choice I think, unless you want to get into the depths of dynamic allocation within your program to check if the file exists, which you can do by linking into ISPF services, and then allocating it, but why waste time and resource searching out a solution that already exists.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1439
Location: Bangalore,India

PostPosted: Tue Apr 03, 2007 2:39 pm    Post subject:
Reply with quote

Quote:
specific business requirement or it is for Learning?


This is a business requirement and I had provided the situation below -

Im coding a new weekly job which kick starts at certain time on Saturday. One of IP file for this job comes from another system through FTP (and my job doesn't wait for this file). Also we had learnt during certain situations (may be because of prod problem etc...), we would not be getting this file.

In my shop files received through FTP, gets automatically deleted after one day. When contacted the batch management on this issue they rejected changing the management class for this particular file. So, we thought of using OPTIONAL file for this.
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 -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts What is the code in CLIST to enable t... jackzhang75 CLIST & REXX 1 Fri Dec 02, 2016 3:02 am
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 IDEAL - Code Retrieval yugendran CA Products 0 Fri Nov 25, 2016 3:27 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm


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