Highlighted
Absent Member.
Absent Member.
3642 views

Locks in RM/COBOL files using Visual COBOL .NET

Jump to solution

[Migrated content. Thread originally posted on 18 October 2011]

Hello,

I am testing the lock behaviour on Visual COBOL .NET, using RM/COBOL indexed files, so I have written a small program that has two options: read a register and unlock it.

For my purpouses, I found that LOCK MODE AUTOMATIC fits the bill, but I haven't found a way reproduce the normal behaviour in RM/COBOL when I try to access the same row from two diferent programs at the same time. In RM, when I try to do that, one of the programs (the last who is accessing) stays waiting until the row has been released. How can I reproduce this in Visual COBOL?

I have tried with the EXTFH file, like follows:

[XFH-DEFAULT]
LOCKTYPE = 1


Regards
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Locks in RM/COBOL files using Visual COBOL .NET

Jump to solution
Chris Glazier originally wrote:
The reason that you are getting a status 47 on the read is that the open is actually failing with a 9/161 but you are not checking the status
.


I know, and I find that odd. I was expecting a program crash after an unsuccesful open.


The reason that the program does not stop automatically after a bad open is that you do have a file status defined for the file so it is assumed that your code logic will check this file status value and handle the exception itself.

If you had not actually defined a file status in the select statement then a RTS error would have occured reporting the error on the open.

View solution in original post

0 Likes
12 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Locks in RM/COBOL files using Visual COBOL .NET

Jump to solution
Use the following option in the file handler configuration file:

[XFH-DEFAULT]
RETRYLOCK=ON

This is defined as follows:

Retry the operation until no lock is encountered

So instead of immediately returning with a locked record file status it will continue to attempt the read until the record is unlocked.

You can control this further by instead using:

[XFH-DEFAULT]
RETRYLOCK=

integer: Specify the number of attempts or the number of seconds for which you wish to retry the operation before a locked record status is returned. The RETRYTIME option controls the meaning of integer; for more information see the topic RETRYTIME.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Locks in RM/COBOL files using Visual COBOL .NET

Jump to solution
Hello,

I've tried with the solution you provided me, but with no results at all. The program keeps on with its previous behaviour:

Press me to see the image
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Locks in RM/COBOL files using Visual COBOL .NET

Jump to solution
I am sorry, you mentioned that you are using the RM file handler not the Micro Focus File Handler.
The extfh.cfg file entries do not apply to the RM or ACU Vision file handlers.

They are only applicable when using the default Visual COBOL file handler which is the Micro Focus External file handler.

You will need to provide an equivalent RM configuration file in order to set options in the RM file handler.
I am not familiar with the RM file handler configuration so I am asking one of the RM engineers to take a look at this.

Thanks.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Locks in RM/COBOL files using Visual COBOL .NET

Jump to solution
I find that if I use the RM directive in addition to the CALLFH("ACUFH") directive to compile the program then the default locking takes place as in RM COBOL.

That is if a locked record is attempted to be read in a second program it will automatically wait until the record is released by the program holding the lock.

You can also use the RETRYLOCK directive instead of the RM directive if you only wanted to turn on this locking behavior without changing other behavior.

I think that this is what you are looking for...
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Locks in RM/COBOL files using Visual COBOL .NET

Jump to solution
I am sorry, but one of the first things I tried was the RM directive. If I use it, I cannot access any indexed file created with an RM/COBOL program. Therefore, I could take a crack at the RETRYLOCK directive, but you said that this file configuration does not work with RM and Acucobol files and, in fact, it has no effect in my program.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Locks in RM/COBOL files using Visual COBOL .NET

Jump to solution
RETRYLOCK is also a compiler directive as well as a file handler configuration option.
If you compile your program using $SET RETRYLOCK then you will get the behavior you are seeking.

Can you elaborate on your statement
"If I use it, I cannot access any indexed file created with an RM/COBOL program."?

What exactly happens if you use the RM directive and try to access a RM file?

This is definately supported and I tried it here and it did work as expected.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Locks in RM/COBOL files using Visual COBOL .NET

Jump to solution
If I include the RM directive, status 47 is reported when reading a row.

Here you can download my project, if you want to: TestLocks

The file which the project is working with must be located in path c:\mango\ficheros. You can download it here: fich003v4

In order to get the project working, you must remove "RM" from Project->Properties->COBOL->Additional directives


By the way, I've gave a try with the $SET RETRYLOCK directive, and it works fine. 🙂

Thanks
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Locks in RM/COBOL files using Visual COBOL .NET

Jump to solution
The reason that you are getting a status 47 on the read is that the open is actually failing with a 9/161 but you are not checking the status.

You have:
open i-o fich003.
if error-in-file then
go end-of-program
end-if.

but error-in-file will only be set on in the declaratives which you currently have commented out.

The reason that the 9/161 is returned on the open is because there is a record size conflict because the program definition and the file on disk.

The size conflict is occurring because the record has signed numeric display data and using the RM directive causes the system to behave as if you had specified the following syntax:

sign trailing separate

which allocates an additional byte of storage in the record description.

To get around this set RM"ANSI" instead.

I tried it here and all works fine.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Locks in RM/COBOL files using Visual COBOL .NET

Jump to solution
Chris Glazier originally wrote:
The reason that you are getting a status 47 on the read is that the open is actually failing with a 9/161 but you are not checking the status.


I know, and I find that odd. I was expecting a program crash after an unsuccesful open.


Chris Glazier originally wrote:
The reason that the 9/161 is returned on the open is because there is a record size conflict because the program definition and the file on disk.

The size conflict is occurring because the record has signed numeric display data and using the RM directive causes the system to behave as if you had specified the following syntax:

sign trailing separate

which allocates an additional byte of storage in the record description.

To get around this set RM"ANSI" instead.

I tried it here and all works fine.


And it works fine for me, too. Thanks a lot for your help. 🙂
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Locks in RM/COBOL files using Visual COBOL .NET

Jump to solution
By the way, do you know the meaning of the error 9/043 (extended file status 043)? I am obtaining this error after trying to open a file converted from file version 0 to file version 4, using rmdefinx in RM/COBOL 9.01 (Windows XP).

I didn't find any explanation for this error on the web.

I found later that I must set the directives:

$SET CALLFH("ACUFH")
$SET RETRYLOCK
$SET RM"ANSI"

... in all the programs which are accessing RM files. I imagine this error is regarding the compatibility mode that has not been set.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Locks in RM/COBOL files using Visual COBOL .NET

Jump to solution
Chris Glazier originally wrote:
The reason that you are getting a status 47 on the read is that the open is actually failing with a 9/161 but you are not checking the status
.


I know, and I find that odd. I was expecting a program crash after an unsuccesful open.


The reason that the program does not stop automatically after a bad open is that you do have a file status defined for the file so it is assumed that your code logic will check this file status value and handle the exception itself.

If you had not actually defined a file status in the select statement then a RTS error would have occured reporting the error on the open.

View solution in original post

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.