‎2006 Oct 18 3:24 PM
Hi all,
I've a query regarding the modifying of a data base table directly ( that means without taking the values into the internal table) for a field, particulary when the field is a primary key.
eg: in a field called RICE the initial value is given as '120'. now i want to change it into a new value 'SAP'.
this RICE field is made as a primary key.
please tell me the solution.
Sailaja.
‎2006 Oct 18 3:31 PM
Instead of updating the key field, you can add one more record ans delete the existing one which makes more sense.
insert ztab from ztab.
delete ztab where key = '120'.
Regards,
ravi
‎2006 Oct 18 3:26 PM
Please use UPDATE
UPDATE (table)SET RICE = 'SAP'
where condition
‎2006 Oct 18 3:28 PM
You cannot change the value of a key field. Select to internal table, update data in internal table and insert into db. Then delete records initially selected.
‎2006 Oct 18 3:36 PM
Sailaja,
Michael's statement is not, in fact, true in all cases. It depends on the underlying DB system. I just changed a primary key in one of custom tables.
HOWEVER, it is wonderful advice. The primary key should be a unique identifer of a record. IF a record's unique identifier changes (which SHOULD NOT be the case if the table is built cleanly/correctly), you should follow Michael's advice. Create a new record with the new key and then delete the previous.
‎2006 Oct 18 3:45 PM
thanks for all ur reply's.even i tried doing the same like inseting and later deleting but my client dont want me to delete the records...
‎2006 Oct 18 3:55 PM
‎2006 Oct 18 4:29 PM
Sailaja,
Then your client should NOT have a table with key fields that are prone to change!! That is a bad design. I assume that this is a custom table?
And their request to you is, in practice, "deleting" the record... once a primary key is altered... the initial record's uniqueness has been destroyed.
Don't forget points for helpful answers as well.
‎2006 Oct 18 4:36 PM
I find this odd. I thought the whole idea behind open SQL is that it should behave the same no matter what the type of database.
What database are you using? You didn't use native SQL to do the update did you?
Rob
‎2006 Oct 18 4:37 PM
If you change the primary key and update the table it would insert a new record, hence you would need to delete the old record unless you wish to keep in the table with some flag indicator.
Apart from the above there is no other alternative.
‎2006 Oct 18 4:45 PM
Sailaja,
IF this is a core table (not a custom Y or Z table)... do not perform this request. You run a high risk of damaging the referential integrity of the client's database.
If it is a core table, take this request to your manager for assistance... this client will need some "Database 101" training first.
‎2006 Oct 18 5:05 PM
Rob,
Was this question for Sailaja?
"I find this odd. I thought the whole idea behind open SQL is that it should behave the same no matter what the type of database.
What database are you using? You didn't use native SQL to do the update did you?"
‎2006 Oct 18 5:10 PM
‎2006 Oct 18 5:22 PM
No it was performed thru Open SQL.
Open SQL is a database interface to your DB engine. It creates/generates native SQL that your DB engine understands. It does not, however, enforce all of the rules, settings, etc that your DBAs have set up at the "true" database layer of the R/3 client-server model.
‎2006 Oct 18 5:23 PM
‎2006 Oct 18 5:32 PM
John - that would mean that ABAP code behaves differently for different databases and therefore not "transportable".
We were on Oracle up to a couple of years ago and it wouldn't let us change primary keys. Are you saying that there are database settings that would allow this? (And that the SAP kernel can read to allow or disallow changes to primary keys?)
Rob
‎2006 Oct 18 5:40 PM
Rob,
"that would mean that ABAP code behaves differently for different databases and therefore not "transportable"."
ABAP code behaves the same... the underlying objects, in this case, the DB engine itself behaves according to the parameters that the DBAs have set - which can be different from implementation to implementation.
And this setting is outside of the SAP kernel... it is truly on the DB itself. Bear in mind that this is 3-tiered client-server model... and each piece can be adjusted (sometimes without the other pieces "knowing").
‎2006 Oct 18 5:51 PM
John - but you said that you changed the key. The rest of us can't. Or am I just not understanding?
Rob
‎2006 Oct 18 6:02 PM
John - <i>mea culpa</i>. I just did what I thought was not possible. I created a table, inserted a record and then changed the key field of that record (DB2).
rob
‎2006 Oct 18 6:05 PM
Enjoy.
It is probably NOT a good thing... but it is possible b/c the DB is TRULY separated from SAP R/3.
‎2006 Oct 18 6:06 PM
‎2006 Oct 18 6:07 PM
‎2006 Oct 18 6:18 PM
You sure did. But there's something else going on here as well. I want to do a bit more digging.
Rob
‎2006 Oct 18 6:49 PM
Well, it looks as if you can do exactly what you want. The only restriction I can see is from the help on the UPDATE command:
you cannot change the primary key
when you UPDATE a table for which a synchronous matchcode
is defined.
But whether or not you should do this is between you your client and the auditors.
Rob
‎2006 Oct 18 6:57 PM
But again... you must ask WHY a unique key needs to be destroyed? Any data field like this should NOT be part of a primary key... it should become a non-keyed field. In this case, it seems that the customer has built a poor table. They would be best to look into retiring this table and creating/using a properly, built table with a "nice" primary key. Perhaps a GUID if nothing else... it is unique...
‎2006 Oct 18 3:31 PM
Instead of updating the key field, you can add one more record ans delete the existing one which makes more sense.
insert ztab from ztab.
delete ztab where key = '120'.
Regards,
ravi
‎2006 Oct 18 6:26 PM
Rob,
Send any follow-up to:
I think we have used this thread enough today.
Sailaja,
Anything else from your end? If not, please close the thread at your convenience.