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
 

 

Optional clause in COBOL file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 216
Location: India

PostPosted: Wed Dec 31, 2008 4:17 pm    Post subject: Optional clause in COBOL file
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 : http://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: Chennai

PostPosted: Wed Dec 31, 2008 4:46 pm    Post subject:
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: 216
Location: India

PostPosted: Wed Dec 31, 2008 5:08 pm    Post subject:
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: 8593
Location: Back in jolly old England

PostPosted: Wed Dec 31, 2008 5:16 pm    Post subject:
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: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Wed Dec 31, 2008 5:35 pm    Post subject:
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: 216
Location: India

PostPosted: Fri Jan 02, 2009 6:38 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10256
Location: italy

PostPosted: Fri Jan 02, 2009 6:43 pm    Post subject: Reply to: Optional clause in COBOL file
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: 2150
Location: At my coffee table

PostPosted: Fri Jan 02, 2009 6:47 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Issue with NDM process to transmit ES... chetanambi All Other Mainframe Topics 6 Wed May 03, 2017 10:52 am


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