09-17-2008 12:30 PM
Hi Gurus,
i have a table in that i have to insert duplicate records i.e with same key field values i have to insert multiple records and i cannot change the present stucture of the table. how can i handle this.
regards,
pavan.
09-17-2008 12:32 PM
09-17-2008 12:36 PM
i am not going to do anything that way.
i mean to say, is there any possibilty of adding new field to the table and using some counter value in program and can i add records. ( i cant change the existing key fields structure from my table ).
09-17-2008 12:47 PM
Hi,
If you want to insert duplicate entries you can do it by using the extension "ALLOW DUPLICATE ENTRIES" with the INSERT command.
If you want to identify the latest record after inserting the duplicate entries then you can check with the following possibility:
Insert 2 fields in the existing table structure:
1. Record Valid From
2. Record Valid To
When ever you insert a record mark the Valid From as the current date and Valid to as 31.12.9999...
After this when you want to insert a new record with same key fields....
for the first record change the Valid To date as current date
Insert new record with Valid from date = current date and Valid from date = 31.12.9999
Before inserting new record:
Record No. Key fields Valid From Date Valid To Date .....other fields
1 XXXXXXXXXXXXXXXXX 31.08.2008 31.12.9999 XXXXXXXXXXXXXXXXXXX
After Inserting new record
1 XXXXXXXXXXXXXXXXX 31.08.2008 17.09.2008 XXXXXXXXXXXXXXXXXXXX
2 XXXXXXXXXXXXXXXXX 17.09.2008 31.12.9999 XXXXXXXXXXXXXXXXXXXX
Hope this helps.
Regards,
Kunjal
09-17-2008 1:26 PM
if we check VBEP table ( schedule line table) there ETENR field is added as counter for the key fields. i want to implement some similar kind of logic in my program but i am unable to find how to do that.
can aneone provide me some idea??
regards.,
pavan.
09-17-2008 1:39 PM
If a bespoke Z table then you can introduce extra "counter" or "duplicate" key field as you have seen.
By default the value 0 would be given to existing entries when you modify the table structure.
Whenever you attempt to insert a duplicate you would get an error, you would then increment the counter by 1 and retry. Failing that if you expect many duplicate entries it is better to do a SELECT MAX ( counter ) using the remaining table key before attempting an insert and incrementing the result by 1.
I've had to do this in the past. It is worth adding error handling for the event when your counter field hits the limit e.g. 99 for a 2 digit domain