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: 

Display only distinct values from an internal table

Former Member
0 Kudos

Hi Everyone,

I get the data in my internal for all the fiscyear 2000 to 2005. and for thats its comp_code values etc.

I just want to display only distinct values for fiscyear 2000 to 2005 and also distinct comp_code values which belongs to these fiscyears.

How do I select from the internal table which get this data.

Please respond with some code samples.

Thanks,

Prashant.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

you can use

SELECT DISTINCT

or

SELECT * from table ORDER BY

and then

DELETE ADJACENT DUPLICATES

11 REPLIES 11

Former Member
0 Kudos

you can use

SELECT DISTINCT

or

SELECT * from table ORDER BY

and then

DELETE ADJACENT DUPLICATES

0 Kudos

Will select work for an internal table itab.

I tried but did not work.

0 Kudos

For DELETE ADJACENT DUPLICATES you have to sort first..

SORT ITAB BY fiscal_year comp_code..

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING fiscal_year comp_code.

0 Kudos

It worked

itab_temp[] = g_t_data[].

delete adjacent duplicates from itab_temp comparing fiscyear comp_code.

But then now how do I display it, willthis work.

LOOP AT g_t_data INTO g_s_data.

WRITE: /(10) g_s_data-fiscyear,

(12) g_s_data-comp_code,

0 Kudos

send the data back after deleteing..


itab_temp[ ] = g_t_data[ ].
delete adjacent duplicates from itab_temp comparing fiscyear comp_code.

g_t_data[ ] = itab_temp [] 

LOOP AT g_t_data INTO g_s_data.
WRITE: /(10) g_s_data-fiscyear,
(12) g_s_data-comp_code..

award points if helpful

0 Kudos

Thank you very much Jay it worked finally.

Regards,

Prashant.

0 Kudos

I know this is quiet old, but my two cents nontheless:
How can this work for a internal table? Using SELECT works on real tables AFAIK.

0 Kudos
Thomas Mundt In 2008 you would have been right, but since 7.52 with HANA database (at least), it works:
IF cl_abap_dbfeatures=>use_features( EXPORTING requested_features = VALUE #( 
      ( cl_abap_dbfeatures=>ITABS_IN_FROM_CLAUSE ) ) ). 
  SELECT ... FROM @itab ...
ENDIF.

former_member156446
Active Contributor
itab_temp[ ] = itab [ ].

delete adjacent duplicates from itab_temp.

or 

delete adjacent duplicates from itab_temp comparing fscyr comp_code.

0 Kudos

itab_temp[ ] = g_t_data[ ].

delete adjacent duplicates from itab_temp comparing fiscyear comp_code.

For my internal table it throws up the erro saying :

Statement "ITAB_TEMP[" is not defined. Check your spelling.

In the beginning i have defined it as itab_temp LIKE g_t_data, but still the same error comes up.

Former Member
0 Kudos

Use ..

SELECT DISTINCT <cols> ... WHERE ...

If you do not use DISTINCT (<lines> is then empty), the system reads all of the lines that satisfy the WHERE condition. If you use DISTINCT, the system excludes duplicate entries

Duplicate entries in the result set are automatically deleted.

Eg..

TABLES SPFLI.

DATA TARGET LIKE SPFLI-CITYTO.

SELECT DISTINCT CITYTO

INTO TARGET FROM SPFLI

WHERE

CARRID = 'LH ' AND

CITYFROM = 'FRANKFURT'.

WRITE: / TARGET.

ENDSELECT.

.

Also check this link.

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb3990358411d1829f0000e829fbfe/content.htm