SAP Knowledge Base Article - Preview

3239971 - DBSQL_DUPLICATE_KEY_ERROR Runtime Error in ABAP ST22

Symptom

  • 'DBSQL_DUPLICATE_KEY_ERROR' dumps occur in ST22 of an ABAP system on HANA. Examples typically present themselves in the following formats:
       
           
       
            Category               ABAP programming error
            Runtime Errors         DBSQL_DUPLICATE_KEY_ERROR
            Except.                CX_SY_OPEN_SQL_DB
            ABAP Program           SAPLV05I
            Application Component  SD-BF
            Date and Time          24.08.2022 17:10:32
            ----------------------------------------------------------------------------------------------------
            
            ----------------------------------------------------------------------------------------------------
            |Short Text                                                                                        |
            |    Open SQL array insert produces duplicate records in the database.                             |
            ----------------------------------------------------------------------------------------------------
            
            ----------------------------------------------------------------------------------------------------
            |What happened?                                                                                    |
            |    Error in the ABAP application program.                                                        |
            |                                                                                                  |
            |    The current ABAP program "SAPLV05I" had to be terminated because it found a                   |
            |    statement that could not be executed.                                                         |
            ----------------------------------------------------------------------------------------------------
            
            ----------------------------------------------------------------------------------------------------
            |Source Code Extract                                                                               |
            ----------------------------------------------------------------------------------------------------
            |Line |SourceCde                                                                                   |
            ----------------------------------------------------------------------------------------------------
            |  458|                                        PARVW = I_XVBPA-PARVW.                              |
            |  459|            IF I_YVBPA-STCD1 <> I_XVBPA-STCD1 OR                                            |
            |  460|                I_YVBPA-STCD2 <> I_XVBPA-STCD2 OR                                           |
            |  461|                I_YVBPA-STCD3 <> I_XVBPA-STCD3 OR                                           |
            |  462|                I_YVBPA-STCD4 <> I_XVBPA-STCD4 OR                                           |
            |  463|                I_YVBPA-STCD5 <> I_XVBPA-STCD5 OR                                           |
            |  464|                I_YVBPA-STCDT <> I_XVBPA-STCDT OR                                           |
            |  465|                I_YVBPA-STKZN <> I_XVBPA-STKZN OR                                           |
            |  466|                I_YVBPA-J_1KFREPRE <> I_XVBPA-J_1KFREPRE OR                                 |
            |  467|                I_YVBPA-J_1KFTBUS <> I_XVBPA-J_1KFTBUS OR                                   |
            |  468|                I_YVBPA-J_1KFTIND <> I_XVBPA-J_1KFTIND.                                     |
            |  469|              MOVE-CORRESPONDING I_XVBPA TO WA_XVBPA3I.                                     |
            |  470|              APPEND WA_XVBPA3I TO DA_XVBPA3I.                                              |
            |  471|            ENDIF.                                                                          |
            |  472|          ENDIF.                                                                            |
            |  473|        ENDIF.                                                                              |
            |  474|      WHEN UPDKZ_OLD.                                                                       |
            |  475|        IF DA_VBPA-ADRDA CA GCF_ADDR_IND_COMB_MAN_OLD   OR                                  |
            |  476|           DA_VBPA-ADRDA CA GCF_ADDR_IND_COMB_MAN_ADRC.                                     |
            |  477|          YADR-ADRNR = DA_VBPA-ADRNR. COLLECT YADR.                                         |
            |  478|        ENDIF.                                                                              |
            |  479|        IF DA_VBPA-ADRDA CA GCF_ADDR_IND_COMB_MAN_OLD   OR                                  |
            |  480|           DA_VBPA-ADRDA CA GCF_ADDR_IND_COMB_MAN_ADRC.                                     |
            |  481|          XADR-ADRNR = DA_VBPA-ADRNR. COLLECT XADR.                                         |
            |  482|        ENDIF.                                                                              |
            |  483|    ENDCASE.                                                                                |
            |  484|  ENDLOOP.                                                                                  |
            |  485|  UPDATE (OBJECT) FROM TABLE DA_XVBPAU.                                                     |
            |  486|  UPDATE VBPA3 FROM TABLE DA_XVBPA3U.                                                       |
            |  487|                                                                                            |
            |>>>>>|  INSERT (OBJECT) FROM TABLE DA_XVBPAI.                                                     |
            |  489|  INSERT VBPA3 FROM TABLE DA_XVBPA3I.                                                       |
            |  490|                                                                                            |
            |  491|  IF SY-SUBRC > 0.                                                                          |
            |  492|    MESSAGE A700 WITH OBJECT SY-SUBRC DA_XVBPAI(21).                                        |
            |  493|  ENDIF.                                                                                    |
            |  494|                                                                                            |
            |  495|* Sonderfall neue VBPA (VBPA2) für Rollen AA und AW                                         |
            |  496|  LOOP AT I_XVBPA2.                                                                         |
            |  497|    DA_VBPA2 = I_XVBPA2.                                                                    |
            |  498|    CASE DA_VBPA2-UPDKZ.                                                                    |
            |  499|      WHEN UPDKZ_NEW.                                                                       |
            |  500|        IF DA_VBPA2-ADRDA CA GCF_ADDR_IND_COMB_MAN_OLD   OR                                 |
            |  501|           DA_VBPA2-ADRDA CA GCF_ADDR_IND_COMB_MAN_ADRC.                                    |
            |  502|          XADR-ADRNR = DA_VBPA2-ADRNR. COLLECT XADR.                                        |
            |  503|        ENDIF.                                                                              |
            |  504|        I_XVBPA-MANDT = SY-MANDT.                                                           |
            |  505|        IF I_XVBPA2-VBELN IS INITIAL.                                                       |
            |  506|          I_XVBPA2-VBELN = F_VBELN.                                                         |
            |  507|        ENDIF.                                                                              |
            ----------------------------------------------------------------------------------------------------
            
            ----------------------------------------------------------------------------------------------------
            |Database Interface Information                                                                    |
            ----------------------------------------------------------------------------------------------------
            |B|1|dumping DbDbslStatement ... [/bas/753_REL/src/krn/dbi/dbsql/dbdbslstatement.cpp#3394]         |
            |B|1|DBSL_SS(  amode=DBSL_ACC_SL  stmtid_ptr=0   stmt=7f5a0cb9d600  nlcb_ptr=0 ) [/bas/753_REL/src/|
            |B|1|DBSL_DA(  lockType=DBSL_LOCK_DEF  inCnt=26  inMax=26  outCnt=0  outMax=0  bulk_cb=56374d031c10|
            |B|1| IN [ 0]: DBSL_TYPE(  type=DBSL_DATA_SHORT_CHAR(11)  len=6  maxlen=6  decs=0  nullable=false  |
               
              
              
                
            Category               ABAP programming error
            Runtime Errors         DBSQL_DUPLICATE_KEY_ERROR
            Except.                CX_SY_OPEN_SQL_DB
            ABAP Program           SAPLIPAR
            Application Component PM-EQM-FL
            Date and Time          25.08.2022 12:44:31
            ----------------------------------------------------------------------------------------------------
            
            ----------------------------------------------------------------------------------------------------
            |Short Text                                                                                        |
            |    Open SQL array insert produces duplicate records in the database.                             |
            ----------------------------------------------------------------------------------------------------
            
            (ABAP dumps are prone to cutting off syntax and lines of text in the dumps, but what it is essentially saying here is that there is an attempt by the application to insert pre-existing data / primary index keys into the table. Hence "already exists"
            
            |C|1|SQLCODE    : 129 [/bas/777_REL/src/dbs/hdb/dbsdbtrc.cpp#614]                                  |
            |C|1|SQLERRTEXT : transaction rolled back by an internal error: Table(PPHMRPLOGITEM), Index(PPHMRPL|
            |C|1|             r: unique constraint violation on pos=0 for table SID::SAPHANADB:PPHMRPLOGITEM$de|
            |C|1|             xexternalkey$=332c3130303b31362c000d3a2775b31edd88e0748804071bb23b39 already exis|
            |C|1|             dexname=PPHMRPLOGITEM~0 [/bas/777_REL/src/dbs/hdb/dbsdbtrc.cpp#621]              |
            
            )

 

   

  • Sometimes the initial Runtime error can present itself as a deadlock 'DBSQL_SQL_DEADLOCK_DETECTED' during duplicate record inserts, due to erroneous DBSL mapping of the SQL error, however the real error and root cause is a unique constraint violation and duplicate key error. Where there is a 'unique constraint violation' error the dbsl should dump a 301 error code.
         
       
         Category               ABAP programming error
         Runtime Errors         DBSQL_SQL_DEADLOCK_DETECTED
         Except.                CX_SY_OPEN_SQL_DB
         ABAP Program           SAPLBREL
         Application Component  BC-SRV-GBT-OBL
         Date and Time          24.08.2022 09:24:44 (CET)
         ----------------------------------------------------------------------------------------------------
         
         ----------------------------------------------------------------------------------------------------
         |Short Text                                                                                        |
         |    A deadlock has occurred while attempting to access table "SMZB_BINREL".                       |
         ----------------------------------------------------------------------------------------------------
         
         ----------------------------------------------------------------------------------------------------
         |What happened?                                                                                    |
         |    A deadlock has been detected by the database. This situation can arise                        |
         |    if two processes make database changes in parallel to the same entries.                       |
         |    For example:                                                                                  |
         |    1) Process 1 changes entry A.                                                                 |
         |    2) Process 2 changes entry B.                                                                 |
         |    3) Process 2 changes entry A.                                                                 |
         |    4) Process 1 changes entry B.                                                                 |
         |    Depending on the database, process 2 gets this short dump at 3) or                            |
         |    prozess 1 gets it at 4).                                                                      |
         |                                                                                                  |
         |                                                                                                  |
         |    Database error number: "SQL code: 129" Database error text: "SQL message:                     |
         |     transaction rolled back by an internal error: Table(SMZB_BINREL),                            |
         |     Index(SMZB_BINREL~0) with error: unique constraint violation on pos=0 for                    |
         |     table SID::SAPHANADB:SMZB_BINREL$delta_1$en, key:                                            |
         |     $trexexternalkey$=3,100;22,00qw9tMp7ks8sKJ5nJzM40;22"                                        |
         ----------------------------------------------------------------------------------------------------
         
          . . . . . 
         
         ----------------------------------------------------------------------------------------------------
         |Database Interface Information                                                                    |
         ----------------------------------------------------------------------------------------------------
         |C|E|  execute() of C_0232, #rec=0, rc=1, rcSQL=129 [/bas/777_REL/src/dbs/hdb/dbsdbsql.cpp#2315]   |
         |C|E|EXECUTE C_0232 on connection 0, rc=129 [/bas/777_REL/src/dbs/hdb/dbslsdb.cpp#10037]           |
         |C|1|SQLCODE    : 129 [/bas/777_REL/src/dbs/hdb/dbsdbtrc.cpp#614]                                  |
         |C|1|SQLERRTEXT : transaction rolled back by an internal error: Table(PPHMRPLOGITEM), Index(PPHMRPL|
         |C|1|             r: unique constraint violation on pos=0 for table SID::SAPHANADB:PPHMRPLOGITEM$de|
         |C|1|             xexternalkey$=332c3130303b31362c000d3a2775b31edd88e0748804071bb23b39 already exis|
         |C|1|             dexname=PPHMRPLOGITEM~0 [/bas/777_REL/src/dbs/hdb/dbsdbtrc.cpp#621]              |
         |C|1|sc_p=7fae0a736680,no=232,idc_p=7fae0a79bc50,con=0,act=1,slen=890,smax=2304,#vars=44,stmt=7fa0f|
         |C|1|stmtid = <13/PPHMRPLOGITEM                           /32768/20170130191003> [/bas/777_REL/src/|
         |C|1|INSERT INTO "PPHMRPLOGITEM" ( "MANDT" , "UUID" , "ITEMID" , "DISST" , "SUBDISST" , "MRP_KIND" |
         |C|1|M_START_TIME" , "ITEM_END_TIME" , "TIME_OVERALL" , "TIME_MASTER" , "TIME_DOCUMENTS" , "TIME_CA|
         |C|1|"TIME_UPDATE" , "TIME_PURREQ_UPD" , "TIME_PLAF_INS" , "TIME_PLAF_DEL" , "TIME_SCHEDL_UPD" , "T|
         |C|1|MNG_UPD" , "TIME_DBVM_UPD" , "TIME_DBVMSET_UPD" , "EBAN_DEL" , "EBAN_INS" , "EBAN_UPD" , "PLAF|
         |C|1|, "PLAF_INS" , "PLAF_W_BOM_P_MAT" , "PLAF_INS_W_BOM" , "PLAF_UPD" , "EKPO_UPD" , "EKET_DEL" , |
         |C|1|INS" , "EKET_UPD" , "RESB_DEL" , "RESB_INS" , "RESB_UPD" , "DBVM_UPD" , "MDPS_READ" , "MATERIA|
         |C|1|D" , "MATERIALS_PLANNED" , "MATERIALS_NOT_PLANNED" , "NUM_PAR" , "MAX_PLNUM" , "MAX_BANFN" , "|
         |C|1|NUM" ) VALUES( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,|
         |C|1| , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ); [/|
         |B|E|***LOG BYO=> deadlock aborts transaction [dbsh#1241]                                          |
         |B|1|SQL code: 129, SQL text: transaction rolled back by an internal error: Table(PPHMRPLOGITEM), I|
         |B|E|***LOG BY4=> sql error 129    performing INS on table PPHMRPLOGITEM [dbdbslst#5211]           |
         |B|E|***LOG BY0=> transaction rolled back by an internal error: Table(PPHMRPLOGITEM), Index(PPHMRPL|

  

 


Read more...

Environment

SAP HANA, platform edition 2.0

SAP HANA, platform edition 1.0

Product

SAP HANA 1.0, platform edition ; SAP HANA, platform edition 2.0 ; SAP S/4HANA 1709

Keywords

unique constraint violation, indexes,   , KBA , HAN-DB , SAP HANA Database , Problem

About this page

This is a preview of a SAP Knowledge Base Article. Click more to access the full version on SAP for Me (Login required).

Search for additional results

Visit SAP Support Portal's SAP Notes and KBA Search.