Application Development and Automation 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: 
Read only

Insert same primary key to custom table not dump

former_member660488
Participant
36,673

Hi experts,

As I am trying to insert same primary key to a custom table ,there is no dump and the data is normally saved to the custom table,not dump.Why is this happening?

INSERT zhx_ficot015i FROM TABLE gt_tb_di.

The same data exists in gt_tb_di and zhx_ficot015i ,but sy-subrc return 0.

codes:

DATA:gw_ficot015i TYPE zhx_ficot015i,
gt_ficot015i TYPE TABLE OF zhx_ficot015i.

gw_ficot015i-mandt = '500'.
gw_ficot015i-od_type = '02'.
gw_ficot015i-receno = 'F510320220420004'.
gw_ficot015i-itemno = '000001'.
APPEND gw_ficot015i TO gt_ficot015i.

INSERT zhx_ficot015i FROM TABLE gt_ficot015i ACCEPTING DUPLICATE KEYS.
IF SY-SUBRC = 0.

ENDIF.
BREAK-POINT.

52 REPLIES 52
Read only

Sandra_Rossi
Active Contributor
33,504

Please look at ABAP Documentation. The consequence of INSERT ... FROM TABLE ... with data which would lead to duplicate keys in the table is:

  • if you also indicate ACCEPTING DUPLICATE KEYS, you will get SY-SUBRC = 4.
  • otherwise you get CX_SY_OPEN_SQL_DB. If you don't catch this exception, there will be a short dump.
Read only

Sandra_Rossi
Active Contributor
0 Likes
33,504

If it's another case, check SAP notes or contact SAP support.

Read only

Jeansy
Active Contributor
33,504

For a detail analysis I would change the INSERT ... FROM TABLE to a single INSERT in a LOOP-statement. Just to find out which record is responsible for the dump.

But sandra.rossi is right, you should indeed consider to catch the related exception if you want to stay by this variant using INSERT ... FROM TABLE.

It would be also an option to change it to MODIFY ... FROM TABLE, then there is no issue anymore in case of an existing record in the table with the same key (as it will be just updated in this case).

Kind regards
Jens

Read only

former_member660488
Participant
0 Likes
33,504

same primary key insert from wa or table not dump.Only this table will show this situation.

indicate ACCEPTING DUPLICATE KEYS , SY-SUBRC still return 0.

Read only

keremkoseoglu
Contributor
0 Likes
33,504

If the previous record came from somewhere else (like an integration); it might be the case that one of the columns contains an additional special character which can't be displayed by SAPGUI. Characters like TAB, CR, LF, etc are typical examples.

If that's the case, the system rightly thinks that the old value (containing the rogue character) is different from your clean value.

You might want to inspect the table contents through an external non-SAP tool and see if it shows such a rogue character. Checking string length is also an approach.

Read only

0 Likes
33,504

Codes:search by primary key have 12 records now.

It should not be the cause of abnormal characters.

SELECT * INTO TABLE @DATA(gt_ficot015i) FROM zhx_ficot015i
WHERE od_type = '02' AND receno = 'F510320220420004'

AND itemno = '000001'.

Read only

jmodaal
Active Contributor
0 Likes
33,504

Hello,

strange. When showing the database object (in SE11 > Utilities > Database Object > Display), is the primary index ZHX...~0 shown as "Unique" (like usually)?

Read only

former_member660488
Participant
0 Likes
33,503

Is the index the cause of this problem?

I'm not sure about the indexes

Read only

former_member660488
Participant
0 Likes
33,502

After checking, I found this problem.

Is it caused by this? What should I do? This table already has a lot of data

Read only

jmodaal
Active Contributor
0 Likes
33,502

Hello,

so it seems the missing primary index causes the problem, that you were able to insert multiple rows with same primary key fields. Don't know how this could happen (except deleting it on database level). With the database utility (Utilities > Database Object > Database Utility) you can try to fix this by choosing "Persist data" and clicking "Activate and adjust database". In front of this duplicates of the primary key fields should be deleted, otherwise I guess the database utility will fail. And I would think about extracting / back up the data in front of this (by using a transport request or R3trans or a self-developed ABAP).

Read only

former_member660488
Participant
0 Likes
33,502

I have delete the duplicates records,then tried clicking "Activate and adjust database" ,Promting success.

but the primary index strill missing.

Read only

jmodaal
Active Contributor
0 Likes
33,502

Hello,

even after activating the table again in SE11?

Then you could try to make one of the primary key fields longer, activate it (my expectation would be that the primary index will be created again) and after it shorten the primary key field again to its original length and activate again.

Read only

former_member660488
Participant
0 Likes
33,502

I try change a primary key longer and add a primary key then clicking "Activate and adjust database",

cannot activate

Read only

jmodaal
Active Contributor
0 Likes
33,502

Encouple the primary key fields from any value tables by using data elements CHAR2, CHAR16, CHAR6 and try it again. Then change it back to the currently used data elements and activate again.

Read only

former_member660488
Participant
0 Likes
33,502

I just checked the z table, Actually the duplicates records cannot delete by se16n or abap code

Read only

