IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Inserting records to DB2 from file, with primary key


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vijayk_hr

New User


Joined: 05 Jul 2005
Posts: 3

PostPosted: Thu Sep 08, 2005 8:41 pm
Reply with quote

Dear All,
I need some input for the following from your side..please.

I have flat file and i need to read one by one records from this file and have to insert it into DB2 table. There is a primary key for this table.
Here what are the scenario i have to handle to avoid duplicate insertion error and others ...

here my doubt is ..how to handle duplicate insertion error and how to have unique key ..

Need help .........

Thanks,
Vijay[color=blue]
[/color]
Back to top
View user's profile Send private message
Anbudan

New User


Joined: 07 Sep 2005
Posts: 26
Location: Germany

PostPosted: Fri Sep 09, 2005 6:27 pm
Reply with quote

Hi Vijay

If duplicate ' means' - complete record(NOT single field), Then
I) create temp field(say Pic 80) in WS

1)Open the file
2)Read file
3)compare with remp field (check 'y' or 'n')
4)Move the record into temp field
5)insert into table


Any doubt, dont hesitate to ask

Regards
Anbudan
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: Mon Sep 12, 2005 12:21 pm
Reply with quote

Hi Vijay,

You go through the following steps...

1. Read File
2. Move File Variables into Host Variables
3. Execute Insert statement
4. IF SQLCODE=-803 THEN
DO ROLLBACK;
ELSE
IF SQLCODE = 0 THEN
DO COMMIT;

But It will take a long time. If it is a one time program then its ok. Other wise follow the steps suggested by Anubudan.

Thanks,
Reddy.
Back to top
View user's profile Send private message
prasanth_thavva

New User


Joined: 28 Jul 2005
Posts: 86
Location: Chennai

PostPosted: Mon Sep 12, 2005 3:46 pm
Reply with quote

hi,
two conditions u wll get one is
Quote:
one that depends on table definition


Quote:
-803 duplicate record found


if junk values moves to host variable -305 u have to handle this situation
usually 0-- do the normal process

IF wrong plz correct me
bye
Back to top
View user's profile Send private message
Nikhil Thayyil

New User


Joined: 12 Sep 2005
Posts: 5
Location: India

PostPosted: Tue Sep 13, 2005 10:07 am
Reply with quote

To eliminate the duplicates u can just use a Sort JCl.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Binary File format getting change whi... All Other Mainframe Topics 7
No new posts To fetch records that has Ttamp value... DFSORT/ICETOOL 4
No new posts ICETOOL returns no records JCL & VSAM 1
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
Search our Forums:

Back to Top