cancel
Showing results for 
Search instead for 
Did you mean: 

Update table

Former Member
0 Kudos

Hello,

I am trying to update a table which contains only 4 fields ( all are key fields ). I have generated a maintenance view and trying to change the value in the field and updating the main table. But all fields are defined as key fields, due to this update getting failing.

Is there any other way to achieve this.

Thanks,Srini

Accepted Solutions (0)

Answers (7)

Answers (7)

Former Member
0 Kudos

You might not want to do this, but in order to do what you want, you could:

Add a new key field to the table at the beginning (after the client) and give it a domain like BENLNR.

Change the other fields to non key.

In the table maintenance dialogue, use one of the events to retrieve a new number using one of the number range FMs.

Rob

Former Member
0 Kudos

Hi please do as follows.

1. get the row which u want to update into a work area.

2. delete the corresponding record from the table.

3. modify the work are with the new values.

4. insert the work are into the table.

satish

Former Member
0 Kudos

Hi Sri nivas,

Primary key is defined to uniquely identify a record in the table.

Since your table has four fields (all four constitute a composite primary key), there is NO WAY you can update or change any value of an already existing record.

Regards,

Raj

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

In Abap program,you can modify the value.

update dbtable set f1 = value1 where f2 = value2.

Or you can use modify command.This will insert the new value,if it doesn't already exists or it will update the value if the value exists already.

modify dbtable from table itab.

Populate the modified value in the internal table itab.

Kindly reward points by clikcing the star on the left of reply,if it helps.

former_member181962
Active Contributor
0 Kudos

Hi Srinivas,

I think it is not possible to update the records as fellow members also say.

As an alternative, you can insert a new record and delete the old one. Please let us know if this is what you wanted.

Regrads,

Ravi

Former Member
0 Kudos

Hi Sri Nivas,

i don't thonk it's possible to UPDATE in your case.

As from following doc(F1 on UPDATE)

If, in the database,<b> there is no row with the same content of the primary key for a row in the internal table</b>, or if the change would lead to a double entry in a unique secondary key, <b>the respective row is not changed </b>and sy-subrc is set to 4. If the internal table is empty, sy-subrc is set to 0. The system field sy-dbcnt is always set to the number of rows actually inserted.

I think You might have to choose other way.

Regards,

Amit

Former Member
0 Kudos

Sri nivas,

I hope this cannot be done on the Maintenance View. U can see all the Key fields will be grayed out.

Develop a program in ABAP to modify the records!!!

Thanks

Kam

Former Member
0 Kudos

Hi Kam,

Thanks for your reply.

Even in program also we need to use same Update command. So it might not be possible. Is there any other way to update the values in the table having all key fields.

Any help greatly appreciated.

Thanks, Srinivas

Former Member
0 Kudos

Sri nivas,

See the sample program:

REPORT ZZ123 .

data:

wa type ZABDCEF,

wa1 type ZABDCEF,

  • All the original Database records

iAbcdef type table of ZABDCEF,

  • Modified records to be updated in the DB

iFinal type table of ZABDCEF,

  • Records to be removed from the database

iTemp type table of ZABDCEF.

  • get all the records

select * from ZABDCEF into table iAbcdef.

loop at iAbcdef into wa.

if wa-zfield1 = 'B'.

  • Collect the records that are to deleted

<b>append wa to iTemp.</b>

move wa to wa1.

wa1-zfield1 = 'A'.

  • Modifed records

<b>append wa1 to iFinal.</b>

endif.

endloop.

  • First delete the existing records that are to be modified

<b>DELETE ZABDCEF FROM TABLE iTemp.</b>

  • Inswert the modified records

<b>modify ZABDCEF from table iFinal.</b>

Thanks

Kam

Note : Allot points for all Worthful postings

Message was edited by: Kam

Former Member
0 Kudos

Hi Sri Nivas,

There is no single step method to do this. What you can do is

1) Select the records for which you want to change the values of the key fields.

2) Copy them. This will create new records with all the fields open for input.

3) Change the values of the key fields and save.

4) Now delete the old records.

Even if you use a program, this is what you will have to do, but at least in a program, it will be transparent to the user, whereas in SM30, user has to do this.

Srinivas

Former Member
0 Kudos

Hi,

I agree with what srinivas adavi say but what I suggest you is AFTER COPYING THE RECORD YOU WANT TO CHANGE,

DELETE THE RECORD FROM THE TABLE AND THEN CHANGE THE RECORD ACCORDING TO YOUR REQUIREMENT AND THEN INSERT IT.

HOPE THIS WILL SERVE YOUR PURPOSE.