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

Help me in correctinf the prepare sql mistake


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Tue Jun 30, 2015 4:35 pm
Reply with quote

Hi,

I have written code like below to insert into the table, but i am getting sql code error of -104 in prepare sql statement and -518 in execute statement. help me in correcting the mistake please...

Code:


VAL.L =  ,FIELD1,FIELD2,FIELD3,FIELD4

DATA = SUBSTR(VAL.L,3)

QUERY1='INSERT INTO 'SRCSCHEMA'.'TABLE' VALUES('DATA') '

ADDRESS DSNREXX "EXECSQL DECLARE C2 CURSOR FOR S2"
IF SQLCODE <> 0 THEN CALL SQLCA

ADDRESS DSNREXX "EXECSQL PREPARE S2 FROM :QUERY1"
IF SQLCODE <> 0 THEN SAY SQLCODE CALL SQLCA

ADDRESS DSNREXX "EXECSQL EXECUTE S2 USING :DATA"

IF SQLCODE = 0 THEN
   SAY "INSERT SUCCESSFUL"
ELSE
  DO
  SAY "INSERT OPERATION FAILED"
  SAY 'SQLCODE' SQLCODE
  SAY 'SQLSTATE' SQLSTATE
  SAY 'SQL ERROR MESSAGE' SQLERRMC
END



VAL.L is obtained from SQL Fetch statement earlier to this code and that works fine.....
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 696
Location: Whitby, ON, Canada

PostPosted: Tue Jun 30, 2015 5:12 pm
Reply with quote

I suggest that you take out the DECLARE CURSOR statement. S2 is an INSERT, which does not require a cursor. You could also consider EXECUTE IMMEDIATE for the Insert rather than PREPARE+EXECUTE.
Back to top
View user's profile Send private message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Tue Jun 30, 2015 5:46 pm
Reply with quote

don.leahy wrote:
I suggest that you take out the DECLARE CURSOR statement. S2 is an INSERT, which does not require a cursor. You could also consider EXECUTE IMMEDIATE for the Insert rather than PREPARE+EXECUTE.


I tried as how you suggested but still get the same:

Code:


QUERY1='INSERT INTO 'SRCSCHEMA'.'TABLE' VALUES('DATA') '

ADDRESS DSNREXX "EXECSQL PREPARE S2 FROM :QUERY1"
IF SQLCODE <> 0 THEN SAY SQLCODE CALL SQLCA

ADDRESS DSNREXX "EXECSQL EXECUTE IMMEDIATE S2"

IF SQLCODE = 0 THEN
   SAY "INSERT SUCCESSFUL"
ELSE
   DO
     SAY "INSERT OPERATION FAILED"
     SAY 'SQLCODE' SQLCODE
     SAY 'SQLSTATE' SQLSTATE
     SAY 'SQL ERROR MESSAGE' SQLERRMC
  END




output Error:

Code:


 INSERT OPERATION FAILED
 SQLCODE -104
 SQLSTATE 42601
 SQL ERROR MESSAGE S2:<HOST-VARIABLE>
 ***


Back to top
View user's profile Send private message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Tue Jun 30, 2015 5:56 pm
Reply with quote

It says the return -104 is illegal token and it should be token-list.... what does the token mean here in the INSERT QUERY....?
Back to top
View user's profile Send private message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Tue Jun 30, 2015 7:12 pm
Reply with quote

don.leahy wrote:
I suggest that you take out the DECLARE CURSOR statement. S2 is an INSERT, which does not require a cursor. You could also consider EXECUTE IMMEDIATE for the Insert rather than PREPARE+EXECUTE.


I sorted out the mistake that I made. now i am able to insert successfully...Thank you very much for give me the suggestion which was very useful to me to understand.....

Thanks,
sakrat
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 SQLCODE -950 in PREPARE statement ... DB2 2
No new posts Prepare in EXECSQL through REXX retur... DB2 1
No new posts Prepare a report to increase readability CLIST & REXX 3
No new posts dynamic SQL - Prepare Execute DB2 3
No new posts How to prepare a map without sending ... CICS 19
Search our Forums:

Back to Top