View previous topic :: View next topic
|
Author |
Message |
sm_2009
New User
Joined: 10 May 2009 Posts: 72 Location: bangalore
|
|
|
|
hi all,
i have a requirement as follows:
1. the cursor will fetch rows from a table taking few fields as key.
2. i have to check the year part of date(fetched from table) with input date year part.
3. if both the years are matching i need to add amounts fields (fethced from table)
the problem is I'm using cursor to fetch data from table.
I'm not getting where i will set end-of-cursor-yes as true. |
|
Back to top |
|
|
sm_2009
New User
Joined: 10 May 2009 Posts: 72 Location: bangalore
|
|
|
|
pls suggest |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
When your SQLCODE is not 000 after a FETCH.
A +100 is a normal out-of-data/end-of-data condition.
Any negative SQLCODE indicates that you have a problem. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
please do not pester
replying is on voluntary base, effort, time, interest
look at the relevant db2 manuals for the return code issued bt SQL when no more rows are avilable to fetched |
|
Back to top |
|
|
aishwarya_20
New User
Joined: 19 Nov 2008 Posts: 57 Location: pune
|
|
|
|
You need to check SQLCODE each time you fetch from the cursor. End of cursor will be set when SQLCODE returned after fetch query is +100.
Else if fetch call is successfull SQLCODE will be zero. |
|
Back to top |
|
|
sm_2009
New User
Joined: 10 May 2009 Posts: 72 Location: bangalore
|
|
|
|
hi all
thanks
table has two rows with values 100.00 and 200.00
pgm:
set end-of-cursor-no to true
open cursor
fetch cursor
evaluate sqlcode
when 0
perform 123-add-para
when 100
set end-of-cursor-yes to true
when other
call error-para
end-evaluate
close cursor
123-add-para.
compute ws-total=ws-total + ws-val
ws-val is fetch amount from table.
here only first row is getting fetched and addition is not happening.
pls suggest solution |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
do You realize that You must implement a loop to fetch all the rows ?? |
|
Back to top |
|
|
sm_2009
New User
Joined: 10 May 2009 Posts: 72 Location: bangalore
|
|
|
|
ok
then
i can write as perform 123-add-para until end-of-cursor-yes
after the query? |
|
Back to top |
|
|
sm_2009
New User
Joined: 10 May 2009 Posts: 72 Location: bangalore
|
|
|
|
now the whole add-para is going in loop
|
|
Back to top |
|
|
sm_2009
New User
Joined: 10 May 2009 Posts: 72 Location: bangalore
|
|
|
|
i have put perform fetch para until end-of-cursor-yes
when sqlcode = 0, perform 123-add-para
still amts are not adding up. |
|
Back to top |
|
|
sm_2009
New User
Joined: 10 May 2009 Posts: 72 Location: bangalore
|
|
|
|
issue resolved |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Please share your solution for the benefit of others. |
|
Back to top |
|
|
sm_2009
New User
Joined: 10 May 2009 Posts: 72 Location: bangalore
|
|
|
|
the looping is like this:
perform fetch para until end-of-cursor
close cursor
if end-of-cursor-yes
display 'no more amts'
end-if
fetch -para.
set end-of-cursor-no to true
open cursor
fetch data from table
evaluate sqlcode
when sqlcode = 0
perform 123-add-para
when 100
set end-of-cursor-yes to true
when other
call error para
end-evaluate
123-add-para.
compute ws-total = ws-total + ws-val(from table) |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Are you sure what you coded works? I think the first 2 statements inside your fetch para should not be where they are now but rather should be placed right before the "perform fetch para entil end-of-cursor" statement. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Are you sure what you coded works? |
I suspect it does not. . . |
|
Back to top |
|
|
|