Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

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. 

Example :
REPORT ZSORT_DUPLICATE .
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,
 t_itab1 LIKE SORTED TABLE OF fs_itab WITH UNIQUE KEY fld1.
SELECT-OPTIONS : s_fld1 FOR fs_itab-fld1 NO-DISPLAY.START-OF-SELECTION.
fs_itab-fld1 = 'AA'.
fs_itab-fld2 = 10.
APPEND fs_itab TO t_itab.
fs_itab-fld1 = 'AA'.
fs_itab-fld2 = 10.
APPEND fs_itab TO t_itab.
fs_itab-fld1 = 'AA'.
fs_itab-fld2 = 10.
APPEND fs_itab TO t_itab.
fs_itab-fld1 = 'AA'.
fs_itab-fld2 = 10.
APPEND fs_itab TO t_itab.
fs_itab-fld1 = 'AA'.
fs_itab-fld2 = 10.
APPEND fs_itab TO t_itab.
fs_itab-fld1 = 'BB'.
fs_itab-fld2 = 10.
APPEND fs_itab TO t_itab.
INSERT LINES OF t_itab INTO TABLE t_itab1.
LOOP AT t_itab1 INTO fs_itab.
WRITE : / fs_itab-fld1,fs_itab-fld2.
ENDLOOP.
 
Output --
AA         10
AA         10
AA         10
AA         10
AA         10
BB         10



  • No labels

2 Comments

  1. 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 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." Could you give references about this "problem"? THX

  2. Refer to the forum discussion about this "bug" and on how to avoid it.

     https://forums.sdn.sap.com/thread.jspa?threadID=1380418&tstart=0

     Regards,
    Naimesh Patel