View previous topic :: View next topic
|
Author |
Message |
kalhor
New User
Joined: 20 May 2007 Posts: 31 Location: iran
|
|
|
|
Hello everybody,
My program is receiving SQL CODE = 514 and I don't know what should to do, in my program I have used dynamic sql to fetching the data from table, also the select statement and the Where clause are in their variables compile, link, edit and bind return code are "0" but the sql code is 514 in run time.
thanks,
Kalhor |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
SQLCODE -514 says it all: "THE CURSOR cursor-name IS NOT IN A PREPARED STATE"
1. You cannot perform a single row SELECT when using dynamic SQL. You must use a cursor.
2. The cursor must be prepared before it is opened.
Please refer to Squeezing the Most Out of Dynamic SQL. Look at chapter 3.7 in PDF file for examples. |
|
Back to top |
|
|
kalhor
New User
Joined: 20 May 2007 Posts: 31 Location: iran
|
|
|
|
Hi Marso
Thanks for your help, can you please check the following code
WORKING-STORAGE SECTION.
EXEC SQL
INCLUDE SQLCA
END-EXEC.
EXEC SQL INCLUDE SQLDA END-EXEC.
01 DSTRING.
49 VAR-LEN PIC S9(4) COMP VALUE 40.
49 VAR-TEXT PIC X(40).
01 BSTRING.
02 FILLER PIC X(32) VALUE "SELECT TRANS_DATE FROM GLIF_VIEW"
02 STMTTEXT PIC X(8).
===================
PROCEDURE DIVISION.
0001-MAIN.
EXEC SQL DECLARE C1 CURSOR FOR STMT END-EXEC.
MOVE BSTRING TO DSTRING.
EXEC SQL PREPARE STMT FROM :DSTRING END-EXEC.
EXEC SQL
OPEN C1
END-EXEC.
EXEC SQL
FETCH C1 INTO
:TRANS-DATE
END-EXEC.
... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
It works better if you post the "real" code. . .
Why is the sqlcode not checked after every sql statement? |
|
Back to top |
|
|
kalhor
New User
Joined: 20 May 2007 Posts: 31 Location: iran
|
|
|
|
Hi Dick
As you have toled, I 've checked the SQL code after every SQL statment,
so the SQL code after prepare is 311
SQLCODE -311, Error: THE LENGTH OF INPUT HOST VARIABLE NUMBER IS NEGATIVE OR GREATER THAN THE MAXIMUM
But I don't know what dose it mean when it says MAXIMUM.
also this is a piece of real code which I've sent.
Thanks[/code][/quote] |
|
Back to top |
|
|
Succor
New User
Joined: 20 Feb 2009 Posts: 96 Location: Bangalore :)
|
|
|
|
Kalhor, Instead of moving moving BSTRING TO DSTRING..move "SELECT TRANS_DATE FROM GLIF_VIEW" to VAR-TEXT. |
|
Back to top |
|
|
kalhor
New User
Joined: 20 May 2007 Posts: 31 Location: iran
|
|
|
|
Tankhs my friend it is solved.
Many thanks again. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
For future topics. . .
Quote: |
I 've checked the SQL code after every SQL statment, |
Then this should have been in the post. Copy/paste is far better than picking and choosing some parts of the info to type in with different names, missing code, etc.
One you have an error, it is best to solve that error rather than letting the code and trying to diagnose something that fails later in the code due to the already known error. As far as getting help from the forum, we can't do much if the real/first error is not the one posted. It just wastes time until the actual problem is posted and resolved. |
|
Back to top |
|
|
kalhor
New User
Joined: 20 May 2007 Posts: 31 Location: iran
|
|
|
|
Hi Dick.
I used your advice of checking SQL code after every SQL statement and it was the key to reach -311 SQL code and solve the problem. but I prefer SQL code 514 which reminds me to thank you 514 times.
Regards,
Kalhor |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
You're welcome
d |
|
Back to top |
|
|
|