Highlighted
Super Contributor.
Super Contributor.
108 views

Why do I get status 2/3 when inserting a duplicate record?

Jump to solution

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."):

Strange file status.png

Record details.pngRelative file contents.png

 

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?

 

 

 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Super Contributor.
Super Contributor.

Re: Why do I get status 2/3 when inserting a duplicate record?

Jump to solution

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:

Set index to relative file.png

Please pardon me for bothering!

View solution in original post

0 Likes
4 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Why do I get status 2/3 when inserting a duplicate record?

Jump to solution

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.

0 Likes
Highlighted
Super Contributor.
Super Contributor.

Re: Why do I get status 2/3 when inserting a duplicate record?

Jump to solution

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:

Set index to relative file.png

Please pardon me for bothering!

View solution in original post

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: Why do I get status 2/3 when inserting a duplicate record?

Jump to solution
What is the reason to use relative files?
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
0 Likes
Highlighted
Super Contributor.
Super Contributor.

Re: Why do I get status 2/3 when inserting a duplicate record?

Jump to solution

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

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.