former_member660488
Participant
0 Likes
33,495

I have been confirmed that there is no duplicate data. The length of the primary key has been adjusted to cahr16, but it cannot be activated

Read only

jmodaal
Active Contributor
0 Likes
33,495

Hello,

column "Data element" still shows your own data elements. Did you try to change this to CHAR16 to get rid off the search help?

Read only

former_member660488
Participant
0 Likes
33,495

Additional error fields that exist and I added a field bukrs as the primary key. Now I can't cancel it

Read only

jmodaal
Active Contributor
0 Likes
33,495

I have the impression that the action is meanwhile somewhat... chaotic. Still using the data elements bound to search helps? My idea was to replace these data elements by simple CHAR... data elements for getting rid of most dependencies to finally enable the activation of the database table with a valid, unique primary key.

Read only

former_member660488
Participant
0 Likes
33,495

The primary key added accidentally in the test cannot be deleted. This problem really has a great impact

Read only

jmodaal
Active Contributor
0 Likes
33,495

Can you provide the error message or a screenshot?

Read only

former_member660488
Participant
0 Likes
33,495

This table is related to many help views and a search help

Read only

jmodaal
Active Contributor
0 Likes
33,495

Did you try SE14 again ("Persist data" > click on "Activate and adjust database")?

Read only

former_member660488
Participant
0 Likes
33,495

try many time and cannot active.

Read only

jmodaal
Active Contributor
0 Likes
33,495

Maybe the dependency to the search help prevents you from adjusting the database table. I would try to deactivate / delete it (and restore it afterwards when everything is fine again). The long text for this message still points to SE14.

Read only

jmodaal
Active Contributor
0 Likes
33,495

Ah, no, it's not pointing to SE14, it's pointing to the dependent tables.

Read only

former_member660488
Participant
0 Likes
33,495

Thank you very much for your patient answer. I have solved the problem. The past two days are weekends and I'm sorry I didn't reply to you in time.

Can you tell me in detail how to back up and restore data? I can only use ABAP toi obtain data from excel and then import it into the system again.

Read only

jmodaal
Active Contributor
0 Likes
33,495

Hello,

great, that you could solve it!

Regarding back up and restore data there are several options available. You can create a transport request and include the data by using object key "R3TR TABU <table name>".

You have to specify the table keys (double click on the line), where you can enter "*" for all records in all clients. By releasing the transport request the data will be written out into a data file. For restoring the data you can import the transport request again.

Another option would be using R3trans (which is also used in the transport request). For this you have to work on OS level, using command files for export and import. Find here a documentation.

Another option (the easiest one, I would state) would be using the product of my company (also using R3trans). For more information on this just click on my profile and follow the link under "Elsewhere" in the "About" part.

Read only

former_member660488
Participant
0 Likes
33,495

The data is from 500 client and I have create requests and relasing,but how can I restoring the data to 500

client. Using code scc1 import the requesting message: Source client is same as logon client

Read only

jmodaal
Active Contributor
0 Likes
33,495

Hello,

use STMS.

Read only

former_member660488
Participant
0 Likes
33,495

the data is dev system data,relasing the request can only accceping in producing sysytem,

This is not the result I want.

Read only

former_member660488
Participant
0 Likes
33,495

The right is the date is from QAS system 500 client

Read only

jmodaal
Active Contributor
0 Likes
33,495

Hello,

for the aim to backup table data for a possibly later restore on D / Q / P system you need to create a transport request on each system (assuming that the data on D / Q / P is different). For this purpose I would choose type "Transport of copies".

I advise to contact your basis administrator(s). If you are a developer, likely you do not have authorizations to import transport requests or to manage the import queue (adding / removing transport requests), so you are dependent on the basis team and should ask for their support and know-how.

Read only

former_member660488
Participant
0 Likes
33,495

I have authorizations to manage request.I want to back up and restore Q / P system data.

When I back up and restore Q system data,

First, I create a request in Q system data ,and delete the the data for Specifies table in Q system

,then relasing the request,how to restore the table data at Q system?

I think the ways is suitable to tranport the data from Q system data to P systrem,

cannot be backup and restore on the same system.

Read only

jmodaal
Active Contributor
0 Likes
33,495

Hello,

is your recent question still about the problematic table of the original question or is this a complete new issue?

However, I can not say more about backup / restore of table data than I have already written. Using transport requests I would choose type "Transport of copies" which bypass the automatic delivery into other systems resp. their import queues. If your task is to do this on Q and P, you need 2 transport requests, one from Q and one from P. And for restoring the data you have to import the data of the transport request back again into its source system, using STMS.

Read only

former_member660488
Participant
0 Likes
33,495

choose type "Transport of copies" error

Read only

jmodaal
Active Contributor
0 Likes
33,495

Hello,

the transport of copies needs a target, to be specified on tab "Properties".

I recommend to contact your basis admin.

Read only

former_member660488
Participant
0 Likes
33,495

I know how to create request and accept in the same client ,but result is not effect,after recovering the table remains zero records

Read only

jmodaal
Active Contributor
0 Likes
33,495

Check the logs of the transport request.