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: 

avoiding duplicates in internal table

Former Member
0 Kudos

Hi Experts,

when Iam populating data into internal table how can i avoid duplicates.

For eg I want to capture all the sales order of all the items , if iam having the same sales order for all the items the internal table should be consisting of only one sales order .

6 REPLIES 6

former_member189059
Active Contributor
0 Kudos

use select distinct while you select

else

sort the table and delete adjacent duplicates

Former Member
0 Kudos

If<b> you wanna extract distict value from data base table , then use

SELECT DISTINCT....

the DISTINCT addition can be used to exclude duplicate lines from the resulting list.

by this you can select only distict values and u can avoid duplicate values.

revert back if not clear.

reward points if helpful</b>

Former Member
0 Kudos

hi,

inorder to get only 1 sales order number for all the item number you need to use the statement :

<b>Select DISTINCT</b> inpopulating your internal table.

regards,

sohi

Former Member
0 Kudos

Dont use select distinct, instead after populating internal table

sort itab

delete adjacent duplicates from itab comparing vbeln.

select distinct will increase load on your database

Former Member
0 Kudos

Hi,

The better approach will be to use the following

SORT T_MARC BY MATNR.

DELETE ADJACENT DUPLICATES FROM T_MATNR COMPARING MATNR.

The DISTINCT addition to the SELECT statement allows you to remove duplicates from a set of results during a SELECT.

SELECT DISTINCT MATNR

FROM MARC

INTO TABLE T_MARC

WHERE DISMM = 'ND'.

<b>Disadvantages:</b>

• Requires sorting on database server and adversely affects overall system performance if no index can be used

• When using DISTINCT the database is always accessed directly by passing the SAP buffer

Alternative approach:

SELECT MATNR

FROM MARC

INTO TABLE T_MARC

WHERE DISMM = 'ND'.

SORT T_MARC BY MATNR.

DELETE ADJACENT DUPLICATES FROM T_MATNR COMPARING MATNR.

<b>Recommendation:</b>• Only use the DISTINCT addition if there are a large number of duplicates and the set of results will be significantly reduced if you remove duplicates.

• Use DISTINCT if the selected fields are part of DB index picked by WHERE clause of the SELECT.

Reward useful answers

Former Member
0 Kudos

To avoid duplicate entries in the internal table you may try this approach

The <b>DELETE ADJACENT DUPLICATES</b> statement is especially useful if the internal table itab is sorted by fields (whether in ascending or descending order) which were compared during duplicate determination. In this case, the deletion of neighbouring duplicates is the same as the deletion of all duplicates.

If a comparison criterion is only known at runtime, it can be specified dynamically as the content of a field name by using COMPARING ... (name) ... . If name is blank at runtime, the comparison criterion is ignored. If name contains an invalid component name, a runtime error occurs.

Comparison criteria - statistically or dynamically specified - can be further restriced by specifying the offset and/or length.

Regards,

Neha.