Below Run-time Error comes when you have not defined Primary key in ZTABLE. SO first Define Primary Key in ZTABEL
Runtime Errors SAPSQL_ARRAY_INSERT_DUPREC
Except. CX_SY_OPEN_SQL_DB
Date and Time 08.02.2013 12:15:59
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
|Short text |
| The ABAP/4 Open SQL array insert results in duplicate database records. |
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
|What happened? |
| Error in the ABAP Application Program |
| |
| The current ABAP program "SAPMZ_GATE_ENTRY" had to be terminated because it has |
| come across a statement that unfortunately cannot be executed. |
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
|Error analysis |
| An exception occurred that is explained in detail below. |
| The exception, which is assigned to class 'CX_SY_OPEN_SQL_DB', was not caught |
| and |
| therefore caused a runtime error. |
| The reason for the exception is: |
| If you use an ABAP/4 Open SQL array insert to insert a record in |
| the database and that record already exists with the same key, |
| this results in a termination. |
| |
| (With an ABAP/4 Open SQL single record insert in the same error |
| situation, processing does not terminate, but SY-SUBRC is set to 4.) |
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
|Missing Handling of System Exception |
| Program SAPMZ_GATE_ENTRY |
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
|Trigger Location of Exception |
| Program SAPMZ_GATE_ENTRY |
| Include MZ_GATE_ENTRY_USER_COMMAND_I01 |
| Row 94 |
| Module type (MODULE PAI) |
| Module Name INSERT_DATA_9000 |
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
|Source Code Extract |
----------------------------------------------------------------------------------------------------
|Line |SourceCde |
----------------------------------------------------------------------------------------------------
| 64| IMPORTING |
| 65| SELECTED_TIME = WA_GATE-TOUT |
| 66| . |
| 67|ENDMODULE. " F4_TIME_OUT INPUT |
| 68|*&---------------------------------------------------------------------* |
| 69|*& Module INSERT_DATA_9000 INPUT |
| 70|*&---------------------------------------------------------------------* |
| 71|* text |
| 72|*----------------------------------------------------------------------* |
| 73|MODULE INSERT_DATA_9000 INPUT. |
| 74| BREAK 10115. |
| 75| CASE sy-ucomm. |
| 76| WHEN 'SAVE'. |
| 77|* WA_INSERT-CNO = WA_GATE-CNO. |
| 78|* WA_INSERT-TIN = WA_GATE-TIN. |
| 79|* WA_INSERT-TOUT = WA_GATE-TOUT. |
| 80|* WA_INSERT-NOA = WA_GATE-NOA. |
| 81|* WA_INSERT-NOP = WA_GATE-NOP. |
| 82|* WA_INSERT-VNO = WA_GATE-VNO. |
| 83|* WA_INSERT-NOP1 = WA_GATE-NOP1. |
| 84|* WA_INSERT-REMARKS = WA_GATE-REMARKS. |
| 85| MOVE-CORRESPONDING wa_gate to wa_insert. |
| 86| APPEND WA_INSERT TO IT_INSERT. |
| 87| CLEAR WA_INSERT. |
| 88|SELECT cno FROM zgateentry INTO wa_temp |
| 89| WHERE cno = wa_gate-cno. |
| 90| ENDSELECT. |
| 91|if wa_temp-cno is INITIAL. |
| 92|* MOVE-CORRESPONDING WA_GATE TO WA_INSERT. |
| 93|* INSERT INTO ZGATEENTRY VALUES it_INSERT. |
|>>>>>| insert zgateentry from table it_insert. |
| 95| ELSE. |
| 96| MODIFY ZGATEENTRY FROM WA_INSERT. |
| 97| ENDIF. |
| 98|*endif. |
| 99|*CLEAR wa_temp. |
| 100| IF sy-subrc = 0. |
| 101| MESSAGE 'Records created succesfully' TYPE 'S'. |
| 102| ENDIF. |
| 103|ENDCASE. |
| 104|*ENDIF. |
| 105|*CASE sy-ucomm. |
| 106| |
| 107|*ENDCASE. |
Runtime Errors SAPSQL_ARRAY_INSERT_DUPREC
Except. CX_SY_OPEN_SQL_DB
Date and Time 08.02.2013 12:15:59
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
|Short text |
| The ABAP/4 Open SQL array insert results in duplicate database records. |
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
|What happened? |
| Error in the ABAP Application Program |
| |
| The current ABAP program "SAPMZ_GATE_ENTRY" had to be terminated because it has |
| come across a statement that unfortunately cannot be executed. |
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
|Error analysis |
| An exception occurred that is explained in detail below. |
| The exception, which is assigned to class 'CX_SY_OPEN_SQL_DB', was not caught |
| and |
| therefore caused a runtime error. |
| The reason for the exception is: |
| If you use an ABAP/4 Open SQL array insert to insert a record in |
| the database and that record already exists with the same key, |
| this results in a termination. |
| |
| (With an ABAP/4 Open SQL single record insert in the same error |
| situation, processing does not terminate, but SY-SUBRC is set to 4.) |
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
|Missing Handling of System Exception |
| Program SAPMZ_GATE_ENTRY |
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
|Trigger Location of Exception |
| Program SAPMZ_GATE_ENTRY |
| Include MZ_GATE_ENTRY_USER_COMMAND_I01 |
| Row 94 |
| Module type (MODULE PAI) |
| Module Name INSERT_DATA_9000 |
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
|Source Code Extract |
----------------------------------------------------------------------------------------------------
|Line |SourceCde |
----------------------------------------------------------------------------------------------------
| 64| IMPORTING |
| 65| SELECTED_TIME = WA_GATE-TOUT |
| 66| . |
| 67|ENDMODULE. " F4_TIME_OUT INPUT |
| 68|*&---------------------------------------------------------------------* |
| 69|*& Module INSERT_DATA_9000 INPUT |
| 70|*&---------------------------------------------------------------------* |
| 71|* text |
| 72|*----------------------------------------------------------------------* |
| 73|MODULE INSERT_DATA_9000 INPUT. |
| 74| BREAK 10115. |
| 75| CASE sy-ucomm. |
| 76| WHEN 'SAVE'. |
| 77|* WA_INSERT-CNO = WA_GATE-CNO. |
| 78|* WA_INSERT-TIN = WA_GATE-TIN. |
| 79|* WA_INSERT-TOUT = WA_GATE-TOUT. |
| 80|* WA_INSERT-NOA = WA_GATE-NOA. |
| 81|* WA_INSERT-NOP = WA_GATE-NOP. |
| 82|* WA_INSERT-VNO = WA_GATE-VNO. |
| 83|* WA_INSERT-NOP1 = WA_GATE-NOP1. |
| 84|* WA_INSERT-REMARKS = WA_GATE-REMARKS. |
| 85| MOVE-CORRESPONDING wa_gate to wa_insert. |
| 86| APPEND WA_INSERT TO IT_INSERT. |
| 87| CLEAR WA_INSERT. |
| 88|SELECT cno FROM zgateentry INTO wa_temp |
| 89| WHERE cno = wa_gate-cno. |
| 90| ENDSELECT. |
| 91|if wa_temp-cno is INITIAL. |
| 92|* MOVE-CORRESPONDING WA_GATE TO WA_INSERT. |
| 93|* INSERT INTO ZGATEENTRY VALUES it_INSERT. |
|>>>>>| insert zgateentry from table it_insert. |
| 95| ELSE. |
| 96| MODIFY ZGATEENTRY FROM WA_INSERT. |
| 97| ENDIF. |
| 98|*endif. |
| 99|*CLEAR wa_temp. |
| 100| IF sy-subrc = 0. |
| 101| MESSAGE 'Records created succesfully' TYPE 'S'. |
| 102| ENDIF. |
| 103|ENDCASE. |
| 104|*ENDIF. |
| 105|*CASE sy-ucomm. |
| 106| |
| 107|*ENDCASE. |