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

Multi ROW fetch question


IBM Mainframe Forums -> DB2
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Thu Aug 30, 2012 7:37 pm
Reply with quote

Code:
Perform until end-process

exec sql                                 
     fetch next rowset                   
      from xyz for 2000 rows
      into :ab                 
end-exec                                 

Evaluate SQLCODE
when 0
when +100
 perform 100-main-process
Error
End-evaluate
100-main-process

exec sql                                   
     get diagnostics :row-count=row_count
end-exec               

if row-count > 0
 process
else
Set end-process to true
end-if                 

Will this be going in loop?
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Aug 30, 2012 8:31 pm
Reply with quote

Something perhaps, you don't want to listen - but why not run a test your own?
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Thu Aug 30, 2012 8:40 pm
Reply with quote

Anuj,

Yes I am trying to test parallely but you know it needs lot of data set up as per program conditions.
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: Thu Aug 30, 2012 8:51 pm
Reply with quote

Hello,

So, set up some data and test. . .

Add a little at a time - it is not all needed the very first time thru . . .
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Thu Aug 30, 2012 9:18 pm
Reply with quote

Yes Dick, true
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Fri Aug 31, 2012 9:22 am
Reply with quote

Hi Rohit,

For me logic looks bit confusing..

You need to set end-process to true in case of Sqlcode 100.

Because for multi-fetch in case of sqlcode 100 your row-count may or may not come greater than zero.

I am not sure what will be value of row count when you issue next fetch even after sqlcode 100 and this next fetch will definitely happen when your first sqlcode 100 return 1 or more row and that might be the reason your logic going in loop

Let me know if I am missing anything or any further information required

Regards,
Chandan
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Aug 31, 2012 9:43 am
Reply with quote

Chandan,
good catch!

point is that when you have FETCH'd and received an sqlcode of +100,
the next FETCH will not give you an SQLCODE of 0 or +100,
it will be negative something.

Rohit,
according to the advice in the manuals, a 2000 row rowset fetch
is not suggested.
100, 200 maybe 500; but more is not suggested.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Fri Aug 31, 2012 10:02 am
Reply with quote

Hi Rohit,

Just a suggestion you can use SQLERRD(3) to get ROW-COUNT after fetch like below

Code:
MOVE SQLERRD(3) TO ROW-COUNT


This will reduce on DB2 I-O operation of get diagnostics

Regards,
Chandan
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Fri Aug 31, 2012 2:52 pm
Reply with quote

@Chandan: Yes your are right, but you know the stored procedure is already in production for a pretty long time.So I can cannot change any code unless it has some performance issue.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Fri Aug 31, 2012 2:59 pm
Reply with quote

Quote:
point is that when you have FETCH'd and received an sqlcode of +100,
the next FETCH will not give you an SQLCODE of 0 or +100,
it will be negative something.


But if it is other than 0 or 100 then it should throw some error as per the logic which is not happening.[/quote]
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Fri Aug 31, 2012 4:02 pm
Reply with quote

With first glance at your code, Rohit : If SQLCODE is 0 or 100, control goes to 100-main-process where program checks for the row-count. In case SQLCODE=100, row-count is 0 which is NOT greater than 0 so the flag 'end-process' is set to true; and this acts as a 'cotrol break' for PERFORM UNTIL and the loop ends.

That's why the condition of "a next fetch after SQLCODE=+100" should not come and the program works.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Fri Aug 31, 2012 4:03 pm
Reply with quote

Hi Rohit,

But as per your earlier post this logic is going into loop then how its working fine in production?

About sqlcode after next fetch,it needs to be checked whether it gives 100 or some other sqlcode. I am not sure about it

its better to check with some test data

Regards,
Chandan
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Fri Aug 31, 2012 4:07 pm
Reply with quote

And why do you question:
Quote:
Will this be going in loop?
- have you faced some problem or you just speculated this while analyzing the code?
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Fri Aug 31, 2012 4:28 pm
Reply with quote

I just ran a quick test code for similar scenario but not with muti fetch

it's giving sqlcode 100 not single fetch when its going for fetch even after sqlcode 100

Regards,
Chandan
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Fri Aug 31, 2012 4:45 pm
Reply with quote

Just a correction in typo

I meant to say it gives sqlcode 100 for next fetch

Few addition to Anuj's reply..

When this query returns sqlcode 100 for first time it may return few rows but less that your row set limit in this case ROW-COUNT > 0 and
end-process will not be set.

But it should for the next fetch when it will return 100

Looks like its your speculation as Anuj mentioned

Regards,
Chandan
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Aug 31, 2012 4:47 pm
Reply with quote

the topic is getting nowhere, wasting time on pure speculation
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Fri Aug 31, 2012 5:02 pm
Reply with quote

Totally agree with you Enrico
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Fetch data from programs execute (dat... DB2 3
No new posts Question for file manager IBM Tools 7
No new posts Convert single row multi cols to sing... DFSORT/ICETOOL 6
No new posts question for Pedro TSO/ISPF 2
No new posts Code Multi Row fetch in PL1 program PL/I & Assembler 1
Search our Forums:

Back to Top