2016 Feb 08 6:45 AM
Hello ABAPER,
I have already searched SCN for similar issue, (post)for related posts although my case seems little different as the line of the table type is a data element (an not a structure with fields).
Scenario:
I am trying to insert into sorted table but facing runtime error of ITAB_DUPLICATE_KEY.
please put some light on this if had similar problem.
For ref: I have attached a snapshot of runtime error from st22 log as below:
Regards,
pavan G
Message was edited by: Pavan Golesar
2016 Feb 08 6:51 AM
2016 Feb 08 7:57 AM
Thanks for quick reply,
Data Declaration of structure:
DATA lt_header_guid TYPE crmt_object_guid_tab.
**** Souce code*
insert wa to table it.
Regards,
Pavan G
2016 Feb 08 9:01 AM
Yes it a non-unique key based sorted table and line of error is as below:
--PG
2016 Feb 08 1:27 PM
Look at the definition of parameter et_orderadm_h in the FM which dumps, and not at your lt_header_guid internal table.
Exceptions
Catchable Exceptions
CX_SY_ITAB_DUPLICATE_KEY
- Cause: Duplicate key values in unique secondary key
Runtime Error: ITAB_DUPLICATE_KEY
Non-Catchable Exceptions
- Cause: When inserting a set of rows, entries with an identical key were produced (the target table is defined by UNIQUE).
Runtime Error: ITAB_DUPLICATE_KEY
- Cause: Sort order violated when using an INSERT with index in a sorted table.
Runtime Error:ITAB_ILLEGAL_SORT_ORDER
- Cause: Invalid index value (<= 0) when FROM, TO, or INDEX specified
Runtime Error:TABLE_INVALID_INDEX
Regards,
Raymond
2016 Feb 08 7:00 AM
Hi ,
Just show your code , how u declared the table/Structure please .
2016 Feb 08 8:00 AM
Thanks sabir,
As mentioned above, the table type crmt_object_guid_tab is based on a DATA ELEMENT.
In this case how to pass the NON-unique key condition to the abap statement below..
insert wa to it.
Thanks,
Pavan G
2016 Feb 08 8:14 AM
You got 2 simple choices based by Raymond question
Did you declare the table key as UNIQUE or NON-UNIQUE?If you declared the table key as UNIQUE, before the insert, you have to read the internal table to check if key already exist and only if not exist, then insert (and i think you are in this condition).
If you declared NON-UNIQUE, you should have no problem.
2016 Feb 08 8:58 AM
Absolutely,
I'm referring to standard table type which is of type sorted with non-unique key.
--PG
2016 Feb 08 9:05 AM
Sorry for the silly question, i couldn't check myself since in my system i do not have that table type
Anyway, replace INSERT with APPEND and, magic!, it works
Check my below example program
2016 Feb 08 9:13 AM
2016 Feb 08 1:04 PM
Umm, I had tried it earlier hence I am pushed to use Insert statemet,
Ya, It would have helped only if table type was standard table and not the SORTED TABLE (as in my case)
Since the table type is have type as SORTED table, (as per SAP DUMP help) It will not accept the append condition...
Error while inserting or changing rows in a sorted table
Regards,
PavanG
2016 Feb 08 1:09 PM
2016 Feb 08 1:24 PM
From the screenshot the table type CRMT_OBJECT_GUID_TAB is a standard table. Can you check the "secondary" keys tab? I think secondary keys are defined for this table type.
Can you please check & confirm?
2016 Feb 09 4:40 AM
2016 Feb 09 5:09 AM
Hence now If I jump back to insert statement I am able to push entries to the Sorted table:
insert l_crmt_object_guid inTO TABLE lt_header_guid

Although I get other issue saying below error with different line from standard FM CRM_ORDER_READ:
A row already exists with this key
--Pavan G
Message was edited by: Pavan Golesar
2016 Feb 09 5:36 AM
Your error occurs, according to the dump, in SAPLCRM_ORDER_ON. That's standard SAP code, which obviously you can't change. Have you search in service.sap.com
Are you reusing some SAP code? The problem could be you calling the SAP code with bad data, for example. As Raymond has pointed out, the issue is with et_orderadm_h - what is the data definition of that?
I think we need rather more context.
2016 Feb 09 6:04 AM
Yes Matthew, Issue is with et_orderadm_h table (which is of type seen in below image)..
After I looked closely, Found that it is having a UNIQUE KEY GUID (Sorted Table)...
On Runtime time I check the contents of tables passed..
It does give the dump on row already exists with KEY..so I checked the contents of GUID (on Second iteration) and it is indeed Different.. then I wonder why the DUMP is occurring...
Regards,
PG
2016 Feb 09 6:48 AM
Are you calling this SAP function module from your own code?
If not, unless you are the analyst working for SAP to fix this issue, you really should stop analysis now and report to SAP. Since this is SAP code you can't fix it yourself.
If you are, please post the relevant parts of your code.