Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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 Changeman get multiple "Browse C... elixir1986 Compuware & Other Tools 4 Fri Jul 14, 2017 1:48 am
No new posts Include/omit with "ALL" pa... mgl DFSORT/ICETOOL 6 Wed Jun 14, 2017 2:31 pm
No new posts compare 2 rows within the same file ram_vizag SYNCSORT 7 Wed Jun 14, 2017 12:34 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts Can I traverse a STEM variable? chong.zhou CLIST & REXX 5 Wed May 31, 2017 3:54 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us