2010 Dec 30 5:08 AM
I have created a table ztable with fields field1,field2,field3,field4,field5,field6.
the key fields are field1,field2,field3,field4,field5.
Records in ztable:
FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6
1 2 3 4 5 6
1 2 3 5 6 7
now i want to modify 1st row with field4 = 9.
and second row with field 4 = 10.
Please suggest how can i update field4.
since field 4 is a key field new line are inserted .
FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6
1 2 3 4 5 6 ....................................old
1 2 3 5 6 7................................old
1 2 3 9 5 6..............................new
1 2 3 9 6 7.............................new
Could anyone help me with a soultion.
Regards,
Rachel
Edited by: Rachel@sap on Dec 30, 2010 6:10 AM
2010 Dec 30 5:41 AM
Hello Rachel,
Your requirement violates the basic principle of RDBMS. All the key fields(of a composite key) form a key which is used to identify a record uniquely.
If you modify a key field, you'll generate a new record with the modified key fields & not overwrite the old one!
So you need to:
1. INSERT / MODIFY the DB table with the modified key field.
2. DELETE the record with the old key field.
Hope i'm clear.
BR,
Suhas
I have created a table ztable with fields field1,field2,field3,field4,field5,field6.
the key fields are field1,field2,field3,field4,field5.
Records in ztable:
FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6
1 2 3 4 5 6
1 2 3 5 6 7
now i want to modify 1st row with field4 = 9.
and second row with field 4 = 10.
Please suggest how can i update field4.
since field 4 is a key field new line are inserted .
FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6
1 2 3 4 5 6 ....................................old
1 2 3 5 6 7................................old
1 2 3 9 5 6..............................new
1 2 3 9 6 7.............................new
Could anyone help me with a soultion.
Regards,
Rachel
Edited by: Rachel@sap on Dec 30, 2010 6:10 AM
2010 Dec 30 5:16 AM
Rachel,
You can use the UPDATE statement to update the KEY FIELDS.
UPDATE ztable)
SET field4 = 1
WHERE field1 = ''
and field2 = ''. " Tip- in the where clause add all the key fields
Regards,
Madhukar Shetty
2016 Oct 05 3:28 PM
I know I'm reviving a dead post six years later... But isn't this the right answer for the question asked...??? Please remark if possible.. Helped me in a tight spot.
2010 Dec 30 5:25 AM
hi Rachel
first you need to select the values from z table into an internal table with similar structure.
then loo through internal table with index.
like
loop at itab into wa.
data; l_index type sy-tabix.
l_index = sy-tabix.
field4 = 9.
modify itab from wa index l_index transporting field4.
endloop.
But this will modify all the values of field4 to value 4.
and the rows will be the same.
then insert the values of internal table itab to your Z table. but before that delete all the values from z table because afterall you are going to update it again from internal table.
or check if it is not necessary to delete the values from z table.
thanks
lalit
2010 Dec 30 5:37 AM
Hi,
Please loop the z table move all the key fiel values to another variable/temp structure, (give ur new value too)
loop at ztab
temtab-field1 = 1.
temptab-field2 = 2.
temptab-field3 = 3.
tempfab-field4 = 9.
MODIFY ztab FROM temptab
TRANSPORTING field1 field2 field3 field4 WHERE field1 EQ temptab-field1
AND field2 EQ temptab-field2
AND field3 EQ temptab-field3.
endloop ztab.
Remember you have to give all the key fields in the modify statement.
regards
Mullai
2010 Dec 30 5:41 AM
Hello Rachel,
Your requirement violates the basic principle of RDBMS. All the key fields(of a composite key) form a key which is used to identify a record uniquely.
If you modify a key field, you'll generate a new record with the modified key fields & not overwrite the old one!
So you need to:
1. INSERT / MODIFY the DB table with the modified key field.
2. DELETE the record with the old key field.
Hope i'm clear.
BR,
Suhas
2010 Dec 30 5:55 AM
Hi Rachel
You sholud not update the keyfields. Then it will create new record with updated keyfield. It should not be happened , so try to Insert or Modify or Delete the keyfield.
So that you can get the new record with updated keyfield.
Edited by: renu1ece on Dec 30, 2010 6:56 AM
2010 Dec 30 6:15 AM
Hi Rachel,
As you want to change the key fields of the ZTABLE the only way is to insert a new record(with the new key) and delete the previous one(if not required).
Please go through the link below for Easy user interface(Provided you have authorisation for the same)
Link:[Easiest way to Edit table but be cautious|http://www.kowboyz.nl/blog/edit-sap-tables/]
Hope it helps you,
Regards,
Abhijit G. Borkar
2010 Dec 30 11:48 AM
2010 Dec 30 12:47 PM
Hey Rachel,
I think you forgot something.
Regards,
Abhijit G. Borkar
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |