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 

Joining a File & a table

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


Joined: 12 Apr 2007
Posts: 28
Topics: 7

PostPosted: Wed Feb 06, 2008 7:17 pm    Post subject: Joining a File & a table Reply with quote

Hi,

We have a certain set of input files which need to mixed & matched with Db2 table information. Basically I can visualize this file as a table which is joined with another DB2 table on a common key.

Currently we are writing DB2 programs which reads each record from a file at a time & uses cursors to look up relevant records from the DB2 table.

I was thinking if there is a better solution to retrieve all matched records from DB2 table in one go instead of using cursors. Basic motive is to increase efficiency (I am assuming here it will give better results, please correct me if I am wrong).

Please suggest.
_________________
-Hatim M P
Back to top
View user's profile Send private message MSN Messenger
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Wed Feb 06, 2008 7:35 pm    Post subject: Reply with quote

Just how are planning on joining a table and a file?
Back to top
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Wed Feb 06, 2008 10:13 pm    Post subject: Reply with quote

For a relatively small number of records on your file, I've used your method of building a cursor for each record. For large files, you might consider unloading the DB2 table and matching the unload file to your input file on the relevant key after sorting both files of course.
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
vkphani
Intermediate


Joined: 05 Sep 2003
Posts: 483
Topics: 48

PostPosted: Thu Feb 07, 2008 12:05 am    Post subject: Reply with quote

Why don't you upload the file into a table and use inner join between both the tables.
Back to top
View user's profile Send private message Send e-mail
hellohatim
Beginner


Joined: 12 Apr 2007
Posts: 28
Topics: 7

PostPosted: Thu Feb 07, 2008 1:16 pm    Post subject: Reply with quote

Well I dont have corresponding tables for those files. I did see something of this sort on this forum
DECLARED GLOBAL TEMPORARY TABLE.

"Just how are planning on joining a table and a file?"

I dont know if this can be done, that's why the question....

As of now we are doing file based mix n match after unloading the table, updating it and reloading it, but then it creates problems for concurrency as the same tables are being used online as well.

Thanks!
-Hatim.
_________________
-Hatim M P
Back to top
View user's profile Send private message MSN Messenger
videlord
Beginner


Joined: 09 Dec 2004
Posts: 147
Topics: 19

PostPosted: Thu Feb 07, 2008 1:37 pm    Post subject: Reply with quote

Temporary table is one solution

DFSORT with SPLICE can be considered if the JOIN is not too complex, unload the table to file too
Back to top
View user's profile Send private message
hellohatim
Beginner


Joined: 12 Apr 2007
Posts: 28
Topics: 7

PostPosted: Thu Feb 07, 2008 1:49 pm    Post subject: Reply with quote

Hi Videlord,

we do have Sort joinkeys option that we are using where appropriate, but the question of concurrency still remains.
We have
1. Unload job
2. Mix n Match with Update
3. Load job

Between 1 & 3 the entire table has to be offline. Also in between if one of the job abends, the table will be offline till the abend is resolved.

I was wondering if its possible to achieve concurrency & efficiency in one go. Perhaps this can be achieved by working on the tables itself rather then files but at the same time avoiding too many connections to the DB.
_________________
-Hatim M P
Back to top
View user's profile Send private message MSN Messenger
videlord
Beginner


Joined: 09 Dec 2004
Posts: 147
Topics: 19

PostPosted: Thu Feb 07, 2008 2:13 pm    Post subject: Reply with quote

if the tabe are changing when do the join, then the result may change,depends on when to join , i think your application can handle it.

For concurrency consideratoin, you have to use DBMS.
Create temporary table or declared temporary table is effeciient than regular table if the table used to store temp data only
Back to top
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Thu Feb 07, 2008 2:30 pm    Post subject: Reply with quote

The size of your input file and the size of your cursors will help determine your solution. What are they? Also, do you update the DB2 table after the join or is it read only?
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
hellohatim
Beginner


Joined: 12 Apr 2007
Posts: 28
Topics: 7

PostPosted: Thu Feb 07, 2008 3:19 pm    Post subject: Reply with quote

The Size of the file as of now is between 50K to 100K rows, table size is same. These tables (including the project) are just 7 months old & they will grow 3-4 times in coming year or so.

Yes we do update the table after join.
_________________
-Hatim M P
Back to top
View user's profile Send private message MSN Messenger
hellohatim
Beginner


Joined: 12 Apr 2007
Posts: 28
Topics: 7

PostPosted: Thu Feb 07, 2008 3:23 pm    Post subject: Reply with quote

The Size of the file as of now is between 50K to 100K rows, table size is same. These tables (including the project) are just 7 months old & they will grow 3-4 times in coming year or so.

Yes we do update the table after join.
_________________
-Hatim M P
Back to top
View user's profile Send private message MSN Messenger
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Thu Feb 07, 2008 3:52 pm    Post subject: Reply with quote

Building a cursor between 50,000 and 100,000 times during a program is going to really tax DB2. I'd suggest defining a DB2 table to load your input file into then joining as vkphani suggested.
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Fri Feb 08, 2008 2:29 pm    Post subject: Reply with quote

Why do you need to use a cursor for each record in the file? Isn't there enought information in a record to identify what you need from the table?
Back to top
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Fri Feb 08, 2008 4:50 pm    Post subject: Reply with quote

I was assuming from Hatim's 1st post that each input record contains a unique key that, when used to build a cursor, would result in a number of rows on the DB2 table that match that key.
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
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