Skip to Content
author's profile photo Former Member
Former Member

ITAB_DUPLICATE_KEY

We are getting a "ITAB duplicate key" error in a DataSource enhancement for BW that selects data from table MBEW into a hash table. The internal table has the same fields as the key of the table. I don't understand how we could be getting ITAB_DUPLICATE_KEY error when the where clause on the select statement has the key of the table. Is this a buffering issue? Here's a subset of the important code:

TYPES:
BEGIN OF TY_MBEW, "Material Valuation
MATNR TYPE MBEW-MATNR, "Material Number
BWKEY TYPE MBEW-BWKEY, "Valuation Area
BWTAR TYPE MBEW-BWTAR, "Valuation Type
STPRS TYPE MBEW-STPRS, "Standard Price
PEINH TYPE MBEW-PEINH, "Price Unit
VERPR TYPE MBEW-VERPR, "Moving Average Price/Periodic Unit Price
VPRSV TYPE MBEW-VPRSV, "Price Control Indicator
END OF TY_MBEW.

DATA:

IT_MBEW_HSH TYPE HASHED TABLE OF TY_MBEW
WITH UNIQUE KEY MATNR BWKEY BWTAR,

SELECT MATNR
BWKEY
BWTAR
STPRS
PEINH
VERPR "Moving Average Price/Periodic Unit Price
VPRSV "Price Control Indicator
FROM MBEW
INTO CORRESPONDING FIELDS OF TABLE it_mbew_hsh
FOR ALL ENTRIES IN LI_DATA
WHERE MATNR = LI_DATA-MATNR AND
BWKEY = LI_DATA-WERKS AND
BWTAR = ''.


Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

14 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Feb 26, 2013 at 07:35 PM

    Hi,

    When you use for all entries in the select statement u should not use the table in the into clause as Hashed table instead use the standard table along with where clause with all primary key fields.

    Regards,

    Vineesh.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 26, 2013 at 08:03 PM

    Hi Rob,

    It seems problem lies in LI_DATA content. Indeed you have table key properly stated in your WHERE clause once it's MBEW full key but for sure LI_DATA is not following same key and, at FOR ALL ENTRIES, it's retrieving more than one line for same entry in MBEW, check it's content.

    What you could do is, once LI_DATA seems to be supposed to follow same MATNR/BWKEY/BWTAR key do a SORT + DELETE ADJACENT DUPLICATES by this key over LI_DATA first.

    Regards,

    Edgar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 26, 2013 at 08:18 PM

    Hi Rob,

    Did you sort and delete adjacent duplicate from LI_DATA? If not I would try doing this. With the for all entries It may be selecting the same record twice.

    Regards,

    Steve

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 26, 2013 at 10:52 PM

    Hi,

    That sounds strange.

    - Please confirm: do you get that error during the execution of that SELECT statement?

    - Are there duplicate entries in LI_DATA? Does i still happen if you remove them>

    - Does it still happen if you use a STANDARD table instead of a HASHED table? (It shouldn't make any difference, but still)

    cheers

    Paul

    cheers

    Paul

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 26, 2013 at 11:39 PM

    FOR ALL ENTRIES does not work that way. Any duplicates in LI_DATA are ignored. From SAP help (http://help.sap.com/saphelp_nw73/helpdata/en/fc/eb3a1f358411d1829f0000e829fbfe/frameset.htm):

    1. SELECT... FOR ALL ENTRIES IN itab WHERE cond...

    cond may be formulated as described above. If you specify a field of the internal table itab as an operand in a condition, you address all lines of the internal table. The comparison is then performed for each line of the internal table. For each line, the system selects the lines from the database table that satisfy the condition. The result set of the SELECT statement is the union of the individual selections for each line of the internal table. Duplicate lines are automatically eliminated from the result set.

    Also, Vineesh mentioned that I shouldn't use the hash in the into. I can't see how that is an issue. We are selecting UNIQUE records from MBEW to put into a hash table. I could throw them in a standard table first and then get rid of dupes and move to the hash, but the select can not return duplicate rows. If the hash table has the same key as MBEW, then the ITAB_DUPLICATE_KEY error is breaking the law, so to speak.

    Something else must be going on here. Crazy

    Cheers,

    Rob

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2013 at 04:34 AM

    hi,

    the piece of code you posted was absolutely correct.. i think the problem is with the LI_DATA internal table.. may be you should delete the duplicates entries from that IT by SORT and DELETE ADJACENT DUPLICATES ENTRIES and try use this code.. it ll work fine i think..

    you can remove into corresponding from this code, cause it ll reduce your code performance.. anyway removing this wont help you to solve your issue.. but try to avoid it while coding..

    thanks,

    Mathan R.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 27, 2013 at 04:54 AM

    Hi Rob,

    Just a thought. Are there any entries that have blank MATNR or WERKS in the LI_DATA table?

    Ideally MATNR shouldn't be blank but if these are dummy entries you never know. Since BWTAR is already blank, maybe there are entries where Material is the same, Plant is blank and BWTAR is blank or Material is blank, Plant is the same and BWTAR is blank. These can also cause duplicate entries.

    So you can sort the table LI_DATA by MATNR WERKS

    Delete adjacent duplicates comparing MATNR WERKS

    Delete LI_DATA where MATNR = space. or WERKS = space.

    and then you may try. Hope this helps!

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2013 at 05:27 AM

    Hi,

    Hashed table wont allow duplicate keys use standard table or sorted table with out unique key.

    Thanks & Regards,

    Ramu Velaga.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2013 at 05:50 AM

    hi,

    Better use sort and

    Delete adjacent duplicates entries comparing MATNR BWKEY BWTAR.

    (i mean all the three fields) .. hence all the fields are primary key fields of MBEW.. so duplicates is not at all possible..


    or else try to change the hash table into standard table.. May be it ll work..

    this wasnt a correct solution for this issue.. but give a try.. it may work..

    thanks,

    Mathan R.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2013 at 05:57 AM

    hi,

    if the duplicate is still appearing use delete adjacent duplicates from itab.

    hope it helps,

    Vinoth

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.