Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Error in inserting or changing rows in a sorted table

Pavan_Golesar
Active Participant
15,548

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

18 REPLIES 18
Read only

RaymondGiuseppi
Active Contributor
0 Likes
10,338

Did you declare the table key as UNIQUE or NON-UNIQUE?

Which statement syntax did you use for the insert?

Regards,

Raymond

Read only

0 Likes
10,338

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

Read only

0 Likes
10,337

Yes it a non-unique key based sorted table and line of error is as below:

--PG

Read only

0 Likes
10,337

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

Read only

sabirshah1
Participant
0 Likes
10,337

Hi ,

Just show your code , how u declared the table/Structure please .

Read only

0 Likes
10,337

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

Read only

0 Likes
10,337

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.

Read only

0 Likes
10,337

Absolutely,

I'm referring to standard table type which is of type sorted with non-unique key.

--PG

Read only

0 Likes
10,337

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

Read only

0 Likes
10,337

This message was moderated.

Read only

0 Likes
10,337

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

Read only

0 Likes
10,337

This message was moderated.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
10,337

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?

Read only

0 Likes
10,337

No, Below is screenshot from SAP:

Regards,

Pavan G

Read only

0 Likes
10,333

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

Read only

matt
Active Contributor
0 Likes
10,333

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.

Read only

Pavan_Golesar
Active Participant
0 Likes
10,333

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

Read only

matt
Active Contributor
0 Likes
10,333

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.