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
 
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 How to write Rexx program to size and... sreejeshcs CLIST & REXX 14 Thu Oct 12, 2017 7:26 am
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Addition of two records on 2 fields amar143 SYNCSORT 8 Tue Oct 03, 2017 11:14 am
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm

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