CPF4205 – Shared open not allowed for query

2505 pts.
Tags:
As400 Opnqryf command
I have an opnqryf in my CL program and I close the file and the ovrdbf. I call a second CL program where I again do an Opnqryf, but this time it throws error CPF4205 - Shared open not allowed for query. What can be the reason? There is an RPG program being called in the first CL, but I am coming out of the program with LR set to ON. Please help me with your suggestions Code DCLF File(XXX) OvrDbf File(xxxx) ToFile(*LIBL/xxxx) SHARE(*YES) OpnQryF File((xxxx) QrySlt('Fld1 *EQ "3"') read the file here Call RPG program Clof Opnid(XXX) DltOvr File(XXX) Call CL program here ---------------------------------------------------------- Inside CL PGM DCLF File(xxx) Ovrdbf File(xxxx) Share(*Yes) Secure(*Yes) Opnqryf File((T00210)) QrySlt('AAAUS *GT "111" + *And AAAUS *LE "222"') Here it fails

Software/Hardware used:
AS400

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 11  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • philpl1jb
    DCLF File(xxx) Ovrdbf File(xxxx) Share(*Yes) Secure(*Yes) Opnqryf File((T00210)) QrySlt('AAAUS *GT "111" + *And AAAUS *LE "222"') 1. DCLF File(xxx) in both programs may not be necessary. This declaration is used in cl programs that use the rcvf to read the file. 2. I assume that T00210 in your sample is xxx an error in editing the question. 3. Clof Opnid(XXX) DltOvr File(XXX) might not act as expected if the RPG program fails to close the file (usually putting on *INLR)
    49,840 pointsBadges:
    report
  • philpl1jb
    Sorry, it's not that we've abandoned you .. but the system will not process my discussion responses.
    49,840 pointsBadges:
    report
  • philpl1jb
    Oh, now it will What I was suggesting ,, no DCLF in the first level programs PgmCL1 OVRDBF OPNQRY Call PgmCL2 CLOF DLTOVR OVRDBF OPNQRY Call PgmCL2 CLOF DLTOVR EndPgm
    49,840 pointsBadges:
    report
  • RamvishakRamesh
    Both my programs are using RCVF on that file, in that case how can I avoid DCLF? I am coming out of the RPG program with INLR on. And to add on that, am not using this file in F spec in RPG, instead it is being used inside an SQL and am making sure to close the cursor and LR = *ON while coming out.
    2,505 pointsBadges:
    report
  • RamvishakRamesh
    I read somewhere that inorder to hard close the cursor I have to put CLOSQLCSR as *ENDMOD instead of *ENDACTGRP . If I come out of SQL RPGLE with Close Cursor command and *INLR on, it will close the files right? Please share your thoughts on this.
    2,505 pointsBadges:
    report
  • philpl1jb
    I’m still of the opinion that you open the queries at one level without a DCLF and work with the results in a called program. But as far as deterimining if the RPG program is hanging up the close, just don’t call it an see if the error goes away. Phil
    49,840 pointsBadges:
    report
  • TomLiotta
    The RPG possibly doesn't matter (though the OVRDBF could make odd trouble; I've never mixed OPNQRYF and embedded SQL which seems almost contradictory). . The ODP is *SHAREd in the outer CL and also *SHAREd in the inner CL while the outer is still active.The outer ODP still exists. The two CLs have different OPNQRYFs, so the *SHARE probably should not be used at all. The two CLs need different ODPs. There's nothing that should be shared as far as I can tell. . Tom
    125,585 pointsBadges:
    report
  • RamvishakRamesh
    Though I used share in both CL, I had deleted that override in that program itself after closing the file and then called the second program. I have commetned out the call to SQLRPGLE program, but still the error is there. But one thing I noticed was my Rcvf was not looping till EOF as for testing purpose I had commented out the loop to read the file again. So the RCVF was reading the file only once and then it was calling the RPG program, then close the file delete the override and call the second RPG program. Now I remove the comment and the file is reading till CPF0864 and the problem is resolved. But if the file is read only once....then even after closing the file why it is not allowing to do another opnqryf in the second program remains unanswered.. :(
    2,505 pointsBadges:
    report
  • TomLiotta
    ...I had deleted that override in that program itself after closing the file...

    That is all completely irrelevant. It doesn't matter if the override was deleted; the ODP is still there until the program ends. It doesn't matter that you ran CLOF; the ODP is still there until the program ends.
    .
    I'll say it again. Once the file reaches EOF, that's where it stays until the CL program ends. You can't make the ODP close. You can't remove the override from the ODP. That's how it has always worked, and it won't be any different until you can upgrade to i 6.1 so you can use the new CLOSE command.
    .
    After the ODP is created, you can't get rid of it without ending the program that created it (or until i 6.1). The override has become part of the ODP. Deleting the override just means that a new ODP over the same file won't have the same override applied to it. But the original ODP is still there.
    .
    Since CL program 2 is running inside of CL program 1, it is directly affected by CL program 1. You might scope the overrides to the activation group, and compile the two CLs to run in different activation groups. But that mostly apparently means the same thing as not sharing the ODP. Run it all as SHARE(*NO) and see if there are differences. I already asked if you had a reason for sharing, but I haven't seen a response yet.
    .
    The error message tells you that you can't use sharing for that function, and I don't see any reason to use sharing. So, why not get rid of it?
    .
    Tom
    125,585 pointsBadges:
    report
  • RamvishakRamesh
    I have used sharing because otherwise my Rcvf was not getting the records that satisfy the QrySlt condition mentioned in Opnqryf. I have Dclf, ovrdbf share(*Yes), opnqryf, and Rcvf on both the CL programs. But the Opnryf QrySlt condition is different in both the CL. As I said, if the file reads till Eof, I dont have any issues. The issue appears only if I read one record alone. And from your response I understood we cannot deletet the ODP just by closing the file and deleting the override. And my programs are not Clle, they are CLPs. If I make Share(*No) do I need to change the scope to *Job inorder to read the Qryslt records using Rcvf?
    2,505 pointsBadges:
    report
  • TomLiotta
    The problem comes from the sharing. OPNQRYF cannot share an existing ODP. But unfortunately, as you've learned, the reason you have to share is because of OPNQRYF. You've answered why the sharing is done; OPNQRYF requires it. But it seems like a contradiction, doesn't it?
    .
    That's why I suggested that you might need three CL programs instead breaking it into only two.
    .
    You need one CL program that calls one CL with OPNQRYF, then calls your RPG program, and finally calls the second CL with the second OPNQRYF. The final structure has three CL programs and one RPG.
    .
    The OPNQRYFs will be in two separate programs, and the first of those will be completely finished before the second one starts. Your code then begins to look like this:
    .
    Main program:
    Call CL1
    
    Call RPG program 
    
    Call CL2
    Inside CL1:
    PGM
    DCLF File(XXX)
    OvrDbf     File(xxxx) ToFile(*LIBL/xxxx) SHARE(*YES)                    
    OpnQryF    File((xxxx) QrySlt('Fld1 *EQ "3"')                   
    read the file here 
    Inside CL2:
    PGM
    DCLF File(xxx)
    Ovrdbf     File(xxxx) Share(*Yes) Secure(*Yes)      
    Opnqryf    File((T00210)) QrySlt('AAAUS *GT "111" +        
                 *And AAAUS *LE "222"')
    If you need to pass values between all of the programs, you'll need to use parms to do it.
    .
    See how CL1 is completely finished by the time CL2 runs?
    .
    Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following