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
 

 

cursor cannot be dynamically declared in COBOL?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: cursor cannot be dynamically declared in COBOL?
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: 641
Location: Whitby, ON, Canada

PostPosted: Sat Aug 30, 2014 1:33 am    Post subject:
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    Post subject:
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: 641
Location: Whitby, ON, Canada

PostPosted: Sat Aug 30, 2014 8:21 am    Post subject:
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    Post subject:
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: 641
Location: Whitby, ON, Canada

PostPosted: Sun Aug 31, 2014 8:00 am    Post subject:
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

Senior Member


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

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

http://publib.boulder.ibm.com/epubs/pdf/dsnapk14.pdf
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    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
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Updating Cursor row withour using FOR... chandan.inst DB2 15 Tue Nov 08, 2016 11:17 am
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am


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