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

Updating database table from an internal table

Former Member
0 Likes
3,605

Hi All,

I am updating a database table from an internal table.

I am changing the non-key fields in that table.

when I check sy-subrc = 4.

Record already exists, because I am changing non-key fields of the

database table.

Is there any addition like to accept the duplicate keys with update.

Alternatively, I have used Modify, It is adding new record,

Again, I have search the old record and use Delete on the database table.

Thanks & Regards,

Kalyan Chandramouli

SAP ABAP Consultant

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,055

It seems that you changed key fields, else MODIFY wont create new records?

Look at your Z-table (I hope this is a Z-table, no?) is there an alternative index with unique key?

Regards

Hi All,

I am updating a database table from an internal table.

I am changing the non-key fields in that table.

when I check sy-subrc = 4.

Record already exists, because I am changing non-key fields of the

database table.

Is there any addition like to accept the duplicate keys with update.

Alternatively, I have used Modify, It is adding new record,

Again, I have search the old record and use Delete on the database table.

Thanks & Regards,

Kalyan Chandramouli

SAP ABAP Consultant

6 REPLIES 6
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,056

It seems that you changed key fields, else MODIFY wont create new records?

Look at your Z-table (I hope this is a Z-table, no?) is there an alternative index with unique key?

Regards

Read only

Former Member
0 Likes
1,055

HI,

You can use the UPDATE statment, but as we know, if the key fields are same then it will update that record, if the key fields are not same then it will add a record to the database table

Regards

Sudher

Read only

Former Member
0 Likes
1,055

Hi,

You are right, the field which I am trying to change is a part of primary key.

Because, sy-subrc = 4. says,

No line with specified primary key exits in the database table.

I have a Z-tabel, with Kunnr Vkorg Matnr Bzirk Bztxt Split_percentage

In this table primary key consists of KunnrVkorgMatnr+Bzirk.

I am able to change the Split_percentage using UPDATE.

Now, my client want to change Bzirk, Bztxt also in the table.

How can I Go.

Thanks & Regards,

Kalyan Chandramouli

SAP ABAP Consultant

Read only

0 Likes
1,055

You can not update when changing primary key, so you need to delete the database from the <b>old</b> values of your internal table and then insert from the <b>new</b> values.

Regards

Read only

0 Likes
1,055

hi

This is the way to update ur Table in this Scenario.

From internal table to DB table.

data : itab type table of <ur Ztable> with header line.

<<Fill the Data into the itab>> . "Key fields must also be filled

UPDATE <ZTABLE> FROM TABLE ITAB .

REWARD IF HELPFUL.

Read only

Former Member
0 Likes
1,055

Using Update we can change only non-key fields,

Kalyan Chandramouli