‎2011 Sep 21 9:24 AM
Hello Gurus,
i am using "INSERT" to add new lines to a databank table and i know that the internal table that i use also contains duplicate keys; so i use TRY ENTRY to catch the mentioned exception and still insert the other lines that can be inserted.
My question is if i can somehow retrieve the lines(keys) that couldn't be inserted in the databank without having to do a select.
Regards,
Ioan.
‎2011 Sep 21 9:59 AM
Hi,
Can be done with each record processing, but no idea while inserting with wholw internal table.
loop at it into wa.
TRY.
INSERT ZZZ FROM wa.
CATCH cx_sy_open_sql_db INTO lf_err.
lf_message= lf_err->get_text( ).
ENDTRY.
endloop.
‎2011 Sep 21 9:59 AM
Hi,
Can be done with each record processing, but no idea while inserting with wholw internal table.
loop at it into wa.
TRY.
INSERT ZZZ FROM wa.
CATCH cx_sy_open_sql_db INTO lf_err.
lf_message= lf_err->get_text( ).
ENDTRY.
endloop.
‎2011 Sep 21 10:04 AM
Hello Keshav,
that is what i don't want to do. I don't want to insert every line with loop.
I have something like this:
data lr_cx type ref to cx_root.
try.
insert zzz from table it_zzz.
catch cx_sy_open_sql_db into lr_cx.
commit work.
raise ausnahme.
endtry.
Regards,
Ioan.
‎2011 Sep 21 11:12 AM
Hello Ioan,
As per SAP documentation records will be inserted till the EXCEPTION is triggered!
Alternatively you can try using the addition [ACCEPTING DUPLICATE KEYS|http://help.sap.com/abapdocu_702/en/abapinsert_source.htm#!ABAP_ALTERNATIVE_2@2@].
My question is if i can somehow retrieve the lines(keys) that couldn't be inserted in the databank without having to do a select.
I don't think there is any straight forward way of doing this I still don't understand why you don't perform a DELETE ADJACENT DUPLICATES on your internal table.
BR,
Suhas
‎2011 Sep 21 11:38 AM
Hi Suhas,
i don't have any DUPLICATES in the internal table. I just wanted to know i there is a way for retrieving the lines that were not save using the exception, without having to select to see which lines(keys) are already in the databank.
Something like this:
insert zzz from it_zzz.
catch exception.
lines that were not saved because of duplicate key = exception->lines_not_saved.
Regards,
Ioan.
‎2011 Sep 21 11:48 AM
Hello Ioan,
As per your original post the internal table does contain duplicate records based on the "table key" fields.
i know that the internal table that i use also contains duplicate keys
Anyway if you cannot perform D.A.D based on the table key fields, then i think it's good to use ACCEPTING DUPLICATE KEYS addition. Beacuse SY-SUBRC & SY-DBCNT have defined values.
In your case the SY-SUBRC & SY-DBCNT values are not set by SAP runtime enviroment(read the SAP documentation).
BR,
Suhas
‎2011 Sep 21 11:59 AM
Hello Suhas,
sorry for that. I meant to that i know that some lines in the internal table already exist in the databank so i know that there are lines that it can't insert. I could do a select before the insert to see which lines are already in the databank, delete those lines from the internal table and insert only the lines that i am sure that are not in the databank. I don't want to have any duplicates in the databank table.
I guess there is no way to find the lines that it couldn't insert just by using the exception, i have to do it myself
Kind Regards,
Ioan.
‎2011 Sep 21 12:49 PM
Hi Ioan,
Just an idea... If you use the addition ACCEPTING DUPLICATE KEYS, I think the SY-DBCNT will contain the number of valid entries until duplicate is found (to be check). If so, you can find the duplicate entry by reading the record in your internal table with index SY-DBCNT + 1.
Kr
‎2011 Sep 21 4:38 PM
Hello Ioan,
so i know that there are lines that it can't insert. I could do a select before the insert to see which lines are already in the databank, delete those lines from the internal table and insert only the lines that i am sure that are not in the databank.
Or ... Use MODIFY command, it'll insert new records & overwrite existing ones !!
BR,
Suhas