IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Using ENQ to lock VSAM files


IBM Mainframe Forums -> CICS
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
SanthoshN

New User


Joined: 13 Nov 2009
Posts: 8
Location: Chennai

PostPosted: Fri Oct 08, 2010 9:07 pm
Reply with quote

Hi,
I want to use ENQ for a VSAM file. The FCT entry is GCONB010.
I tried this inside code through a program in tranasction A:

MVC SMGENFNM,=C'GCONB010'
EXEC CICS ENQ RESOURCE(SMGENFNM) UOW NOSUSPEND


and did not end the tranasction. I was using Intertest and basically after the BASR of the ENQ command, the response code was zero.

Opening another session, with another user id, I tried to run the tranasction B, which had this code in another program
MVC SMGENFNM,=C'GCONB010'
EXEC CICS WRITE FILE(SMGENFNM) .........


And the write executed to response code zero where as I thought ENQ lock would not allow the WRITE to happen.
After some search, found out that, bascially the variable SMGENFNM only will be enqueued and not the logical FCT entry contained in the variable.

What should be my exact syntax in this case to lock the VSAM file using ENQ..?

Note:-
1) Tried EXEC CICS ENQ RESOURCE('GCONB010') UOW NOSUSPEND but got compilation error
2) The shareoption of the dataset of the FCT entry is (1,3)
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Oct 08, 2010 9:13 pm
Reply with quote

review Your understanding of the ENQ/DEQ mechanism
it is based on strict conventions and tight agreement on how to behave in order to enforce ENQ/DEQ

enq/deq is based on <tokens> which are a <logical> name assigned to the resource under attempted exclusive control

all the interested parties in the process must agree on
issuing an ENQ on an agreed toked
issuing a DEQ on the same token so that other might access the resource

like in Your example
all the interested parties must agree on
ENQ
process <whatever the process>
DEQ

if one of the partners does not abide to the convention the ship will sink !
Back to top
View user's profile Send private message
SanthoshN

New User


Joined: 13 Nov 2009
Posts: 8
Location: Chennai

PostPosted: Fri Oct 08, 2010 9:33 pm
Reply with quote

Thanks for the reply!

I am just trying to understand what you said.

My requirement is that
1) The first transaction should lock the VSAM file
2) If any other tranasaction tries to update it, it should wait if any lock is held agains the file
3) Once the first transction releases the exclusive access, the second trasnsaction should continue.

We thought ENQ/DEQ mechanism would exactly achieve this purpose. Are we wrong on this? If no, then

Quote:
issuing a DEQ on the same token so that other might access the resource

what exactly should be the token to link it with the file if it not the FCT name ? If it is the FCT name, then how exaclty I manage the syntax in the example I had given?

(Since all these programs are in one sytem only, if there is a convention, it can be followed throughout)
Quote:
it is based on strict conventions and tight agreement
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Oct 08, 2010 9:49 pm
Reply with quote

the <names> used for enq/deq are completely <arbitrary> as long as everybody agrees on using the same name for the same <resource>

in Your example transaction B did to care to use the ENQ before processing the dataset

Quote:
1) The first transaction should lock the VSAM file


the enq/deq processing is self contained nobody else is aware of it
so no locking is done ( FCP is not aware of anything )
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Oct 08, 2010 10:02 pm
Reply with quote

Hello,

If even one of the processes that update the file does not first enqueue the file-token, there will be no "lock" protection. Every participant must use the same resource and every one must issue the enq and later the deq.

If there are only 2 participants and you have complete control of the code, this might work. If there are many participants, the chance of a process not following the rules increases dramatically.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Oct 08, 2010 10:52 pm
Reply with quote

In addition, your ENQ/DEQ name should be a unique (but well known) name. It should NOT be the same name (as in your example) of the file-name. I'm surprised you didn't get an INVREQ on one (or more) of the API's, involving this name.

As has been said, all participating programs who access this file need to use the same ENQ/DEQ name and mechanism.

Otherwise, it won't work as expected.

To centralize the ENQ/DEQ naming convention, define a VSAM file (CICS SDT) or a Static Assembler table, which contains an Resource-Name (IE: A File-Name, A Program-Name, etc) and its corresponding Site-Defined RESOURCE-ID.

EG: GCONB010,RESOURCE-ID-GCONB010

If you don't find an entry for the resource you would like to ENQ on, then just continue.

However, if there is an entry, then issue a HANDLE CONDITION ENQBUSY (YOUR-LABEL-NAME) and then ENQ on the Site-Defined RESOURCE-ID.

Resource-Id's have a maximum length of 255-Bytes.

I would recommend that as soon as you're done with the ENQ'd Resource, issue a DEQ, unless you're very close to task termination, in which case, CICS will issue an implicit DEQ.

If you're not close to task termination (IE: returning to a caller), issue a HANDLE CONDITION ENQBUSY, without a label, which essentially returns control to CICS and removes this condition from your program.

One last observation. There needs to be a compelling reason to ENQ/DEQ on ANY resource as it causes Exclusive-Control/Single-Threading. You don't want to fictitiously increase task-time. Tasks should complete as fast as possible.

Most shops are still not Threadsafe, so only the QR TCB is used for delegating work. You don't want to back it up because all sorts of "opportunities" could rear their ugly head.... icon_wink.gif

Bill
Back to top
View user's profile Send private message
SanthoshN

New User


Joined: 13 Nov 2009
Posts: 8
Location: Chennai

PostPosted: Fri Oct 22, 2010 3:13 pm
Reply with quote

Thanks All for the help.

I have some queries regarding the same.
Quote:
To centralize the ENQ/DEQ naming convention, define a VSAM file (CICS SDT) or a Static Assembler table, which contains an Resource-Name (IE: A File-Name, A Program-Name, etc) and its corresponding Site-Defined RESOURCE-ID.


1) Is it possible to dynamically fetch the resource-id using any API/SPI commands?I tried looking something regarding the CEDA commands but got really confusing.

2) If it is not possbile, then we are looking to build the table the first time by getting information from the system guys. However, is it possible that every time the CICS region is refreshed, willl the resource-id be changed?

This might be my site-specific, but wanted to get your inputs.

Again thanks for the help
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CICS

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Access to non cataloged VSAM file JCL & VSAM 18
No new posts Compare only first records of the fil... SYNCSORT 7
Search our Forums:

Back to Top