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

problem in setting end-of-cursor-yes


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sm_2009

New User


Joined: 10 May 2009
Posts: 72
Location: bangalore

PostPosted: Mon Jun 08, 2009 11:34 am
Reply with quote

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
View user's profile Send private message
sm_2009

New User


Joined: 10 May 2009
Posts: 72
Location: bangalore

PostPosted: Mon Jun 08, 2009 2:10 pm
Reply with quote

pls suggest
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Jun 08, 2009 2:13 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Jun 08, 2009 2:14 pm
Reply with quote

please do not pester icon_evil.gif

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
View user's profile Send private message
aishwarya_20

New User


Joined: 19 Nov 2008
Posts: 57
Location: pune

PostPosted: Mon Jun 08, 2009 2:15 pm
Reply with quote

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
View user's profile Send private message
sm_2009

New User


Joined: 10 May 2009
Posts: 72
Location: bangalore

PostPosted: Mon Jun 08, 2009 2:30 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Jun 08, 2009 2:32 pm
Reply with quote

do You realize that You must implement a loop to fetch all the rows ??
Back to top
View user's profile Send private message
sm_2009

New User


Joined: 10 May 2009
Posts: 72
Location: bangalore

PostPosted: Mon Jun 08, 2009 2:34 pm
Reply with quote

ok

then

i can write as perform 123-add-para until end-of-cursor-yes
after the query?
Back to top
View user's profile Send private message
sm_2009

New User


Joined: 10 May 2009
Posts: 72
Location: bangalore

PostPosted: Mon Jun 08, 2009 2:42 pm
Reply with quote

now the whole add-para is going in loop

icon_sad.gif
Back to top
View user's profile Send private message
sm_2009

New User


Joined: 10 May 2009
Posts: 72
Location: bangalore

PostPosted: Mon Jun 08, 2009 3:28 pm
Reply with quote

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
View user's profile Send private message
sm_2009

New User


Joined: 10 May 2009
Posts: 72
Location: bangalore

PostPosted: Mon Jun 08, 2009 5:14 pm
Reply with quote

issue resolved
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Mon Jun 08, 2009 5:32 pm
Reply with quote

Please share your solution for the benefit of others.
Back to top
View user's profile Send private message
sm_2009

New User


Joined: 10 May 2009
Posts: 72
Location: bangalore

PostPosted: Mon Jun 08, 2009 6:43 pm
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Mon Jun 08, 2009 7:48 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jun 09, 2009 4:24 am
Reply with quote

Hello,

Quote:
Are you sure what you coded works?
I suspect it does not. . .
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
No new posts Change Default Scroll Setting TSO/ISPF 1
No new posts z/vm installation problem All Other Mainframe Topics 0
No new posts Job scheduling problem. JCL & VSAM 9
Search our Forums:

Back to Top