Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

table value insertion

Former Member
0 Kudos
165

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

1 ACCEPTED SOLUTION

former_member181962
Active Contributor
0 Kudos
131

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

8 REPLIES 8

former_member181962
Active Contributor
0 Kudos
132

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

0 Kudos
131

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

0 Kudos
131

Please can you cut-paste the structure of your table as well as the piece of code trying to insert the values ?

Regards

Anurag

Former Member
0 Kudos
131

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

Former Member
0 Kudos
131

I think as per your requirement the MODIFY ztable from itab should do the trick.

Regards

Anurag

Former Member
0 Kudos
131

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

Former Member
0 Kudos
131

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

Former Member
0 Kudos
131

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