Hi Dan,
Sorry, I didn't examine your code that closely. I was merely zeroing in
on the spot you complained about instead of reading the whole code from
start to finish.
You're right... you won't be able to do it in CL without changing the
way your code works. The following are facts (to the best of my knowledge:)
a) You can't delete (or CLRPFM) a file you have open.
b) CL opens a file the first time it does a RCVF.
c) CL closes a file when it gets a CPF0864 (end of file) error.
d) CL never lets you re-open a file once it's closed.
e) Although CLOF closes the OPNDBF copy, it doesn't close the open
instance created by your CL program, and therefore won't allow you to
delete/clear the file.
Therefore, the only way to make this work is to restructure your code
(or rewrite it in another language). If you take your loop that reads
the file and put it into a separate CL program, then you can have this:
First Program:
PGM
Loop1:
/* Call ReGen2<=== disable for test */
DBU qtemp/e2VaultDi$ /* test */
DltF qtemp/e2VaultDir /* test */
MonMsg CPF2105 /* File not found */ /* test */
CrtPF qtemp/e2VaultDir RcdLen(40) /* test */
cpyf qtemp/e2VaultDi$ qtemp/e2VaultDir /* test */ +
MBROPT(*add) FMTOPT(*NOCHK) /* test */
CALL YOUR-SECOND-CL-PROGRAM
Goto Loop1
EndPgm
(or replace the ugly GOTO with a DOWHILE)
Second Program:
PGM
Dclf e2VaultDir OpnId( dir )
Dcl &eof *lgl value('0')
OvrDbf e2VaultDir qtemp/e2VaultDir
ReadLoop:
Rcvf OpnID( dir )
monmsg msgid(cpf0864) exec(chgVar &Eof '1')
If (&Eof *eq '0' ) Then( Do )
/* do whatever you need to do */
Goto ReadLoop
Enddo
DltOvr e2VaultDir
EndPgm
So no special tricks are now needed in the 2nd program, since you no
longer need to try to read it more than once. When the CPF0864 comes,
the file will be closed, and then the program will end -- so no problem
with the first program deleting/clearing the file.
Then when it's called again, since it's a separate call, it'll reopen
the file and read it again.
Honestly, I would've done this to begin with rather than using the
POSDBF kludge. (I only explained how the POSDBF kludge worked because
you asked for it, it's not something I'd recommend.)
or, of course, you could rewrite it in RPG as you suggested.
Or... you could consider using a different approach entirely, like a
data queue instead of a file.
On 4/28/2010 2:34 PM, Dan wrote:
Hi Scott,
I *did* have OPNDBF in an earlier rendition of the app, but it didn't seem
to offer any improvement, so I took it out. I think the killer was not
specifying SHARE(*YES) on the OVRDBF. So, now, the POSDBF works.
However, I am still getting an error because the CPYF issues a CPF4123
("Open options ignored for shared open of member E2VAULTDIR.") three times
for type codes 2, 10, 6, and then fails on CPF2859 ("Shared open data path
not allowed.")
Also, the ReGen2 app deletes and recreates the E2VAULTDIR, and once I
restored the OPNDBF and kept the file open, the statement to delete the file
after it was opened failed. Since ReGen2 is already in production, I am
unable to change it, so this problem renders the current idea of using this
CLLE framework dead. I will have to rewrite this in RPG.
Thanks for getting me over the POSDBF hump!
- Dan
As an Amazon Associate we earn from qualifying purchases.