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

Print or write records fetched from a query


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

New User


Joined: 21 May 2005
Posts: 21
Location: Hyderabad

PostPosted: Fri Oct 08, 2010 1:15 am
Reply with quote

I will have multiple rows fetched from a query , i need to write all the records in to a file/ print as report.Someone help me how to do this.
Back to top
View user's profile Send private message
ovreddy

Active User


Joined: 06 Dec 2004
Posts: 211
Location: Keane Inc., Minneapolis USA.

PostPosted: Fri Oct 08, 2010 1:28 am
Reply with quote

Hi,

Follow below steps

1. Create a cursor at the begining of the program. Open the cursor.
2. Repeat below steps until you reach end of the cursor i.e. SQLCODE = +100.
-- Fetch Cursor into host variables
-- Move Host variable data to File variable or Report Variables
-- WRITE FILE or Report
3. Close Cursor and Close File or Report.

Thanks,
Reddy
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Oct 08, 2010 3:08 pm
Reply with quote

@ovreddy : I guess you missed the part : multirow ?

@sen: pseudo cobol:
Code:
open cursor
perform until sqlcode not = 0
   fetch next rowset for 100 rows
   move sqlerrd(3) to nrow-fetched
   perform varying ix from 1 by 1 until ix > nrow-fetched
     move host-var1 (ix) to output-var1
     move host-var2 (ix) to output-var2
     write
   end-perform
end-perform
close 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: Fri Oct 08, 2010 7:26 pm
Reply with quote

Hello,

Quote:
I guess you missed the part : multirow ?

Quote:
1. Create a cursor at the begining of the program. Open the cursor.
2. Repeat below steps until you reach end of the cursor i.e. SQLCODE = +100.

Would this not handle multirow? Seems like lots of the code here does exactly this to handle multirow selection. . . icon_confused.gif

Actually, when the code was written, this was the only to select multiple rows for a predicate. . .
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Oct 08, 2010 7:53 pm
Reply with quote

fetching 1 row multiple times <> fetching multiple rows
fetching multiple rows is not the same as selecting multiple rows.

It could be that the poster asks for solution of ovreddy, but then he has phrased his question wrong.
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: Fri Oct 08, 2010 9:03 pm
Reply with quote

Hi Guy,

Possibly we have read this differently:
Quote:
I will have multiple rows fetched from a query , i need to write all the records in to a file/ print as report


I don't see where "fetching 1 row multiple times" is mentioned in the original request icon_confused.gif
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Oct 11, 2010 12:31 pm
Reply with quote

is it "multiple-rows fetched" or "multiple rows-fetched" ?
my solution was for "multiple-rows fetched".
Any way now TS has both solutions, and hopefully he can decides whihc one he needs.
Back to top
View user's profile Send private message
prashanth1

New User


Joined: 27 Sep 2006
Posts: 47
Location: Hyderabad

PostPosted: Mon Oct 11, 2010 1:45 pm
Reply with quote

In perfromance aspect multple-rows fetch better than multiple rows-fetch.

But there are some limitations in multiple-rows fetch.
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: Mon Oct 11, 2010 9:24 pm
Reply with quote

Hello,

Quote:
where "fetching 1 row multiple times" is mentioned
And re-reading this again today, i see where i misread. . .

What i read (although mistakenly) was to read the same row (i.e. 1 row) multiple times. . . icon_redface.gif

I'll try to do better icon_smile.gif

d
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 2
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top