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
 

 

Print or write records fetched from a query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
sen_1983us

New User


Joined: 21 May 2005
Posts: 18
Location: Hyderabad

PostPosted: Fri Oct 08, 2010 1:15 am    Post subject: Print or write records fetched from a query
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Fri Oct 08, 2010 7:26 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Fri Oct 08, 2010 9:03 pm    Post subject:
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Mon Oct 11, 2010 9:24 pm    Post subject: Reply to: Print or write records fetched from a query
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    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 Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts Join giving more records than expected Danielle.Filteau SYNCSORT 2 Thu Mar 09, 2017 3:28 am
No new posts TSO or command line utility to genera... kishpra JCL & VSAM 3 Thu Mar 09, 2017 1:11 am
No new posts Extract set of records matching on ac... bhaskar_kanteti DFSORT/ICETOOL 3 Mon Mar 06, 2017 7:19 am


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