
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
I've been trying to WRITE a record to a relative organized file:
SELECT carMasterFile ASSIGN ".\~Files\Vehicle Master File.dat"
LOCK MODE IS MANUAL
ORGANIZATION IS RELATIVE
ACCESS MODE IS RANDOM
RELATIVE KEY IS cmfIndex
FILE STATUS IS cmfStatus.
I intentially tried to insert a record with an index/key value that's already existing in the file to check my error handling sentences.
Yet, instead of getting the expected file status 2/2 ("Duplicate key and duplicates are not allowed.") I got a file status of 2/3 ("Key not found."):
The documentation page on file status states that I should have gotten a file status of 2/2.
Why did I get a 2/3 error?
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Thank you for trying to help, @RobertSales,
I found the solution to my problem now: I forgot to set the index before writing the file:
Please pardon me for bothering!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
I think we'd need to see the whole program. With this:
$set sourceformat(free)
SELECT carMasterFile ASSIGN "File.dat"
LOCK MODE IS MANUAL
ORGANIZATION IS RELATIVE
ACCESS MODE IS RANDOM
RELATIVE KEY IS cmfIndex
FILE STATUS IS cmfStatus.
fd carMasterfile.
01 r1 pic x(20).
working-storage section.
01 cmfStatus pic xx.
01 cmfIndex binary-long.
open output carMasterFile
move 1 to cmfIndex
write r1
display cmfStatus
write r1
display cmfStatus
...I'm definitely seeing a status of 22 for the second write.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Thank you for trying to help, @RobertSales,
I found the solution to my problem now: I forgot to set the index before writing the file:
Please pardon me for bothering!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
we use this for screens in dos application in 1980...
Are there a reason to use this files today?
Better is to use isam-files (indexed) or when beginning new Projects to use directly modern databases (mssql, db2, Oracle, mysql and many others)
i am only interessed to give my experience and want also to learn things i don't now

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Absolutely agree. Personally, I wouldn't perfer to use these kind of files, either. They seem a huge waste of disk/tape space to me, and I wonder how programmers perceived these kind of files back in the 80's when memory was scarce.
Interesting fact: NTFS comes with a special feature called Sparse Files that's particularly useful when using such things as relative files.
Yet, I just plain follow my textbook teaching me COBOL here. I don't judge on the usefulness of one or the other feature. I just want to be prepared when a potential future client wants me to do some COBOL job on their machines 😉.