09-22-2008 9:36 PM
Hi,
I m using Insert stmt to insert the records to ztable from itab.
insert ztable from table itab.
I m getting 'CX_SY_OPEN_SQL_DB' exception bcoz the record with the same key exists in the table. pls let me know how to catch this exception and how to set the message to the user
Thanks
09-22-2008 9:43 PM
Hmmmm... You should get a return code of 4, not a dump if you try to insert a record with a duplicate key.
In any event, use MODIFY instead of INSERT.
Rob
09-22-2008 9:58 PM
Hi,
You can read the table using a Select * using the table key before insterting the record so that if there is a record existing in the table then the sy-subrc will return as 0, then you can catch the exception or insert the record.
Another way is to use MODIFY instead of INSERT statement, this statement inserts the record if there is not record with that key or modifies the records if exists.
Regards,
Trikanth
09-22-2008 10:03 PM
I think it's something else. Can you post your code and dump analysis?
Rob
09-23-2008 5:52 AM
Hi,
The exception 'CX_SY_OPEN_SQL_DB' also occurs if your database table is empty.
Use the TRY..CATCH block to handle the exception (to avoid a dump).
e.g.: to handle a run-time error if the dbtab is empty..
TRY.
select * from ztable.
CATCH CX_SY_OPEN_SQL_DB.
ENDTRY.
insert ztable from table itab.
If the dump occurs even if the dbtab has data in it, then you should check to see if your itab contains rows with identical primary keys..
Regards,
Purnima.
09-23-2008 5:58 AM
Hi,
use the following to set the message to the user:
TRY.
insert ztable from table itab.
CATCH CX_SY_OPEN_SQL_DB.
message "Duplicate Insert due to same key" display like 'E'.
exit.
ENDTRY.
Shruthi