MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Listing extra records in DB2 table

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
abhinav343
Beginner


Joined: 12 Jun 2007
Posts: 23
Topics: 12

PostPosted: Thu Dec 18, 2008 3:54 pm    Post subject: Listing extra records in DB2 table Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Thu Dec 18, 2008 4:36 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
abhinav343
Beginner


Joined: 12 Jun 2007
Posts: 23
Topics: 12

PostPosted: Thu Dec 18, 2008 8:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Fri Dec 19, 2008 9:07 am    Post subject: Reply with quote

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
View user's profile Send private message
haatvedt
Beginner


Joined: 14 Nov 2003
Posts: 66
Topics: 0
Location: St Cloud, Minnesota USA

PostPosted: Fri Dec 26, 2008 8:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group