Page 1 of 1

Can we declare same Cursor more than once in a program

PostPosted: Fri Jun 15, 2012 3:02 pm
by Mann_B
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

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

PostPosted: Fri Jun 15, 2012 6:37 pm
by prino
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!

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

PostPosted: Fri Jun 15, 2012 8:56 pm
by dick scherrer
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.

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

PostPosted: Thu Jun 21, 2012 4:05 pm
by Nik22Dec
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.

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

PostPosted: Thu Jun 21, 2012 5:23 pm
by GuyC
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
   .

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

PostPosted: Thu Jun 21, 2012 5:58 pm
by Nik22Dec
Now, that's really an embarrasing position to be into. I really need to brush my concepts thoroughly. Sorry All!!! :oops:

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

PostPosted: Wed Apr 01, 2015 3:33 pm
by adson3492
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.

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

PostPosted: Fri Apr 03, 2015 10:32 pm
by NicC
I guess it was figured out almost 3 years ago! Please reply to active topics.