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
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
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Apr 03, 2007 7:04 pm
Reply with quote

Hello,

One other option would be to run a step to "check" if the dataset was available. If it is pass one condition code, if not pass another. For example, running a LISTCAT will not abend, but will let you know if the file exists.

There is a difference (in many bits of code) between having a "READ -AT END" and not issuing the read at all. Some code "gets confused". Some apps are designed to "start fresh" periodically and are coded such that once a "period" they don't read the "old" file as it does not exist.

My personal preference is to have an "empty" file, but when working on existing (especially older) code, "ya can't always get what ya want" icon_smile.gif
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Tue Jun 12, 2007 10:52 am
Reply with quote

I had some confusion with the OPTIONAL clause, it is now clear to me so I thought of sharing with you guys-
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.

Here,'NON EXISTING' file means, DD name not present during the execution. Earlier I had thought, NON EXISTING means file which is not created or uncataloged DSN.
Following scenario will make it more clear-
Two file reading programs exactly similar except in one of the program, input file is coded as OPTIONAL.
While running program using JCL, I didn't code DD name of input file then-
Program coded without OPTIONAL clause abended with message "There was an unsuccessful OPEN or CLOSE of file" (abend at OPEN statement)
while the program coded with OPTIONAL clause did not abend, AT condition became true on first read (OPEN was successful).
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


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

PostPosted: Wed Jun 13, 2007 6:52 pm
Reply with quote

Quote:
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).

Hi,

I don't know much about the concept to use OPTIONAL file. However, for the above business situation, would like to suggest follwoing, perhaps can work for you.

Lets another system file DSN is
Code:
HLQ.FIRST.FILE.R
Now your JOB, in which you'll call your Batch/Development program (PGM1) should look like
Code:
//JOBCARD
.
.
//STEP020 EXEC PGM=IEFBR14               
//*                                       
//DDNAME  DD   DSN= HLQ.FIRST.R(+1),
//             DISP=(NEW,CATLG,DELETE),   
//             LRECL=64,                 
//             BLKSIZE=0,                 
//             RECFM=VB,                 
//             DSORG=PS,                 
//             UNIT=SYSDA,               
//             DATACLAS=STANDARD
//*
.
.
.
//STEP050 EXEC PGM=PGM1               
//STEPLIB                                       
//*
//DDNAME1 DD   DSN=HLQ.FIRST.R,
//             DISP=(OLD,DELETE,KEEP)
.
.


(You can alter DCB parametes as per your need.)

If the file from third party is present then the program PGM1 will run with that data otherwise with an empty file. As the empty-file is created by IEFBR14, READ verb used in the program must not casue an abend & based upon the EOF condition of HLQ.FIRST.R you can move RC value to some variable & can display that in SYSOUT, so that you can know ..whether today's JOB ran with empty-file or with a valid-data file.

Basicly, IEFBR14 will create an empty version of another system dataset & PGM1 will assume as if there is no activity done today by another system. Once your job is over we need to delete the the dataset, may be you would like to take backup then add one step to take backup.
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: Wed Jun 13, 2007 7:26 pm
Reply with quote

Hello,

For IEFBR14 to create an empty file, the dataset must be sms-managed. If that particular dataset is not sms-managed, IEFBR14 will only allocate space, not create a valid end-of-file.

If the file is not going to be sms-managed, you can do this by using IEBGENER which will create a valid empty dataset.

Using either approach a new GDG must be defined.
Back to top
View user's profile Send private message
Robert DeLong

New User


Joined: 18 Jun 2007
Posts: 1
Location: New Orleans

PostPosted: Wed Jun 20, 2007 11:20 pm
Reply with quote

I am posting this for future reference if someone else has this same question as I am sure that it willno longer be relevant to the original person who started this topic.

Notice that files opened for INPUT or I-O can cause an error if the file does not physically exist on the disk.

Some versions of COBOL allow you to add the reserved word OPTIONAL to a SELECT clause to prevent these errors. (See Listing 9.4.) The word OPTIONAL indicates that if the file is opened in INPUT or I-O mode, the file is created automatically if it does not exist. If your version of COBOL supports OPTIONAL, use it. Micro Focus Personal COBOL, ACUCOBOL, LPI COBOL, and VAX COBOL all support it.

TYPE: Listing 9.4. SELECT OPTIONAL.
000300
000400 ENVIRONMENT DIVISION.
000500 INPUT-OUTPUT SECTION.
000600 FILE-CONTROL.
000700 SELECT OPTIONAL PHONE-FILE
000800 ASSIGN TO "phone.dat"
000900 ORGANIZATION IS SEQUENTIAL.
001000
001100 DATA DIVISION.


Also found this at the IBM website:
http://publib.boulder.ibm.com/infocenter/pdthelp/v1r1/index.jsp?topic=/com.ibm.entcobol4.doc/rliossel.htm

SELECT clause

The SELECT clause identifies a file in the COBOL program to be associated with an external data set.

SELECT OPTIONAL
Can be specified 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. For more information, see the Enterprise COBOL Programming Guide.

file-name-1

Must be identified by an FD or SD entry in the data division. A file-name must conform to the rules for a COBOL user-defined name, must contain at least one alphabetic character, and must be unique within this program.

When file-name-1 specifies a sort or a merge file, only the ASSIGN clause can follow the SELECT clause.

If the file connector referenced by file-name-1 is an external file connector, all file-control entries in the run unit that reference this file connector must have the same specification for the OPTIONAL phrase.

Bottom line is that OPTIONAL is a reserved word and when coded into the program SELECT statement it treats that file as that, optional. If the file is not physically present when the program executes it does not cause the program to abend. If present it processes the file.
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: Thu Jun 21, 2007 12:31 am
Reply with quote

Hello and welcome to the forums,

Thanks for the additional info icon_smile.gif

d
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top