Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
FETCH FIRST "N" ROWS ONLY using a variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: FETCH FIRST "N" ROWS ONLY using a variable
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

Site Director


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

PostPosted: Wed Jul 15, 2009 8:28 am    Post subject:
Reply with quote

Hello,

You could use a cursor. . .
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Wed Jul 15, 2009 8:32 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Wed Jul 15, 2009 9:03 am    Post subject:
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    Post subject:
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: 6968
Location: porcelain throne

PostPosted: Wed Jul 15, 2009 1:11 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Fetch Previous month & year in MM... girishb2 DFSORT/ICETOOL 3 Thu Sep 21, 2017 9:54 pm
No new posts Conditional highlighting of rows in I... packerm CLIST & REXX 2 Thu Sep 21, 2017 6:50 pm
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts Moving values to a variable of copybo... Vignesh Sid COBOL Programming 6 Wed Sep 06, 2017 1:04 pm
This topic is locked: you cannot edit posts or make replies. Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us