Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Dynamic SQL help

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
David Joyce

New User


Joined: 08 Aug 2008
Posts: 17
Location: Boulder Colorado

PostPosted: Fri Nov 13, 2009 1:24 am    Post subject: Dynamic SQL help
Reply with quote

I am trying to write a DB2/Cobol program using the SQLDA that executes dynamic SQL with a fixed-list of SELECT columns but a variable list of paramater markers. I keep receiving a -313 on the OPEN CURSOR and am stumped as to why this is happening. We are running DB2 v8 and IBM Cobol 3.3.
After each SQL statement I do check the SQLCODE and stop the program if anything other than 0 is found.

Here is a basic structure of my program:

SQL statement
SELECT COL1,COL2 FROM TABLE1 WHERE COL3 = ?

Move the SQL statement to a ws-variable

EXEC SQL
DECLARE STMT STATEMENT
END-EXEC

EXEC SQL
DECLARE ACMCUR CURSOR FOR STMT
END-EXEC

move 5 to SQLN

EXEC SQL
PREPARE STMT INTO :SQLDA FROM :STMTBUF
END-EXEC

SET SQLDATA(1) TO ADDRESS OF COL1
SET SQLDATA(1) TO ADDRESS OF COL2

*** FOR EACH PARAMETER MARKER
*** SET VALUES IN SQLDA

MOVE 453 TO SQLTYPE(3)
MOVE 4 TO SQLLEN(3)
MOVE 'ACT ' TO COL3
SET SQLDATA(3) TO ADDRESS OF COL3

The OPEN fails with a -313
EXEC SQL
OPEN ACMCUR USING DESCRIPTOR :SQLDA
END-EXEC

Any help, suggestions would be greatly appreciated. Thanks.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Nov 13, 2009 2:28 am    Post subject:
Reply with quote

Sqlcode -313 THE NUMBER OF HOST VARIABLES SPECIFIED IS NOT EQUAL TO THE NUMBER OF PARAMETER MARKERS


Redbook Dynamic SQL
Back to top
View user's profile Send private message
David Joyce

New User


Joined: 08 Aug 2008
Posts: 17
Location: Boulder Colorado

PostPosted: Fri Nov 13, 2009 3:24 am    Post subject: Reply to: Dynamic SQL help
Reply with quote

Dick,
Thanks for your reply but I am familiar with a -313 sqlcode. What I am hoping is someone to look at my code and let me know if I have something in the code I shouldn't or I am missing something in the code. Thanks.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1753
Location: Bloomington, IL

PostPosted: Fri Nov 13, 2009 3:27 am    Post subject:
Reply with quote

Have you checked the value of STMTBUF at the time of the PREPARE?
Back to top
View user's profile Send private message
David Joyce

New User


Joined: 08 Aug 2008
Posts: 17
Location: Boulder Colorado

PostPosted: Fri Nov 13, 2009 3:32 am    Post subject: Reply to: Dynamic SQL help
Reply with quote

Yes. Here is the value of STMTBUF

SELECT COL1,COL2 FROM TABLE1 WHERE COL3 = ?
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1280
Location: Belgium

PostPosted: Tue Nov 17, 2009 6:54 pm    Post subject:
Reply with quote

SET SQLDATA(1) TO ADDRESS OF COL1
SET SQLDATA(1) TO ADDRESS OF COL2
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Dynamic array request/response contai... Suja.Sai CICS 2 Tue Jan 24, 2017 11:37 am
No new posts REXX DB2: Dynamic allocation of DB2.D... BHAS CLIST & REXX 3 Mon Dec 19, 2016 8:26 pm
No new posts Creating a dynamic sort card in JCL u... ChitraChhabra DFSORT/ICETOOL 4 Wed Aug 03, 2016 6:15 pm
No new posts Need help on SQL Dynamic WHERE Clause subratarec DB2 12 Sat Jul 16, 2016 3:11 pm
No new posts Need to create file with Dynamic Name... kapil27 JCL & VSAM 4 Wed May 25, 2016 9:45 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us