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

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: 765
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: 765
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: 765
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: 3053
Location: NYC,USA

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

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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Duplicate transid's declared using CEDA CICS 3
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top