View previous topic :: View next topic
|
Author |
Message |
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Quote: |
code IP2FILE in my job. |
??
Isn't that a DD name you should give? |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
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 |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
What was the abend code you got?
Well, it can be realted to something else than file being delared as OPTIONAL. |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1041 Location: Richmond, Virginia
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
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 |
|
|
muthuvel
Active User
Joined: 29 Nov 2005 Posts: 217 Location: Canada
|
|
|
|
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 |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
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 |
|
|
muthuvel
Active User
Joined: 29 Nov 2005 Posts: 217 Location: Canada
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
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 |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
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 |
|
|
muthuvel
Active User
Joined: 29 Nov 2005 Posts: 217 Location: Canada
|
|
|
|
Murali
Come on Man...
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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
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 |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
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? |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
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 |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
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 |
|
|
|