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

Runtime Errors ITAB_DUPLICATE_KEY In ALV Report

Former Member
0 Likes
741

Hi,

Tried various hit and trial but this dump didn't get removed, plase help.

Runtime Errors         ITAB_DUPLICATE_KEY
Date and Time          2012-10-19 07:57:09

Short text
     A row with the same key already exists.

What happened?
     Error in the ABAP Application Program

     The current ABAP program "ZFIAAR_INVLIST_ALV01" had to be terminated because it
      has
     come across a statement that unfortunately cannot be executed.

Error analysis
     An entry was to be entered into the table
      "\PROGRAM=ZFIAAR_INVLIST_ALV01\DATA=I_COST" (which should have
     had a unique table key (UNIQUE KEY)).
     However, there already existed a line with an identical key.

     The insert-operation could have ocurred as a result of an INSERT- or
     MOVE command, or in conjunction with a SELECT ... INTO.

     The statement "INSERT INITIAL LINE ..." cannot be used to insert several
      initial lines into a table with a unique key.

Trigger Location of Runtime Error
    Program                                 ZFIAAR_INVLIST_ALV01
    Include                                 ZFIAAN_INVLIST_ALV01_FORMS
    Row                                     1,921
    Module type                             (FORM)
    Module Name                             F_AUTHORITY_CHECK

  1891   ELSEIF l_exit = space.
1892     p_vari = wl_variant2-variant.
1893   ENDIF.
1894
1895 ENDFORM.                    " F_SHOW_LIST_OF_VARIANTS
1896 *&---------------------------------------------------------------------*
1897 *&      Form  F_AUTHORITY_CHECK
1898 *&---------------------------------------------------------------------*
1899 *       text
1900 *----------------------------------------------------------------------*
1901 *  -->  p1        text
1902 *  <--  p2        text
1903 *----------------------------------------------------------------------*
1904 form F_AUTHORITY_CHECK .
1905
1906   SELECT bukrs ktopl periv
1907        FROM t001 INTO TABLE i_t001
1908        WHERE bukrs IN s_bukrs.
1909   IF sy-subrc IS NOT INITIAL.
1910     MESSAGE e000 WITH text-130.
1911   ELSE.
1912
1913 *** Select Asset Class
1914     IF s_anlkl[] IS NOT INITIAL.
1915       SELECT anlkl FROM anka INTO TABLE i_anka
1916                    WHERE anlkl IN s_anlkl.
1917     ENDIF.
1918
1919 *** Select Cost Center
1920     IF s_kostl[] IS NOT INITIAL.
>>>>>       SELECT kostl FROM csks INTO TABLE i_cost
1922                    WHERE kostl IN s_kostl.
1923     ENDIF.
1924
1925 *** Select Plant
1926     IF s_werks[] IS NOT INITIAL.
1927       SELECT werks FROM t001w INTO TABLE i_t001w
1928                    WHERE werks IN s_werks.
1929     ENDIF.
1930
1931     LOOP AT i_t001 INTO wa_t001.
1932
1933 *** Authorization object Asset class
1934       PERFORM f_auth_object_anlkl.
1935
1936 *** Authorization object Cost center
1937       PERFORM f_auth_object_kostl.
1938
1939 *** Authorization object Plant
1940       PERFORM f_auth_object_werks.

In TOP Include:

TYPES: BEGIN OF tp_cskt,
               spras TYPE cskt-spras,
               kokrs TYPE cskt-kokrs,
               kostl TYPE cskt-kostl,
               ltext TYPE cskt-ltext,
            END OF tp_cskt,

     

           BEGIN OF tp_cost,                          "Cost Center Master Data
               kostl TYPE csks-kostl,                     "Cost Center
           END OF tp_cost.

DATA: i_cskt TYPE STANDARD TABLE OF tp_cskt,
          wa_cskt TYPE tp_cskt,

          i_cost      TYPE SORTED TABLE OF tp_cost
                         WITH UNIQUE KEY kostl,
          wa_cost     TYPE tp_cost.

In FORMS Include:

SORT: i_cskt BY  kostl,
            i_ankt BY anlkl.

3 REPLIES 3
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
608

Look into the declaration of i_cost, KOSTL is defined as unique, but the select query appends non unique values.  Read the sap help for sorted internal tables.In only becomes unique if you add KOKRS and DATBI.

Un-marking this discussion as a question due to its basic nature.

Read only

0 Likes
608

If this was the case i_anka sould also show a dump but it is not. Both i_anka and i_cost have the same declaration and select.

In TOP Include.

Types:BEGIN OF tp_anka,
        anlkl TYPE anlkl,
      END OF tp_anka,

      BEGIN OF tp_cost,                          "Cost Center Master Data
*       kostl TYPE csks-kostl,                     "Cost Center
        kostl TYPE kostl,
      END OF tp_cost.

Data:i_anka TYPE SORTED TABLE OF tp_anka
            WITH UNIQUE KEY anlkl,

      wa_anka TYPE tp_anka,

     i_cost TYPE SORTED TABLE OF tp_cost
            WITH UNIQUE KEY kostl,
      wa_cost TYPE tp_cost.

In FORMS include.

*** Select Asset Class
    IF s_anlkl[] IS NOT INITIAL.
      SELECT anlkl FROM anka INTO TABLE i_anka
                   WHERE anlkl IN s_anlkl.
    ENDIF.

*** Select Cost Center
    IF s_kostl[] IS NOT INITIAL.
      SELECT kostl FROM csks INTO TABLE i_cost
                   WHERE kostl IN s_kostl.
    ENDIF.

Read only

0 Likes
608

In ANKA , ANLKL is the only key field, so it is always unique whereas in CSKS , KOSTL is a partial key field, so it is non-unique.