View previous topic :: View next topic
|
Author |
Message |
kumar119119
New User
Joined: 31 May 2010 Posts: 25 Location: Pune
|
|
|
|
Hi Folks,
Advance Happy friendsip day to you all folks,
L&T interview question:
Interviewr:
I have an Insurance policy,
In my policy table there are 100 rows,
150 records are comes from third party file,
both record and row have same length,
I want to insert all records into my policy table,
But condition is:
1) If file record is already present in policy table...no need to insert ,
2) If record is not present...I need to insert in table,
3) If record is presnt in table...If any change I need to update,
4) If policy-num is not in file and :hv-pol-num is in table....I need to delete :hv-pol-num in DB2 policy table,
How you do all these?
So, please folks, help me in this,
I tried to explain..but he didn't satisfy,
If anyone have an idea please tell me,
Thanks in advance. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
With COBOL or some other programming language, it should be very easy for a software engineer. |
|
Back to top |
|
|
rockish
Active User
Joined: 05 Jun 2009 Posts: 185 Location: Planet Earth
|
|
|
|
As the question involves comparing table with file, file with table and as the total number of records to be handled is just 250, I would prefer a job with following steps,
1. Unload the table.
2. Delete all rows in the table.
3. Use sort utility to create the appropriate records to be inserted/updated in the table.
4. Load the table.
Of course, as Craq Giegerich has suggest, a simple COBOL program can also be used to accomplish this. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
You might also choose to use CURSORs... |
|
Back to top |
|
|
arvind.m
Active User
Joined: 28 Aug 2008 Posts: 205 Location: Hyderabad
|
|
|
|
Hi Kumar,
This is something we did earlier....
for each 100 columns we made a standard copybook in which we have change_flags and then the actual records.
For example, if a db2 table had 3 columns then copybook will be
Code: |
01 record.
05 rec-flags.
10 data-change pic x(01).
88 add value 'A'.
88 update value 'U'.
88 delete value 'D'.
10 empno-flag pic x(01) value 'N'.
88 empno_change value 'Y'.
10 empname-flag pic x(01) value 'N'.
88 empname_change value 'Y'.
10 empadd-flag pic x(01) value 'N'.
88 empadd_change value 'Y'.
05 rec-data.
10 empno pic x(05).
10 empname pic x(25).
10 empadd pic x(50).
|
and now whenever we get data from 3rd party, we'll read the data from the input file and will check the data-change field and made the program to take the necessary action.
Later this turned to be the standard copybook and whenever we have to update the database we used the same copybook.
Note: this was just an example. You need to work around with your resources.
Thanks,
Santosh G. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Arvind,
when you can get your user/third-party to annotate the data via the update/add/delete flag, you are in luck.
in kumar119119's situation, his user/third-party is just sending a file of data and it is up to kumar119119 to determine if update/insert/delete is the appropriate action based on a match against the existing db.
As Anuj indicated, use of a cursor can be used to perform the match merge/decision logic or unload as rochish suggested and then match merge the two qsam files and create a file like Arvind has suggested. |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
One more option assuming there is a timestamp field in the table.
Iterate the following process for all the records in the file.
1) Read the record from the file
2) Find for the policy number in the table and insert/update the record in the table.
Update timestamp even if there are no changes found between the record in the file and the table. This will make sure every record that needs to have an entry in the table is touched.
After reaching end of file, you can delete all the rows from the table which were not touched that day. |
|
Back to top |
|
|
kumar119119
New User
Joined: 31 May 2010 Posts: 25 Location: Pune
|
|
|
|
Thanx a lot to all of you for sharing your valuable time and replies for my post,
Thanx again. |
|
Back to top |
|
|
razesh84
New User
Joined: 05 Apr 2010 Posts: 41 Location: Kolkata,India
|
|
|
|
considering the criteria, policy table will hold only the records coming from the file.so i guess a load replace will be a better way to achieve this. |
|
Back to top |
|
|
santosh.shet82
New User
Joined: 15 Apr 2009 Posts: 1 Location: Bangalore
|
|
|
|
1) If file record is already present in policy table...no need to insert ,
2) If record is not present...I need to insert in table,
3) If record is presnt in table...If any change I need to update,
4) If policy-num is not in file and :hv-pol-num is in table....I need to delete :hv-pol-num in DB2 policy table,
There is another way for this:
Read the File and do a Update on the Policy Table,
If the SQLCODE is 00 then Point 3 is satisfied.
If the SQLCODE is -803 which is duplicate then skip processing the data then Point 1 is satisfied.
If the SQLCODE is +100, then write a Insert statement, Point 2 is satisfied.
Then Write a DELETE statement on Plicy table whose UPT_TIMESTAMP is Less than Current date, Point 4 is satisfied.
Hopefully I am correct. |
|
Back to top |
|
|
|