Can we handle file not found exception in cobol program?



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Can we handle file not found exception in cobol program?

Postby arya_starc » Thu Feb 02, 2017 12:36 am

Hi All

Suppose some file is not given in the dd name of the jcl, in that case can we handle the error in the cobol program during run time execution of the program.
arya_starc
 
Posts: 136
Joined: Mon Sep 21, 2015 1:39 pm
Has thanked: 5 times
Been thanked: 0 time

Re: Can we handle file not found exception in cobol program?

Postby Robert Sample » Thu Feb 02, 2017 1:24 am

It depends -- look at the SELECT OPTIONAL clause in the Enterprise COBOL Language Reference manual for your version of COBOL. SELECT OPTIONAL is only valid for INPUT, I-O, EXTEND open modes and may set a file status code of 05; you will get a file status code such as 35 for other file open modes.

Note that some of these errors are trapped by the converter / interpreter which processes the JCL long before the program can execute, so again whether or not what you want to do can be done will depend.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Can we handle file not found exception in cobol program?

Postby Aki88 » Thu Feb 02, 2017 11:45 am

Hello,

arya_starc wrote:...Suppose some file is not given in the dd name of the jcl...


I find this statement tad bit confusing. Generally, imo, application programmers, when they know that a situation may arise that a certain DD statement can be skipped - either use 'SELECT OPTIONAL' as Mr. Sample has stated, or they code a mechanism to handle it.
Handling can be in the form of:
a. OPEN/READ/WRITE the DS only if a certain flag is present, this flag in turn can be set basis the conditions that identify if the DS in question is to be present for this run or not.
b. Identify the file-status returned (as stated by Mr. Sample) and then reset it to '0' or handle it. One needs to understand that 'handle' here has its own caveat.

Note that a COBOL program will not abend unless you want it to abend or code an abend routine; though it will set a return code basis the file-access and the code execution flow, which in turn is left to the programmer's discretion to be catered to.
Aki88
 
Posts: 381
Joined: Tue Jan 28, 2014 1:52 pm
Has thanked: 33 times
Been thanked: 36 times

Re: Can we handle file not found exception in cobol program?

Postby Terry Heinze » Thu Feb 02, 2017 8:28 pm

Another reason for "file not found" can be missing or misspelled DD which will result in a file status of 96.
.... Terry
Terry Heinze
 
Posts: 239
Joined: Wed Dec 04, 2013 11:08 pm
Location: Richfield, MN, USA
Has thanked: 12 times
Been thanked: 11 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post