IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search Log in to check your private messages Log in
 

cursor cannot be dynamically declared in COBOL?


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

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Fri Aug 29, 2014 9:01 pm
Reply with quote

I'm trying to declare a cursor dynamically, and the select statement for the cursor varies according to input parameter.
But when I prepare the 'DECLARE CURSOR' statement, SQLCODE -084 always appear . As the the same cursor can be used without any problem in static SQL way, so , the DECLARE cursor itself is acceptable for DB2.
I cannot find why SQLCODE -084 always appear, can anybody help me on this? or, 'DECLARE CURSOR' statement cannot be used in dynamic way?
Back to top
View user's profile Send private message
don.leahy

Active Member


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

PostPosted: Sat Aug 30, 2014 1:33 am
Reply with quote

Yes, dynamic SQL is possible with Cobol.

However, you do not Prepare a DECLARE statement. DECLARE statements look like this:
Code:
EXEC SQL DECLARE DT CURSOR FOR SEL  END-EXEC
EXEC SQL DECLARE SEL STATEMENT      END-EXEC


In this example, it is the "SEL" sql statement that gets prepared:
Code:
EXEC SQL                                       
    PREPARE SEL INTO :SQLDA FROM :DYN-SQL-STMT 
END-EXEC                                       
Where :DYN-SQL-STMT is a host variable that contains the SELECT statement.
Back to top
View user's profile Send private message
dejunzhu

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Sat Aug 30, 2014 7:52 am
Reply with quote

I'm afraid I did not statement myself clearly enough.
I'm going to -DECLARE CURSOR,--OPEN CURSOR , -FETCH CURSOR ,- POSITIONED DELETE, -CLOSE CURSOR .

the declare part like below, and should be executed by using dynamic sql way.
Code:
DECLARE C1 CURSOR WITH HOLD FOR SELECT 1 FROM TMPA WHERE COL1 IN (SELECT COL1 FROM TMPB) FOR RS USE AND KEEP UPDATE LOCKS


but when prepare above statement, -084 occurred.
Back to top
View user's profile Send private message
don.leahy

Active Member


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

PostPosted: Sat Aug 30, 2014 8:21 am
Reply with quote

It failed because DECLARE is not an executable statement and cannot be Prepared. I suggest a careful reading of the DB2 Application Programming Guide be your next step. Pay particular attention to the sections dealing with dynamic SQL.
Back to top
View user's profile Send private message
dejunzhu

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Sat Aug 30, 2014 9:27 am
Reply with quote

If cursor declaration cannot be dynamically prepared, is there an solution to my requirement? Please suggest. thanks in advance.
Back to top
View user's profile Send private message
don.leahy

Active Member


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

PostPosted: Sun Aug 31, 2014 8:00 am
Reply with quote

You cannot just wrap a Prepare statement around a static SQL statement and expect it to work.

There is a solution, and you can find it in the manual I mentioned earlier.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2503
Location: NY,USA

PostPosted: Mon Sep 01, 2014 11:49 am
Reply with quote

Use [URL] BBCode for Links
page 340 onwards...
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DB2
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Forum Replies
No new posts Dynamically switching terminal model TSO/ISPF 9
No new posts JCL for replacing code in Cobol JCL & VSAM 8
No new posts COBOL VS SORT Utility for file format... COBOL Programming 6
No new posts XML Parsing in COBOL creating "h... COBOL Programming 0
No new posts Calling Rexx program from Cobol CLIST & REXX 12

Back to Top