Bjorn Behr wrote:
Morning All
We are running on UV 10.2.11 and have encountered an error.
Scenario:
PROGRAM MAIN_PROG
OPEN "FILE" TO FILE ELSE STOP 201,"FILE"
CALL READ_PROG
CRT "YOU SHOULD BE HERE...":
INPUT X
RELEASE FILE, "TESTER"
PROGRAM READ_PROG (A)
OPEN "FILE" TO FILE ELSE STOP 201,"FILE"
READU REC FROM FILE, "TESTER" ELSE REC = ""
REC<1> = 1
WRITEU REC ON FILE, "TESTER"
RETURN
PROGRAM READ_PROG (B)
OPEN "FILE" TO FILE ELSE STOP 201,"FILE"
READU REC FROM FILE, "TESTER" ELSE REC = ""
RETURN
With both Program (A) and (B) when READ_PROG returns to MAIN_PROG it releases
the Record Lock before the release.
Has anybody else encountered this, is there a way to fix it (Work Around /
Setting etc...)
I don't know if I'd call that an "error".
You're calling programs and not passing them open file pointers. So,
you open the file within the called routine, readu the record, and
return. When you return, you're EXITING the called routine and it has
nothing to keep the file open, so it releases the lock when it closes
the file.
If you want the lock to persist, you need to open the file within the
main routine, pass the pointer, (either in subroutine list or in
common), and use the pointer within the called routine.
Sample code follows (just typed, not tested):
PROGRAM MAIN
OPEN "", "XYZ" TO XYZ.FILE ELSE STOP
CRT "XYZ OPENED, IN MAIN NOW, CALLING SUBR ABC"
CALL ABC(XYZ.FILE)
CRT "BACK IN MAIN; CHECK THE LOCKS AND ENTER SOMETHING: ":
INPUT DUMMY
STOP
ABC (XYZ.FILE)
CRT "IN SUBROUTINE 'ABC'"
READU XYZ.REC FROM XYZ.FILE, "XYZ" THEN
CRT "GOT LOCK IN SUBR"
END ELSE
CRT "NO SUCH RECORD"
END
CRT "READY TO RETURN, CHECK LOCK, THEN PRESS RETURN: ":
INPUT DUMMY
RETURN
--
Allen Egerton
aegerton at pobox dot com
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/