Application Development and Automation 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: 
Read only

insert data into db table

Former Member
0 Likes
1,967

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..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,783

i think u r inserting with same primary key value ,if u do so it will overwrite the first data .

9 REPLIES 9
Read only

Former Member
0 Likes
1,783

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

Read only

0 Likes
1,783

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.

Read only

0 Likes
1,783

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

Read only

Former Member
0 Likes
1,783

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

Read only

Former Member
0 Likes
1,783

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

Read only

Former Member
0 Likes
1,783

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

Read only

Former Member
0 Likes
1,783

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

Read only

Former Member
0 Likes
1,783

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

Read only

Former Member
0 Likes
1,784

i think u r inserting with same primary key value ,if u do so it will overwrite the first data .