开发者

cobol Open-IO: create file if it doesn't exist

Does anyone have an idea how you can catch the exception that cobol throws if you try开发者_开发百科 to open an IO file if it doesn't exist, and then create a new file?


The OPTIONAL phrase on the SELECT cause will do this:

SELECT OPTIONAL FILE-A 
   ASSIGN TO "INFILE" 
   ORGANIZATION INDEXED. 

If OPEN IO the file will be created if necessary. For OPEN INPUT, the file not be created but treated as being at EOF and all random reads will be "INVALID KEY".

I'm pretty sure this is an ANSI standard clause, but can't remember when it showed up.


I don't know what version of Cobol you use or what platform you use it on. My program checks first to see if the file exists before it tries to open it. I use Unisys Cobol 85 on the MCP mainframe platform. The messages are lame, but who cares?

Here is a snippet from a job that runs daily:

968545     IF  ATTRIBUTE RESIDENT OF OU3-WORK-LIST-FILE = VALUE TRUE  
968550         DISPLAY "PROGRAM SHOWS ATTRIBUTE TRUE"                 
968555         OPEN EXTEND OU3-WORK-LIST-FILE                         
968560     ELSE                                                       
968565         DISPLAY "PROGRAM SHOWS FALSE"                          
968570         OPEN OUTPUT OU3-WORK-LIST-FILE                         
968575     END-IF.                                                    
968580                                    

Cathy

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