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

FETCH FIRST "N" ROWS ONLY using a variable


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Ezhil Murugan

New User


Joined: 10 Jul 2008
Posts: 14
Location: Chennai

PostPosted: Wed Jul 15, 2009 8:09 am
Reply with quote

I have a pretty simple Cobol program which accepts an integer as an input parameter. This parameter tells me how many rows to fetch. In my select statement, I can say 'FETCH FIRST 2 ROWS ONLY' but DB2 doesnt work when I replace the number 2 with the variable MMAXRECS. It says "Unexpected text "MMAXRECS" encountered.

Is there any other way i can fetch a variable number of rows?
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: Wed Jul 15, 2009 8:28 am
Reply with quote

Hello,

You could use a cursor. . .
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: Wed Jul 15, 2009 8:32 am
Reply with quote

Hello,

Sorry 'bout that - hit Submit too quickly. . . icon_redface.gif

In the cursor, define the max you intend to support and use the parm count to further restrict the number of rows processed.
Back to top
View user's profile Send private message
Ezhil Murugan

New User


Joined: 10 Jul 2008
Posts: 14
Location: Chennai

PostPosted: Wed Jul 15, 2009 8:52 am
Reply with quote

Hi d.sch,
My intension is to not lock the table and just lock the desired number of rows
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: Wed Jul 15, 2009 9:03 am
Reply with quote

Hello,

Why do you believe that defining a cursor locks the entire table?

If you post your cursor declaration, it may be helpful.
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Wed Jul 15, 2009 12:36 pm
Reply with quote

Quote:
when I replace the number 2 with the variable MMAXRECS

Could you please post the exact query that you wrote.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Jul 15, 2009 1:11 pm
Reply with quote

in addition to the exact query,
what is the working-storage definition of MMAXRECS?
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 -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts To get the count of rows for every 1 ... DB2 3
No new posts PuTTY - "User is not a surrogate... IBM Tools 5
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Fetch data from programs execute (dat... DB2 3
Search our Forums:

Back to Top