2006 Aug 24 11:30 AM
Hi,
I have a customized table and for which the first 2 are key fields..
1. Clnt keyfield
2. date keyfield..
I want the Date field to be unique..but it is not happening in my case while inserting the table from my pgm.
if the table don't hav the date as my itab date i want to insert the record and if it has already i want to modify the record.
Rgds
SAPUSER100
Message was edited by: SAPUSER 100
2006 Aug 24 11:34 AM
In effect, only the date field seems to be the key here(mandt will be there by default for most of the tables).
Can you show us how you are trying to populate the table? Probably you are inserting sy-datum (Which wil be same for all records uploaded on the same date).
Probably you need a time field as well as a key field to protect the uniqueness.
Regards,
Ravi
2006 Aug 24 11:34 AM
In effect, only the date field seems to be the key here(mandt will be there by default for most of the tables).
Can you show us how you are trying to populate the table? Probably you are inserting sy-datum (Which wil be same for all records uploaded on the same date).
Probably you need a time field as well as a key field to protect the uniqueness.
Regards,
Ravi
2006 Aug 24 11:45 AM
ravi,
i have inserted a set of records from 1st aug 2006 to 30 aug 2006.it was inserted fine.Again i execute the pgm for the same date 1st aug 2006 to 30 aug 2006.It's inserting again..That's my problem.
Ys..i can use time field also for more precision..
Rgds,
SAPUSER
2006 Aug 24 11:51 AM
Please can you cut-paste the structure of your table as well as the piece of code trying to insert the values ?
Regards
Anurag
2006 Aug 24 11:36 AM
Hi,
table structure and itab structure should be same.
data itab like ztable occurs 0 with header line.
itab-date = sy-datum.
append itab.
inset ztable form table itab.
Regards,
Amole
2006 Aug 24 11:43 AM
I think as per your requirement the MODIFY ztable from itab should do the trick.
Regards
Anurag
2006 Aug 24 11:44 AM
hi
good
yes you can do it by update statement, you have to mention the primary key for the particular table and than using UPDATE statement you can update the particular table from your internal table.
thanks
mrutyun
2006 Aug 24 11:53 AM
Hi,
Follow this logic.
select * from ztable into table itab1.
loop at itab.
read table itab1 with key date = itab1-date.
if sy-subrc <> 0.
insert ztable from itab.
else.
modify ztable from itab.
endif .
endloop.
Regards
Amole
2006 Aug 24 12:00 PM
hi,
Use modify statement.
As per the help: The MODIFY statement inserts one or several lines specified in source in the database table specified in target, or overwrites existing lines.
So, it will check for an existing entry (primary key)and if it exist - data is overwritten. if it does not exist, that line gets inserted into the database table.
Hope this helps.
Regards,
Richa