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

SAPSQL_ARRAY_INSERT_DUPREC

Former Member
0 Likes
797

We have an issue when a program is attempting to insert records into a Z table. This is the main code which is producing the error.

DATA i_recs like z_abc_recs occurs 0 with header line.

DELETE z_abc.

.....

delete adjacent duplicates from i_recs.

insert zzz_high_sell from table i_recs.

The help agains DELETE DUPLICATE says it deletes based on the keys. There are no keys as far as I can tell as no SORT has been performed on i_recs, although it was based on a Z_ABC_RECS which does have an index and therefore keys. Do these keys get picked up when i_recs is defined?. I suspect not.

The answer may be to insert a SORT against i_recs just before the DELETE DUPLICATE statement.

Do you think that should work?.

Jas.

6 REPLIES 6
Read only

Former Member
0 Likes
744

Hello

Yes, it may work.

But try this:


INSERT zzz_high_sell from table i_recs ACCEPTING DUPLICATE KEYS. 

Read only

PedroGuarita
Active Contributor
0 Likes
744

The delete adjacent duplicates instruction is based on the the keyword "adjacent", so it means that it will delete duplicates that are near in the z table.

Quoting SAP HELP :

"Lines are considered to be doubled if the content of neighboring lines is the same in the components examined. In the case of several double lines following one another, all the lines - except for the first - are deleted"

So, it would wise to do a sort before the delete instruction in order to get the duplicates as adjacent to one another as possible, otherwise it might not work correctly.

Read only

Former Member
0 Likes
744

Hi Jason,

In zzz_high_sell table when you are inserting the record from i_recs already exist

put a break-point on the insert statement check you will come to know

What is exactly record which is duplicated

Regards

Nilesh

Read only

0 Likes
744

Ah, if only it was that simple. The problem only occurs in production and there's a DELETE table instruction almost as the first line. So, in debug I can't process this as it will be committed, and then it will fall over when it attempts to insert. We can not leave this table empty and that's why I asked the question.

I could do one of three things I belive. Either SORT the itab beforehand so that the DELETE ADJACENT DUPLICATES works. Or remove the ADJACENT statement from the DELETE, or use an UPDATE instead of INSERT.

Accepting duplicate when I INSERT is not an option as I do not want duplicate records.

I think I'll opt for the SORT method, as that sounds like the neatest way, plus the itab is not that big in terms of number of records. around 600 to 1000 records. The sort/delete/insert is only performed once in the code, so this does sound like the right approach.

Regards

Jason.

Read only

0 Likes
744

Hi,

Correcting few things...


DATA i_recs like z_abc_recs occurs 0 with header line.

DELETE z_abc.

.....

--delete adjacent duplicates from i_recs.--

--insert zzz_high_sell from table i_recs.--

SORT i_recs BY <fieldlist>
delete adjacent duplicates from i_recs COMPARING <fieldlist>.

insert zzz_high_sell from table i_recs.

ACCEPTING DUPLICATE KEYS won't insert duplicate keys. But will ignore during the INSERT so that you wont get the dump.

If you don't define the key in internal table definition, all character fields are considered as the key(For standard and sorted tables).

Thanks,

Vinod.

Read only

Former Member
0 Likes
744

Decided to place a SORT statement before the DELETE.