View previous topic :: View next topic |
Author |
Message |
dubasir Beginner
Joined: 13 Dec 2004 Posts: 20 Topics: 9
|
Posted: Thu Nov 26, 2009 10:27 am Post subject: Help on Fetch Curson in a loop |
|
|
I have a requirement where i have to process input file of 30,000 to 40,000 records and for every record read i have to open, fetch, close a cursor which is taking huge CPU time.
I tried to open and close the cursor once before (open) and after (close)reading the file and have only fetch statement for every record.
I have to use with hold option since i have DB2 commits in between.
When i used the above logic, i am not able to fetch the records from cursor for second record onwards. I guess the cursor is not triggered for
the second record onwards. Please suggest me how to resolve this.
Thanks in Advance,
Ramki |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Thu Nov 26, 2009 11:58 am Post subject: |
|
|
how many rows do you need to select for each of the 30-40,000 trigger records of the qsam file?
what does your cursor declaration look like?
are you re-populating the host-declarations before each cursor open?
obviously, you don't want to open/close the cursor for each of the trigger records;
but you have to give us a little info before we can offer suggestions.
answer all the above questions, please. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
dubasir Beginner
Joined: 13 Dec 2004 Posts: 20 Topics: 9
|
Posted: Thu Nov 26, 2009 11:44 pm Post subject: |
|
|
I can have maximum of 10 records for each of 30-40,000 trigger records of the qsam file
My Cursor declaration as follows
DECLARE CSR_NAME CURSOR WITH HOLD FOR
Yes, I am re-populating the host-declarations before each cursor open
Thanks,
Ramki |
|
Back to top |
|
 |
papadi Supermod
Joined: 20 Oct 2009 Posts: 594 Topics: 1
|
Posted: Fri Nov 27, 2009 12:13 am Post subject: |
|
|
You need to post the complete sql of the declare. What has been posted for the declare provides basically nothing  _________________ All the best,
di |
|
Back to top |
|
 |
dubasir Beginner
Joined: 13 Dec 2004 Posts: 20 Topics: 9
|
Posted: Fri Nov 27, 2009 12:21 am Post subject: |
|
|
Here is my complete cursor declaration
Code: |
EXEC SQL
DECLARE PRFRCST_CSR CURSOR WITH HOLD FOR
SELECT DISTINCT
A,
B
FROM Table
WHERE A <> :WS-A
AND C = :HV-C
AND D = :HV-D
AND E = :HV-E
AND F = :HV-F
AND G = :HV-G
AND (DATE_START <> :HV-DATE-START
OR DATE_END <> :HV-DATE-END)
AND ((DATE_START BETWEEN :HV-DATE-START AND
:HV-DATE-END)
OR (DATE_END BETWEEN :HV-DATE-START AND
:HV-DATE-END)
OR (DATE_START = :HV-DATE-START AND
DATE_END < :HV-DATE-END)
OR (DATE_START > :HV-DATE-START AND
DATE_END = :HV-DATE-END)
OR (DATE_START = :HV-DATE-START AND
DATE_END > :HV-DATE-END))
AND X > 0
QUERYNO 2
END-EXEC. |
|
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Fri Nov 27, 2009 10:10 am Post subject: |
|
|
you are correct; with the current WHERE conditions, you will need to open and close the cursor each time.
i have no idea on the relationship between any of the host variables and any order by, thus just a plain cursor for a match merge is not going to work either.
you are not UPDATing the DB2 table.
have you thought of unloading the table
using some criteria for where condition,
you will have to unload all columns referenced in your where clause.
and make your process a qsam match merge.
not knowing the process leaves us in the dark on what to suggest.
you could add a FOR READ ONLY clause, thus there would be no ambiguity and
it could process faster, but i doubt it.
AND (DATE_START <> :HV-DATE-START OR DATE_END <> :HV-DATE-END)
precludes
(DATE_START = :HV-DATE-START AND
DATE_END < :HV-DATE-END)
OR (DATE_START > :HV-DATE-START AND
DATE_END = :HV-DATE-END)
OR (DATE_START = :HV-DATE-START AND
DATE_END > :HV-DATE-END))
from ever being true.
You are either going to have to live with your OPEN/CLOSE/OPEN.... logic
(need indexes on date's)
or figure out how to unload and process qsam files - which would probably be faster
than 30-40,000 cursor open/closes. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
dubasir Beginner
Joined: 13 Dec 2004 Posts: 20 Topics: 9
|
Posted: Sat Nov 28, 2009 1:15 am Post subject: |
|
|
Thanks for the reply
Here is my requirement
I have to read all the records from database A and for each record read i have to look for a match based on some key and the date conditions in the
same database A and some other database B.
For this i have unloaded table A to a qsam file and for every record read
i have used open/fetch/close cursors to determine matched records from
both the tables A and B.
Table A can have 30,000 to 40,000 records and Table B can have millions of records.
Please suggest me the efficient approach for this.
Thanks in advance,
Ramki |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Sat Nov 28, 2009 2:13 pm Post subject: |
|
|
you can prepass the qsam file with either a sort or cobol program
to determine what limits can be imposed on the unload or an all inclusive cursor.
You could unload table B - limiting the unload based on the prepass
or just simply expand your cursor to include everything - again based on a prepass of the qsam.
a really huge cursor probably would not be worse than 30-40,000 opens/closes. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
|
Back to top |
|
 |
|
|