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

Optional clause in COBOL file


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

Active User


Joined: 31 Aug 2006
Posts: 218
Location: India

PostPosted: Wed Dec 31, 2008 4:17 pm
Reply with quote

Can anyone provide the scenario where we code OPTIONAL clause in cobol and what is it's importance.

I have referd this post : www.ibmmainframes.com/viewtopic.php?t=19532&postdays=0&postorder=asc&start=15

But i did get the clear picture of OPTIONAL clause.

Can any one throw some light on this.
Back to top
View user's profile Send private message
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Canada

PostPosted: Wed Dec 31, 2008 4:46 pm
Reply with quote

I guess below part of the text in the linked post by Rob explains much clear of OPTIONAL clause.

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


It can be used based on requirements.
Back to top
View user's profile Send private message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 218
Location: India

PostPosted: Wed Dec 31, 2008 5:08 pm
Reply with quote

muthuvel wrote:
I guess below part of the text in the linked post by Rob explains much clear of OPTIONAL clause.

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


It can be used based on requirements.


Muthuvel Thanks for the reply.
Do you mean that if we code the file in JCL which does not exist, the program will not abend if we use OPTIONAL.
Back to top
View user's profile Send private message
expat

Global Moderator


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

PostPosted: Wed Dec 31, 2008 5:16 pm
Reply with quote

Why not try and see what happens.

I believe that if the dataset is coded in the JCL and the dataset does not exist ...........................
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Dec 31, 2008 5:35 pm
Reply with quote

The use of OPTIONAL applies to files in COBOL which may or may not be used by the program; its use says absolutely nothing about whether or not the file referenced by the DD statement exists. If your JCL references a file that does not exist, depending on the DISP the file will be created or the job will be flushed -- totally independently of whether or not the COBOL program actually uses the file.
Back to top
View user's profile Send private message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 218
Location: India

PostPosted: Fri Jan 02, 2009 6:38 pm
Reply with quote

expat wrote:
Why not try and see what happens.

I believe that if the dataset is coded in the JCL and the dataset does not exist ...........................


Hi expact i have tried it.
I have coded the optional clause in the program and in the JCL i have given a file which does not exist as Disp=shr.
Then i got JCL Error .

Then i have added the all the parametser for teh creation of the file in the JCL.
Now the program went fine.New input file was created and program went fine as it goes for an EMPTY file.

But program behaved in the same manner even i did not specify OPTIONAL.

That is the reason i raised this question
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Jan 02, 2009 6:43 pm
Reply with quote

the issue is not about the file existing/being present ( tht' s taken care by jcl )

but about the DDNAME being there or not

flow...

file without OPTIONAL....
jcl error if file not there ( for disp=shr ) and DDNAME present
cobol abend if DDNAME not there

file with OPTIONAL
cl error if file not there ( for disp=shr ) and DDNAME present
cobol processing by manual if DDNAME not there
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Jan 02, 2009 6:47 pm
Reply with quote

Try the OPTIONAL in the program without defining the file in the JCL...
IIRC, if defined in the JCL, the system tries to enqueue the dataset and if it doesn't exist, the JCL will fail....
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

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 1
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top