Application Development 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: 

abap bug? insert lines of ... into (sorted unique) table creates duplicates

Sandra_Rossi
Active Contributor
0 Kudos

Hello,

what I read in this wiki (https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/sorted+UniqueTablewithnon-unique++entries) was very much surprising : it says that "If we insert entries of a sorted table ( unique or non-unique ) to a sorted unique empty table by INSERT LINES OF t_itab INTO TABLE t_itab1 statement , the target table would be populated with duplicate entries if any." (the 2 conditions in bold MUST BE true).

I thought an internal table with unique key couldn't have duplicates of course. But this wiki is right! TRY IT!

How does SAP consider that, is this a bug, or is it a bug in SAP documentation (http://help.sap.com/saphelp_nw70/helpdata/EN/fc/eb361f358411d1829f0000e829fbfe/content.htm) because it doesn't specify this exception ; it just says "The system inserts the lines of table itab1 one by one into table itab2 using the same rules as for single lines."

For single lines, the same SAP library says "If the internal table has a unique key, lines whose key already exists in the table will not be inserted and sy-subrc is set to 4."

Do you have a SAP URL or SAP note which explains that ?

Thank you for your opinion and inputs!

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos

Good finding..

Seriously, it would be a problem. The WIKI program inserts data into the SORTED UNIQUE table.

But, I tried with different type of tables other than the SORTED NON-UNIQUE table like STANDARD TABLE OF, TABLE OF and I got the Short-dump (as expected) ITAB_DUPLICATE_KEY.


DATA:
BEGIN OF fs_itab,
fld1(2) TYPE c,
fld2 TYPE i,
END OF fs_itab,
* t_itab LIKE SORTED TABLE OF fs_itab WITH NON-UNIQUE KEY fld1, " No Error
* t_itab LIKE standard TABLE OF fs_itab, " Shortdump
 t_itab LIKE TABLE OF fs_itab, " Shortdump
 t_itab1 LIKE SORTED TABLE OF fs_itab WITH UNIQUE KEY fld1.

Regards,

Naimesh Patel

2 REPLIES 2

naimesh_patel
Active Contributor
0 Kudos

Good finding..

Seriously, it would be a problem. The WIKI program inserts data into the SORTED UNIQUE table.

But, I tried with different type of tables other than the SORTED NON-UNIQUE table like STANDARD TABLE OF, TABLE OF and I got the Short-dump (as expected) ITAB_DUPLICATE_KEY.


DATA:
BEGIN OF fs_itab,
fld1(2) TYPE c,
fld2 TYPE i,
END OF fs_itab,
* t_itab LIKE SORTED TABLE OF fs_itab WITH NON-UNIQUE KEY fld1, " No Error
* t_itab LIKE standard TABLE OF fs_itab, " Shortdump
 t_itab LIKE TABLE OF fs_itab, " Shortdump
 t_itab1 LIKE SORTED TABLE OF fs_itab WITH UNIQUE KEY fld1.

Regards,

Naimesh Patel

0 Kudos

thx Naimesh