I've tried most of the suggestions I've received here but to no avail.
The idea of forming one big joined view between my two views was shot
down possibly due to being overly complex (the view created by the CLP
is already a UNION view), not up to standard or could create future
problems (the primary view's data is from another new system that is

The only event that precisely caused the problem was the creation of a
view in an external CL program (CLLE). As long as that event did not
occur, there were no problems.

Two workarounds presented themselves: create the complex view inside the
RPG program or read the first view into an array for processing later.
The first option was pretty ugly and the second option seemed a good fit
based on the somewhat simple data contained in the associated table. We
went with the latter.

Thank you for all your suggestions.

-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of
Charles Wilt
Sent: Friday, July 25, 2014 10:29 AM
To: Midrange Systems Technical Discussion
Subject: Re: Creating SQL View in CL closes SQL cursor in RPG program

Taking a cue from John Voris' post...

Do you have a COMMIT being done somewhere by chance?

The default for a static DECLARE CURSOR is WITHOUT HOLD - "Does not
the cursor from being closed as a consequence of a
commit operation."

Reading the docs for WITH HOLD I also notice: "All cursors are
closed by a CONNECT (Type 1)"

So I'm thinking your CL is probably initiating a new connection; thus
closing the cursor.

I'd move the create view to the RPG.

Since RUNSQLSTM is an OPM program and runs in the DFTACTGRP, you may be
able to get it to work by running the RPG program in a *NEW or a named
activation group.


On Fri, Jul 25, 2014 at 10:04 AM, Vernon Hamberg

I'm going to suggest that you embed the CREATE VIEW statement into the
code in a procedure, maybe - make it the first thing you run in the

Or, if the view is needed to do something more with the results from
other cursor, put its definition in as part of a JOIN or some such.
table expression instead of the view.

Otherwise, you might look at the create attribute that controls when
cursor is closed. It might make a difference.


On 7/25/2014 7:54 AM, Siwicki, Gary (GSiwicki) wrote:

In my RPG program, I call a CL that has a RUNSQLSTM command that uses
the commands in a TXT source member to create an SQL view in QTEMP.
only command executed is "CREATE VIEW". When this occurs, there is
already another, unrelated SQL cursor that is open and being
in the RPG program. When the view is created by the CL program, as
as control is returned to the RPG program, the "unrelated" SQL cursor

I realize this is a very awkward way of creating a view but it was
decided that this is the best way to address the unique needs of the
application. Does anyone know what's going on here? I posted here
because I don't think this really has much to do with RPG.

Gary Siwicki

RPG Developer

Lincare, Inc.

(727) 431-8186

This message originates from Lincare Holdings Inc. It contains
information which may be confidential or privileged and is intended
for the individual or entity named above.
It is prohibited for anyone else to disclose, copy, distribute or use
contents of this message.
All personal messages express views solely of the sender, which are
to be attributed to Lincare Holdings Inc., and may not be copied or
distributed without this disclaimer.
If you received this message in error, please notify us immediately
MailAdmin@xxxxxxxxxxx or (800) 284-2006.

This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.

This thread ...


Return to Archive home page | Return to MIDRANGE.COM home page