Focal Point
Looping Multiple SQL Stored Procedure Requests

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/4351099002

December 11, 2006, 01:11 PM
Deborah Sullivan
Looping Multiple SQL Stored Procedure Requests
Hi, I am wondering if anyone has run into this problem. I need to execute a SQL stored procedure multiple times and am running into some problems. Basically, after my first loop, any subsequent loop runs into a conflict with "SQLOUT". (This is the error: "(FOC1400) SQLCODE IS 49 (HEX: 00000031) : ct_options(): user api layer: external error: This routine cannot be called because another command structure has results pending.") Basically, the procedure seems to fail to create a new SQLOUT hold because SQLOUT is still active from the first pass. I have gotten around this before by renaming the targeted the output (for example, "PREPARE SQLOUT2 FOR") but the prepare statement doesn't seem to work with the called stored procedure.

I'm just throwing this out there in case anyone has some ideas.

Thanks,

Debbie Sullivan
December 11, 2006, 01:13 PM
Francis Mariani
Do you have -RUN between your requests?

If not, the problem you're getting may have something to do with the FOCUS stack...


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
December 11, 2006, 01:14 PM
Deborah Sullivan
Yep. I always use -RUN.
December 11, 2006, 01:49 PM
Francis Mariani
Deborah, I did a quick test, and this works in my DB2 environment:

SET SQLENGINE=DB2
-RUN

SQL
SELECT T1.REP_CD,T1.REP_DS FROM EQP.EQ_REP T1 FETCH FIRST 5 ROWS ONLY FOR FETCH ONLY;
TABLEF FILE SQLOUT
PRINT 
REP_CD
REP_DS
ON TABLE HOLD AS H001 FORMAT ALPHA
END
-RUN

SQL
SELECT T1.REP_CD,T1.REP_DS FROM EQP.EQ_REP T1 FETCH FIRST 10 ROWS ONLY FOR FETCH ONLY;
TABLEF FILE SQLOUT
PRINT 
REP_CD
REP_DS
ON TABLE HOLD AS H002 FORMAT ALPHA
END
-RUN

SQL
SELECT T1.REP_CD,T1.REP_DS FROM EQP.EQ_REP T1 FETCH FIRST 20 ROWS ONLY FOR FETCH ONLY;
TABLEF FILE SQLOUT
PRINT 
REP_CD
REP_DS
ON TABLE HOLD AS H002 FORMAT ALPHA
END
-RUN



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
December 11, 2006, 01:57 PM
Francis Mariani
Sorry, the previous posting may not be addressing the "stored procedure" issue.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
December 11, 2006, 02:21 PM
<RickW>
If you know approx. how long the proc runs, you could create a countdown timer with DM as part of your loop logic - or - use ReportCaster and flag completion files.

Food for thought Smiler
December 11, 2006, 02:37 PM
BlueZone
My first inclination would be towards Francis' solution above. You could have a dynamic naming variable for the Hold-file (in a loop if needed).
-*
-SET &HCNT=&HCNT + 1;
SQL DB2
SELECT
...
ON TABLE HOLD AS HOLD&HCNT..F
END
-* (gives you HOLD1F, HOLD2F, HOLD3F, etc.)
-*
If that does not work with Stored Procedures, you could try flushing out the SQLOUT to a hold file and then get back to the next S.P.

Intriguing Q anyway Debbie. Please post back as to what eventually worked.

Sandeep Mamidenna


-------------------------------------------------------------------------------------------------
Blue Cross & Blue Shield of MS
WF.76-10 on (WS2003 + WebSphere) / EDA on z/OS + DB2 + MS-SQL
MRE, BID, Dev. Studio, Self-Service apps & a dash of fun !! Music
December 12, 2006, 03:35 AM
Tony A
Deborah,

That message is normally due to the fact that the recordset returned from the stored proc has not been accessed and therefore the post from Francis is probably mostly on the money in as much that you need to issue a table request against your SP recordset before calling your SP again.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10