Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 658
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: 658
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: 658
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: 1818
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. Cobol to fetch the content by using s... arunc55 COBOL Programming 4 Fri Nov 17, 2017 1:25 pm
No new posts VBS and VB, COBOL syntax is the same ... natt.sut COBOL Programming 3 Sun Nov 12, 2017 6:36 am
No new posts -502 Error - Cursor already open anand jeyapaul DB2 7 Sun Oct 29, 2017 4:22 am
No new posts COBOL - EXIT statement weird behavior anthony.pangestu COBOL Programming 0 Fri Oct 27, 2017 9:57 am
No new posts IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us