View previous topic :: View next topic |
Author |
Message |
abhinav343 Beginner
Joined: 12 Jun 2007 Posts: 23 Topics: 12
|
Posted: Thu Dec 18, 2008 3:54 pm Post subject: Listing extra records in DB2 table |
|
|
Hi,
I am comparing a flat file with a DB2 table. Taking a key from flat file and searching it into DB2 table.
I want to list all the DB2 records which doesnt have a mathcing key in file or you can say extra records in DB2 table.
Also, I know there can be a way comparing the flat file and DB2 unload file using SORT and get the differences but could you please suggest me other options?
Thanks,
Abhinav |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Thu Dec 18, 2008 4:36 pm Post subject: |
|
|
abhinav343,
If you dont want to unload and do a compare. Assuming that you don't have duplicates on the key values in the table you can try something like this
1. sort the flat file on ascending sequence of the key.
2. read the file in the program
3. for every key open a cursor on the db2 table with table key <= file key
4. fetch the cursor and compare the key . if equal ignore , else write output
5. repeat step 4 till end of cursor. once reached end of cursor close the cursor
6. perform the same steps for all the records in the file.
Kolusu |
|
Back to top |
|
 |
abhinav343 Beginner
Joined: 12 Jun 2007 Posts: 23 Topics: 12
|
Posted: Thu Dec 18, 2008 8:26 pm Post subject: |
|
|
kolusu wrote: | abhinav343,
If you dont want to unload and do a compare. Assuming that you don't have duplicates on the key values in the table you can try something like this
1. sort the flat file on ascending sequence of the key.
2. read the file in the program
3. for every key open a cursor on the db2 table with table key <= file key
4. fetch the cursor and compare the key . if equal ignore , else write output
5. repeat step 4 till end of cursor. once reached end of cursor close the cursor
6. perform the same steps for all the records in the file.
Kolusu |
Thanks Kolusu..I will try these steps and let you know. |
|
Back to top |
|
 |
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Fri Dec 19, 2008 9:07 am Post subject: |
|
|
You could also use a DECLARE'd GLOBAL TEMPORARY TABLE. Issue the command to create the table, insert your records, and then issue a query with a NOT EXISTS. |
|
Back to top |
|
 |
haatvedt Beginner
Joined: 14 Nov 2003 Posts: 66 Topics: 0 Location: St Cloud, Minnesota USA
|
Posted: Fri Dec 26, 2008 8:49 pm Post subject: |
|
|
Abhinav,
unless the table is very small, it would be much faster and more cost efficient to use a high performance unload utility to unload the table. I would recommend using an "order by" clause to put the unload into the same sequence as the sequential file. Then a simple COBOL match program could be used.
On of the questions I ask myself is "is this a cost effective solution to what the customer wants ?". There is always a cost to running a process and as such you want your process to be cost effective. _________________ Chuck Haatvedt
email --> clastnameatcharterdotnet
(replace lastname, at, dot with appropriate
characters) |
|
Back to top |
|
 |
|
|