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

How to code optional file in JCL?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
murmohk1

Senior Member


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

PostPosted: Mon Apr 02, 2007 10:20 am
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: 691
Location: Earth

PostPosted: Mon Apr 02, 2007 11:02 am
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: 1436
Location: Bangalore,India

PostPosted: Mon Apr 02, 2007 11:12 am
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: 691
Location: Earth

PostPosted: Mon Apr 02, 2007 12:23 pm
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: 1436
Location: Bangalore,India

PostPosted: Mon Apr 02, 2007 12:55 pm
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: 691
Location: Earth

PostPosted: Mon Apr 02, 2007 1:01 pm
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: 691
Location: Earth

PostPosted: Mon Apr 02, 2007 1:05 pm
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: 1436
Location: Bangalore,India

PostPosted: Mon Apr 02, 2007 2:07 pm
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

Senior Member


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

PostPosted: Mon Apr 02, 2007 5:57 pm
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

Moderator Emeritus


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

PostPosted: Mon Apr 02, 2007 8:11 pm
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: 1436
Location: Bangalore,India

PostPosted: Tue Apr 03, 2007 9:03 am
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: Canada

PostPosted: Tue Apr 03, 2007 11:19 am
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: 1436
Location: Bangalore,India

PostPosted: Tue Apr 03, 2007 12:09 pm
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: Canada

PostPosted: Tue Apr 03, 2007 12:25 pm
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: 8797
Location: Welsh Wales

PostPosted: Tue Apr 03, 2007 12:34 pm
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: 1436
Location: Bangalore,India

PostPosted: Tue Apr 03, 2007 1:17 pm
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: Canada

PostPosted: Tue Apr 03, 2007 2:13 pm
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: 691
Location: Earth

PostPosted: Tue Apr 03, 2007 2:17 pm
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: 8797
Location: Welsh Wales

PostPosted: Tue Apr 03, 2007 2:18 pm
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: 1436
Location: Bangalore,India

PostPosted: Tue Apr 03, 2007 2:39 pm
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
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Apr 03, 2007 2:43 pm
Reply with quote

What happens when a file is missed. Does it get accumulated and fed into the next run or is it just ignored ?
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Tue Apr 03, 2007 2:51 pm
Reply with quote

Are you checking the file has come or not before starting your job.
If you have got no file, then make it dummy, else the file you've got!
Tell me if I am getting diverted from the problem? icon_confused.gif
Back to top
View user's profile Send private message
murmohk1

Senior Member


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

PostPosted: Tue Apr 03, 2007 2:59 pm
Reply with quote

Quote:
is it just ignored


Will receive the current data along with next week data.

Quote:
Are you checking the file has come or not before starting your job.

We are not verifying the file. That is the reason I had asked for optional file.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Apr 03, 2007 3:11 pm
Reply with quote

What about two versions of your program in one job, one with the optional file and one without, using IDCAMS to check in the first step if the file exists or not.
Code:

//VERIFY   EXEC PGM=IDCAMS                           
//SYSPRINT DD SYSOUT=*                               
//SYSIN    DD *                                     
 VERIFY DATASET('my dataset name')         
 IF MAXCC EQ 12 THEN SET MAXCC EQ 2                 
/*
//WITHFILE EXEC whatever,COND=(2,EQ,VERIFY)
//WITHOUT  EXEC whatever,COND=(0,EQ,VERIFY)
Back to top
View user's profile Send private message
murmohk1

Senior Member


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

PostPosted: Tue Apr 03, 2007 3:21 pm
Reply with quote

I have a two more weeks before I actually start testing the program/job. If I get the solution (by chance) before, Il use optional file else use one of the solution provided by you people.
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 -> COBOL Programming Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts run rexx code with jcl CLIST & REXX 15
No new posts Compile rexx code with jcl CLIST & REXX 6
No new posts Access to non cataloged VSAM file JCL & VSAM 18
Search our Forums:

Back to Top