Page 1 of 1

Can we handle file not found exception in cobol program?

PostPosted: Thu Feb 02, 2017 12:36 am
by arya_starc
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.

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

PostPosted: Thu Feb 02, 2017 1:24 am
by Robert Sample
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.

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

PostPosted: Thu Feb 02, 2017 11:45 am
by Aki88
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.

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

PostPosted: Thu Feb 02, 2017 8:28 pm
by Terry Heinze
Another reason for "file not found" can be missing or misspelled DD which will result in a file status of 96.