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

how to update key fields for table

Former Member
0 Likes
4,677

Hi,

how to update key fields for a table.The update statement is not working for the same.

Regards,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,716

You have to delete and insert new entry.

5 REPLIES 5
Read only

Former Member
0 Likes
2,717

You have to delete and insert new entry.

Read only

Former Member
0 Likes
2,716

Hi,

You can not update key fields of a table.

Regards,

Pranaya

Read only

Former Member
0 Likes
2,716

Key fields cannot be updated. Delete and create the records

Regards

Vinod

Read only

Former Member
0 Likes
2,716

Hi,

See the below example.

TABLES SPFLI.

DATA WA TYPE SPFLI.

MOVE 'AA' TO WA-CARRID.

MOVE '0064' TO WA-CONNID.

MOVE 'WASHINGTON' TO WA-CITYFROM.

...

UPDATE SPFLI FROM WA.

MOVE 'LH' TO SPFLI-CARRID.

MOVE '0017' TO SPFLI-CONNID.

MOVE 'BERLIN' TO SPFLI-CITYFROM.

...

UPDATE SPFLI.

CARRID and CONNID are the primary key fields of table SPFLI. All fields of those lines where the primary key fields are "AA" and "0064", or "LH" and "0017", are replaced by the values in the corresponding fields of the work area WA or the table work area SPFLI.

Regards,

raj.

Read only

RaymondGiuseppi
Active Contributor
2,716

You must rely on an UPDATE SET WHERE to change primary keys, else use DELETE/INSERT. cause Open SQL use the value of the primary keys of the work area to identify records to update in the other alternatives of the statement.

Even with UPDATE SET WHERE, primary keys can only be changed if the respective database table is not linked with a search help and if pool and cluster tables are not accessed. ([ref|http://help.sap.com/abapdocu_70/en/ABAPUPDATE_SOURCE.htm#!ABAP_ALTERNATIVE_1@1@])

Regards,

Raymond