Can we declare same Cursor more than once in a program



IBM's flagship relational database management system

Can we declare same Cursor more than once in a program

Postby Mann_B » Fri Jun 15, 2012 3:02 pm

Hi All

We have a requirement where we need to fecth data from more than one table.The table we need to refer will dynamically chnage based on Date in request .We have different tables defined for each date.We need to calculate the date in program and based on the results range we need to call those many Date tables.

Is it possible to declare the same cursor multiple times,each time for differet date to refer to that Date table?

Please tell me if we have any other option

Thank You
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Re: Can we declare same Cursor more than once in a program

Postby prino » Fri Jun 15, 2012 6:37 pm

Your question is just as (censored) "can we declare the same variable twice, once to hold debits and once to hold credits."

Of course you cannot!
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 635
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

Re: Can we declare same Cursor more than once in a program

Postby dick scherrer » Fri Jun 15, 2012 8:56 pm

Hello,

But you can declare 2 separate cursors that accomplish the same thing. . .

If you more clearly post more detail about what you want to do, maybe someone will have a more useful suggestion.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Can we declare same Cursor more than once in a program

Postby Nik22Dec » Thu Jun 21, 2012 4:05 pm

Hi,

I guess I understood where are you coming from. You need to have the same cursor function differently for different inputs. Right?

In that case, have you tried declaring the cursor more than once with the same name in the procedure division. The only thing which you will have to make sure of would be that you cannot execute 2 paras, both declaring the same cursor, in the same execution. You will at the time of execution have to make sure which cursor defintion do you want to pick. Be aware, that you can choose only one definition.
Thanks,
Nik
User avatar
Nik22Dec
 
Posts: 68
Joined: Mon Dec 26, 2011 6:38 pm
Has thanked: 2 times
Been thanked: 0 time

Re: Can we declare same Cursor more than once in a program

Postby GuyC » Thu Jun 21, 2012 5:23 pm

Actually what Nik22Dec said, is not true.
DECLARE CURSOR is not an executable statement. it is just a definition you give to the DB2 precompiler, much like DECLARE TABLE.
It is resolved during precompile / bind.
It's like asking to have two (77-level) variables in working storage with the same name (as Prino pointed out).

so you can NOT have :

IF A then perform para-A else perform para-B end-if.
OPEN cursor A

PARA-A.
     DECLARE CURSOR A  .. FROM tableA
    .
PARA-B
   DECLARE CURSOR A .. FROM TableB
   .
I can explain it to you, but i can not understand it for you.

These users thanked the author GuyC for the post:
Nik22Dec (Thu Jun 21, 2012 5:59 pm)
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times

Re: Can we declare same Cursor more than once in a program

Postby Nik22Dec » Thu Jun 21, 2012 5:58 pm

Now, that's really an embarrasing position to be into. I really need to brush my concepts thoroughly. Sorry All!!! :oops:
Thanks,
Nik
User avatar
Nik22Dec
 
Posts: 68
Joined: Mon Dec 26, 2011 6:38 pm
Has thanked: 2 times
Been thanked: 0 time

Re: Can we declare same Cursor more than once in a program

Postby adson3492 » Wed Apr 01, 2015 3:33 pm

I figure I comprehended what kind of slant are you taking on this issue. You have to have the same cursor work distinctively for diverse inputs. Isn't that so?

All things considered, have you taken a stab at pronouncing the cursor more than once with the same name in the strategy division. The main thing which you will need to verify would be that you can't execute 2 paras, both pronouncing the same cursor, in the same execution. You will at the time of execution need to verify which cursor defintion would you like to pick. Be mindful, that you can pick stand out definition.
adson3492
 
Posts: 1
Joined: Sat Jan 17, 2015 1:23 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Can we declare same Cursor more than once in a program

Postby NicC » Fri Apr 03, 2015 10:32 pm

I guess it was figured out almost 3 years ago! Please reply to active topics.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post