‎2007 May 08 10:52 PM
hi frends,
i need to insert the data into the DB table. i am able to insert one one record. but when i try to insert another record ie another single row with only 2 fields different, its deleting my previous record and overwriting it. i could only insert one row at a time.pls guide me to slove my problm..thanx in advance..
‎2007 May 09 7:19 AM
i think u r inserting with same primary key value ,if u do so it will overwrite the first data .
‎2007 May 08 10:56 PM
Hi rahul,
If you are trying to insert a new record with same key fields, then it will overwrite the old.
YOu have to pass a new key combination for the record.
Or you should use
accepting duplicate keys addition with the insert statement.
Regards,
Ravi
‎2007 May 08 11:01 PM
thanx a lot for the solution. but i am using insert dbtable from table it_tab accepting duplicate entries. but still i could not enter the second record.for eg..
my first record is xxxx yyyy 1111
second record is xxxx yyyy 2222.
first time its inserting correctly but when i try to insert the second record its overwriting the first one.dont mind please go through my code..and help me please..
here is my code...
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETER: USERROLE LIKE AGR_1251-AGR_NAME.
ORGVALUE LIKE AGR_1251-FIELD.
SELECT-OPTIONS: ORGVALUE FOR AGR_1251-FIELD,
LOWVAL FOR PT1252-LOW.
SELECTION-SCREEN END OF BLOCK B1.
CONCATENATE '$' ORGVALUE-LOW INTO ORGVALUE.
LOOP AT LOWVAL.
ORGLEVELS-VARBL = ORGVALUE.
ORGLEVELS-LOW = LOWVAL-LOW.
ORGLEVELS-HIGH = LOWVAL-HIGH.
APPEND ORGLEVELS.
ENDLOOP.
BREAK NTHOTA.
LOOP AT ORGLEVELS.
MAXCOUNTER = MAXCOUNTER + 1.
MOVE-CORRESPONDING ORGLEVELS TO I_AGR_1252.
I_AGR_1252-COUNTER = MAXCOUNTER.
I_AGR_1252-MANDT = SY-MANDT.
I_AGR_1252-AGR_NAME = USERROLE.
APPEND I_AGR_1252.
IF SY-SUBRC <> 0.
WRITE / 'no updates'.
ENDIF.
ENDLOOP.
BREAK-POINT.
DELETE AGR_1252 FROM TABLE I_AGR_1252.
IF SY-SUBRC EQ 0.
WRITE:/ 'deleted'.
ENDIF.
INSERT AGR_1252 FROM TABLE I_AGR_1252 ACCEPTING DUPLICATE KEYS.
modify agr_1252 from table i_agr_1252.
IF SY-SUBRC EQ 0.
WRITE:/ 'inserted'.
ENDIF.
CLEAR I_AGR_1252.
REFRESH I_AGR_1252.
COMMIT WORK.
‎2007 May 08 11:50 PM
Check in your DB table xxxx yyyy 1111 these fields should be primary key.
It seams that you have only xxxx yyyy fields defined as a primary key fields.
Regards,
Amey
‎2007 May 08 10:58 PM
Hi,
I believe you are using MODIFY statement to insert records..Because MODIFY will insert if there is no record for the key combination and INSERT record if there is a record for the key combination..
So in your case...The key field values has to be different to create a new record in the table..
Thanks,
Naren
‎2007 May 09 5:11 AM
hi,
I think you have defined only xxxx yyyy fields as primary key.
along with xxxx yyyy keep 1111 also a key field.
Reward points if it is helpful.
Regards,
Sangeetha.A
‎2007 May 09 5:34 AM
Hi Rahul,
If u r trying to insert a record with same primary key fields.
It will overwrite the record.
I think ur first two field are primary fields.therefore no record will exists with same key fields.U make ur third field as primary field.then it will work.
Reward points if helpful.
Regards,
Hemant
‎2007 May 09 5:42 AM
HI Rahul,
If you want to insert record in the database table then you should be care ful with these things,
you should table the primary keys as the reference for joining. i.e. you should have the rpimary keys populated in the internal table.
for modifying i.e. if you want to modify only with some fields then please use..
modify dbtable transporing that fields.
I think this will do for the datbase tables.
Regards,
Jayant
Please award if helpful
‎2007 May 09 5:48 AM
HI Rahul.
You cannot enter the data as you are saying , that way ... beacuse if you are having two key in the database table ... in you case the values caooespongding to that field are 'XXX' and 'YYY'
Then you can have only one value in the third field and if you try any other operation then it will definitely replace the old entry....
i.e. XXX YYY 111
XXX YYY 222 ; THIS THING IS NOT POSSIBLE KEEPING FIELDS FOR XXX AND YYY AS KEY FIELDS......
Regards,
Jayant
‎2007 May 09 7:19 AM
i think u r inserting with same primary key value ,if u do so it will overwrite the first data .