Application Development 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: 

Problem with Insert Statement

former_member188001
Active Participant
0 Kudos
217

Hello all,

I have a very weird problem. I have downloaded table entries in an excel file F1. Now, I deleted these entries and uploaded the table with new set of entries from file F2.

Now again, I deleted these entries and when I try to Insert the entries from file F1, i get a short dump saying that there are duplicate entries.

Now, since the table is blank, there is no question of having duplicate entries.

Can anyone please help me.

Both the excel files are in .CSV format

Regards,

Salil

1 ACCEPTED SOLUTION

Subhankar
Active Contributor
0 Kudos
120

Hi ...

use this one...

INSERT tjqxmlcontdepval FROM TABLE gt_make_year

accepting duplicate keys.

It will not give you short dump.

Thanks

Subhankar

15 REPLIES 15

naimesh_patel
Active Contributor
0 Kudos
120

Did you Commit your LUW by calling COMMIT WORK?

Regards,

Naimesh Patel

0 Kudos
120

Commit Work is there, but even before commit is being called, i get a short dump on Insert statement.

laxmanakumar_appana
Active Contributor
0 Kudos
120

Hi,

Use the statement 'DELETE ADJACENT DUPLICATES FROM <ITAB> COMPARING <Key Fields> before insert statement.

Or

Change to MODIFY statement .

Regards

L Appana

0 Kudos
120

I have tried using Modify Statement. But even after I run the program, the table shows zero entries.

0 Kudos
120

I tried testing this by just trying to insert one record. Even then I get a short dump saying that duplicate records cannot be inserted. But in fact there are no records existing in the table.

0 Kudos
120

hi

goto se14, open ur table -> press delete database .

then select radio button delete data and press activate and adjust data. i think this shud solve ur problem

0 Kudos
120

Can i know in which table you are trying to update data???????????//

0 Kudos
120

Its a IS-Media table - TJQXMLCONTDEPVAL

0 Kudos
120

Please find the code below. Here, when I Insert for the first time, I get sy-subrc = 0. When I go and check in the database table, there are no records. I dont know why.

Secondly, when I run the same code again, i get a short dump saying that duplicate records cannot be entered. Now there is no question of duplicates, since the table is empty.

*&---------------------------------------------------------------------*
*& Report  ZMAM_DTD_UPLOAD_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zmam_dtd_upload_test.

CONSTANTS : c_version TYPE ism_amc_dtd_version VALUE '0004',
            c_year    TYPE ism_amc_element     VALUE 'YEAR',
            c_make    TYPE ism_amc_element     VALUE 'MAKE',
            c_model   TYPE ism_amc_element     VALUE 'MODEL',
            c_trim    TYPE ism_amc_element     VALUE 'TRIM'.


TYPES :         BEGIN OF t_content_dep,
          client           TYPE mandt,
          dtd_version      TYPE ism_amc_dtd_version,
          element          TYPE ism_amc_element,
          attribute        TYPE ism_amc_attribute,
          parent_element   TYPE ism_amc_parent_element,
          parent_attribute TYPE ism_amc_parent_attribute,
          sequence_no      TYPE ism_amc_sequence_no,
          value            TYPE ism_amc_value,
          parent_value     TYPE ism_amc_parent_value,
        END OF t_content_dep,

        BEGIN OF t_upload,
          field  TYPE char200,
        END OF t_upload.

* Local Variable
DATA :l_filename           TYPE string,
      l_length             TYPE char200,
      l_file_format        TYPE char3,
      l_client             TYPE sy-mandt.

* Internal Tables and Work Areas
DATA :
       gt_upload            TYPE STANDARD TABLE OF t_upload,
       gw_upload            TYPE t_upload,
       gt_make_year   TYPE STANDARD TABLE OF t_content_dep,
       gt_test        TYPE STANDARD TABLE OF t_content_dep,
       gw_make_year   TYPE t_content_dep.


PARAMETERS : p_fname  TYPE rlgrap-filename OBLIGATORY,
             p_header AS CHECKBOX DEFAULT 'X'.


*---------------------------------------------------------------------*
* At Selection Screen
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      program_name  = syst-repid
      dynpro_number = syst-dynnr
    CHANGING
      file_name     = p_fname
    EXCEPTIONS
      mask_too_long = 1
      OTHERS        = 2.

  IF sy-subrc  = 0.
    l_filename = p_fname.
  ELSE.
    MESSAGE e052(sppf_media) WITH 'File Not Found'.
  ENDIF.

START-OF-SELECTION.
  IF NOT p_fname IS INITIAL.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename            = l_filename
        filetype            = 'ASC'
        has_field_separator = ','
      TABLES
        data_tab            = gt_upload.

    IF sy-subrc = 0.
      LOOP AT gt_upload INTO gw_upload.

        SPLIT gw_upload AT ',' INTO  l_client gw_make_year-dtd_version
                                    gw_make_year-element gw_make_year-attribute
                                    gw_make_year-parent_element gw_make_year-parent_attribute
                                    gw_make_year-sequence_no gw_make_year-value
                                    gw_make_year-parent_value.

        APPEND gw_make_year TO gt_make_year.
        CLEAR : gw_make_year, gw_upload.
      ENDLOOP.
    ENDIF.
  ENDIF.

  IF p_header = 'X'.
    DELETE gt_make_year INDEX 1.
  ENDIF.

  BREAK-POINT.

DATA : oref   TYPE REF TO cx_root,
         text   TYPE string.
  TRY .
      INSERT tjqxmlcontdepval FROM TABLE gt_make_year.
    CATCH cx_sy_open_sql_db INTO oref.
      text = oref->get_text( ).
  ENDTRY.

  IF NOT text IS INITIAL.
    WRITE / text.
  ENDIF.
  COMMIT WORK.

Edited by: salil vaidya on Dec 31, 2008 11:11 AM

MarcinPciak
Active Contributor
0 Kudos
120

This has to be a problem of duplicating records, as you described above.

Ensure the table is really empty


if itab[] is initial.
   insert ...
endif.

or use common way of insert/update records.


data: upd type i, ins type i.

Loop at ...
  update table...
  if sy-subrc ne 0.
    insert table ...
    if sy-subrc eq 0.
      add 1 to ins.
    endif.
  else.
    add 1 to upd.
  endif.
endloop.

write: 'Updated', upd, /'Inserted', ins.

...to check if this is relevant to the issue.

Regards

Marcin

Former Member
0 Kudos
120

Hi,

First find the record which is gives dump because of duplicate entries and you remove that record from the F1 file and try to upload. Once if you successfully uploaded then you make a file with that record and execute in debug mode check where you facing problem.

Regards,

Md.MahaboobKhan.

Former Member
0 Kudos
120

hi,

if record present in the table also update command should just over wirte the record but in ur case that is not happening i thing that is because of some ur updated file data is not maching with the dataelements of the table once check all fields mainly date fields etc.........

thanq,

rajesh.k

Subhankar
Active Contributor
0 Kudos
121

Hi ...

use this one...

INSERT tjqxmlcontdepval FROM TABLE gt_make_year

accepting duplicate keys.

It will not give you short dump.

Thanks

Subhankar

0 Kudos
120

Hello,

Any idea, why the data is not getting inserted in the table eventhough the sy-subrc = 0 for the insert query ?

0 Kudos
120

Hello all,

The problem got solved. I had to just go to SE 14 and Adjust and Activate the table.

Thanks all for your help.

Regards,

Salil