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
 

 

Help me in correctinf the prepare sql mistake

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

Active User


Joined: 05 Feb 2014
Posts: 159
Location: India

PostPosted: Tue Jun 30, 2015 4:35 pm    Post subject: Help me in correctinf the prepare sql mistake
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: 641
Location: Whitby, ON, Canada

PostPosted: Tue Jun 30, 2015 5:12 pm    Post subject:
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: 159
Location: India

PostPosted: Tue Jun 30, 2015 5:46 pm    Post subject:
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: 159
Location: India

PostPosted: Tue Jun 30, 2015 5:56 pm    Post subject:
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: 159
Location: India

PostPosted: Tue Jun 30, 2015 7:12 pm    Post subject:
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    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 Prepare in EXECSQL through REXX retur... sakrat DB2 1 Fri Jun 12, 2015 5:34 pm
No new posts Prepare a report to increase readability sivakumar somala CLIST & REXX 3 Thu Sep 11, 2014 5:16 pm
No new posts dynamic SQL - Prepare Execute erhema DB2 3 Mon Jul 14, 2014 1:07 pm
No new posts How to prepare a map without sending ... Simone Salzmann CICS 19 Mon Nov 26, 2012 10:45 pm
No new posts Using PREPARE to Call a Stored procedure Gowri Janakiraman DB2 6 Fri Oct 26, 2012 2:19 am


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