MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

db2 cursor related problem

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
Beswar
Beginner


Joined: 04 Feb 2003
Posts: 33
Topics: 15

PostPosted: Thu Mar 20, 2003 12:19 pm    Post subject: db2 cursor related problem Reply with quote

Hi

Is there any way I can find in the program whether curosr is opened or not. I have a situation where I should know if the cusrot is opened I need to do different process and if it is not openened I need to other process. Is there any way I can find this

Thanks
Eswar
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Thu Mar 20, 2003 1:38 pm    Post subject: Reply with quote

Eswar,
You can issue an OPEN cursor on the cursor in question and check the sqlcode and based on the sqlcode you can choose the process.To explain clearly, when issue an open cursor statement and if indeed the cursor is already opened then you will get a sqlcode of -502.If your open of the cursor is successful,then you will get a sqlcode of 0.

Code:

EXEC SQL
     OPEN CURSOR C1
END-EXEC 


EVALUATE SQLCODE     
    WHEN 0
         PERFORM PROCESS A     
    WHEN -502
         PERFORM PROCESS B
    WHEN OTHER
         PERFORM INHOUSE-ABEND-ROUTINE
END-EVALUATE



Hope this helps...

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Beswar
Beginner


Joined: 04 Feb 2003
Posts: 33
Topics: 15

PostPosted: Thu Mar 20, 2003 4:44 pm    Post subject: Reply with quote

Thaks for your help Kolusu. But if I Open again and if it already opened, the program would abend automatically. Becasue the I/O program that has the SQL query will automaticall abends the program when it get the sql codes other than 0 or 100. I don't think I can modify this, becasue these programs are from one of the products and usually the company polices won't recommend in changing the program which are related to the product.

that is why I just want to know without doing in any open/close again , can I perform any SQL query or any other way to find whether the cursor is already opened or not

Thanks
Eswar
Back to top
View user's profile Send private message
Manas Biswal
Intermediate


Joined: 29 Nov 2002
Posts: 382
Topics: 27
Location: Chennai, India

PostPosted: Fri Mar 21, 2003 12:31 am    Post subject: Reply with quote

Beswar,
Not a solution but just a thought on your problem. Opening a cursor through your application program does not in any way reflect on the DB2 catalog tables and hence there is no way, we can query any catalog tables and know whether the cursor is open or not. Other than Kolusu's solution, I feel that the only way that we can go is if we can somehow query the bufferpool to know. Whenever, we open a cursor, all the relevant records are fetched into the bufferpool. So, if there is any way we can query the bufferpool (none that I know of), then maybe we can know whether the cursor is opened or not.
Quote:

that is why I just want to know without doing in any open/close again , can I perform any SQL query or any other way to find whether the cursor is already opened or not

Now, if open/close are your only constraints and you are allowed to do fetch cursor in your application program without using the standard IO routine, then you can do a fetch on the cursor to know on whether the cursor is open or not. if the ftech succeds, that means that the open has been done else the open has not been done.

Regards,
Manas
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group