IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Dynamic SQL help


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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
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: 1788
Location: Bloomington, IL

PostPosted: Fri Nov 13, 2009 3:27 am
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
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: 1281
Location: Belgium

PostPosted: Tue Nov 17, 2009 6:54 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Using Dynamic file handler in the Fil... COBOL Programming 2
No new posts JCL Dynamic System Symbols JCL & VSAM 3
No new posts Synctool-dynamic split job for varyin... JCL & VSAM 7
No new posts Dynamic file allocation using JCL JCL & VSAM 8
No new posts Dynamic Sortin DD cards SYNCSORT 8
Search our Forums:

Back to Top