views:

99

answers:

3

First of all, here's the full source code: http://pastebin.com/5teGNrPC

I'm getting a weird COBOL Error, and I couldn't find what it means. It says Open Error (see the following screenshot: Screenshot ) (full size at http://img251.imageshack.us/img251/623/screenshotyj.png )

It doesn't occur if I first use "new file", and add a record after that.

Here's the application binary, and some log files it produced: http://www.mediafire.com/?5enhwqcvid9djnr

Many thanks,

Yvan

PS: It's Fujitsu NetCobol dialect.

+1  A: 

Perhaps the the program tries to access the file before it is created. The 'new file' option probably creates the data file with the OPEN OUTPUT statement and adding a record will succeed.

Kwebble
It indeed works if first a new file is created, and afterwards a record is added to the new file. But if I exit the app, and try to reopen the file and add a new record, it crashes with the message above.
Yvan JANSSENS
+1  A: 

The first error is probably a file status error 35, opening a file that does not exist. You should restructure your code. In a data entry program you only need the OPEN and CLOSE statements to be executed once each time. In this program the OPEN statement should be placed as near as possible to the beginning of the source code (to execute once at the beginning, as well as for readability) and the CLOSE should be just before the STOP RUN.

colemanj
+1  A: 

I would like to have a bit more information on the file I/O problem you are having. If I understand correctly, you can do the following without problem:

  • Create new file
  • Add record
  • Exit

Then if you start the program again and immediately

  • Add record

the program bombs with a "weird error".

Is it possible for you to read and display the record you wrote in the initial run? I am wondering if the prior write was successful, which in turn brings into question the integrity of the file.

I would suggest exploring the OPTIONAL keyword for SELECT and adding a FILE STATUS clause too. The file status should be checked after each I/O operation (OPEN, CLOSE, WRITE, READ etc.). The value contained in the variable associated with FILE STATUS will take you a long way toward sorting out the problem. The following table describes FILE STATUS values.

You might also want to review this tutorial on processing indexed files in COBOL.

I may not have figured out what your file I/O problem is but I do see something else that is bound to cause trouble later on!

You have used the following construct:

PERFORM Some-Paragraph
...
Some-Paragraph.
...
IF Some-Condition
   PERFORM Some-Paragraph
END-IF
.

The last PERFORM Some-Paragraph is within the scope of the paragraph itself. COBOL compilers may not flag this as an error but the behaviour is undefined. COBOL PERFORM does not conform to the CALL/RETURN semantics that you may be familiar with from other languages. What you have coded here is commonly known as as 'Logic Bomb'. A detailed description of what I am referring to can be found here.

NealB
I can read and display the record written in the initial run, but if I exit the app, the data is written (I can see it with a Hex Editor), but it cannot be read anymore.But I'm going to restructure the program, and rewrite it from scratch.Thanks for the help!Yvan
Yvan JANSSENS