ITAB_DUPLICATE_KEY — ITAB_DUPLICATE_KEY Dump Causes and Fixes
ITAB_DUPLICATE_KEY is raised when an INSERT or APPEND tries to add a row to an internal table declared with a unique key (hashed, sorted unique, or standard table with UNIQUE KEY) and a row with that same key already exists. The exception class behind it is CX_SY_ITAB_DUPLICATE_KEY. It almost always points to unchecked duplicate business data or a missing sy-subrc check after the insert.
Covers why ITAB_DUPLICATE_KEY fires when inserting into a uniquely-keyed internal table, the realistic causes ranked by frequency, what to read off the ST22 short dump, and how to fix each cause without silently dropping data. Also flags the common reflex of catching the exception and discarding the row, which hides a data problem rather than fixing it.
Published 16 Sept 2026· 1,217 words
What the dump means
This is a catchable runtime exception, not a fatal ABAP processing error in itself, but it still terminates the program if nothing catches CX_SY_ITAB_DUPLICATE_KEY. It fires on an INSERT statement (INSERT itab, INSERT LINES OF, INSERT INITIAL LINE) or on APPEND to a table whose type enforces a unique key: HASHED TABLE, SORTED TABLE with UNIQUE KEY, or a STANDARD TABLE explicitly declared with UNIQUE KEY. The runtime checks the key of the row being inserted against existing rows and refuses the operation rather than silently overwriting or duplicating. The dump means the data feeding that insert contains two or more rows that resolve to the same key value, and the code did not anticipate that. It is a data-shape mismatch between what the table type promises (uniqueness) and what the data actually contains.
Root causes that actually produce it
- Genuine duplicate business data reaching a unique-key table: two source records (from a DB select, a file upload, or an RFC result set) legitimately share the key fields chosen for the internal table, and the developer assumed the key was unique when it is not. Common with tables keyed only on document number when line-item or period splits exist.
- Missing sy-subrc check after INSERT: the code does INSERT itab FROM wa without checking the return code, assuming success every time. The first duplicate in a loop then throws the dump instead of being skipped or logged.
- Wrong choice of table type during design or refactoring: a table was declared HASHED or SORTED UNIQUE for performance reasons without checking whether the source data can actually repeat. A later data volume increase or a new calling context exposes the previously untested duplicate case.
- Aggregation logic replaced with a plain INSERT: code that should use COLLECT to sum values for repeating keys was written with INSERT instead, so the second occurrence of a key is treated as an error rather than an addition.
- Multi-call accumulation into a shared table: a loop over BAPI or RFC calls appends results from each call into one internal table without resetting or deduplicating, and two calls return overlapping key ranges, especially in parallel processing.
- Master data or custom table quality issue upstream: a custom Z-table lacking a database uniqueness constraint has already accumulated duplicate rows, and any program reading it into a hashed table with the same key inherits the duplication as a runtime dump instead of a database error.
What to inspect in ST22
Work through the short dump top to bottom before touching code.
- Category and exception class: confirm it says CX_SY_ITAB_DUPLICATE_KEY, not a similar table-handling dump such as ITAB_ILLEGAL_INDEX or TABLE_INVALID_INDEX, since the fix path differs.
- Trigger location (program, include, line number): this is the exact INSERT or APPEND statement responsible, not a generic library routine in most cases.
- Source code display around the trigger line: identify the target internal table name and its declared type, particularly the UNIQUE KEY clause.
- Variables section: look at the work area or table line being inserted at the moment of failure, and compare its key fields against what is already in the table if the dump includes a table content dump.
- Call stack: trace back to the calling transaction, report, or function module to understand the business object involved (sales order, material, custom interface run).
- Follow-on transactions: use ST22's 'display ABAP source' to check the declaration statement for the table type, then SE80 or SE38 to see where the data is sourced, and if the data comes from a Z-table, check its structure in SE11 for the absence of a primary key uniqueness enforcement.
Resolution path
If the cause is genuine duplicate business data that should be summed or merged, replace the INSERT with COLLECT, or add explicit READ TABLE with key before INSERT and update the existing line instead; this is a code change requiring a transport. If the cause is a missing sy-subrc check, wrap the INSERT in a check on sy-subrc equal to 4 and handle the duplicate deliberately, either by logging it, skipping it, or updating the existing entry; also a code change under change management. If the table type itself was wrong for the data (declared unique when duplicates are valid), change the declaration to STANDARD TABLE without a unique key, or to SORTED TABLE with a non-unique key, after confirming no downstream logic relies on the uniqueness guarantee; this is a more invasive change and needs regression testing before transport. If the cause is upstream data quality in a custom table, the immediate incident fix is to deduplicate the offending rows in that table, and the durable fix is adding a proper primary key or unique secondary index at the database level, which is a functional and data-cleanup task, not purely an ABAP one.
The fix people try first (and why it fails)
The reflex fix is wrapping the INSERT or APPEND in TRY CATCH cx_sy_itab_duplicate_key and doing nothing in the CATCH block, or catching the broader cx_root. The dump disappears immediately and the program runs to completion, which looks like success. What actually happened is that the duplicate row was silently dropped. Downstream, that shows up as a missing line item, an incomplete total, a document that reconciles wrong, or a report that undercounts, discovered days or weeks later by someone who has no idea the itab insert ever failed, because the log shows a clean run.
Prevention
Treat any INSERT or APPEND into a uniquely-keyed internal table as needing an explicit sy-subrc check or a deliberate CATCH with logging, never a silent catch. Where duplicates are expected and should be summed, use COLLECT from the start rather than INSERT. During code review, flag any HASHED or SORTED UNIQUE table declaration and ask what happens if the source data repeats the key, and require a test case with duplicate input data before the transport is released.
Whose problem this is
ABAP development owns the fix in nearly all cases, since the resolution is a code change to the insert logic or table declaration. Functional or master data teams get involved only when the root cause is duplicate records in a custom table feeding the program. The handover note should state the exact table name, its key fields, the source of the duplicate data, and whether the fix is COLLECT-based merging, a subrc check, or a table type change.
Related SAP objects
Reviewed pages this object connects to in the ERPClimb knowledge graph.
Source: ERPClimb — https://erpclimb.com/sap-abap-dumps/itab-duplicate-keyERPClimb is an independent platform and is not affiliated with SAP SE. Reference pages are written and reviewed by SAP consultants for learning and troubleshooting.