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
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.