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: 

Displaying unique entries from internal table

former_member248300
Participant
0 Kudos

Hello Friends,

I have a internal table link this:

NAME AGE

RAJ 26

RAVI 32

RAJ 26

SOM 29

SOM 29

How can I display only unique name from this internal table?

My o/p should look like this:

NAME AGE

RAJ 26

RAVI 32

SOM 29

Thanks,

Shreekant

6 REPLIES 6

Former Member
0 Kudos

Hi,

sort itab by name.

delete adjacent duplicates from itab comparing name.

loop at itab.

write itab-name, itab-age.

endloop.

Thanks,

Arun

Former Member
0 Kudos

Very simple

Delete duplicate entries from your internal table

Syntax

Delete adjacent duplicate entries from itab comapring

field1 and field2

after this display the o/p

It will work fine

Thnkx

0 Kudos

The code would be like this:

SORT <internaltable> BY name.

DELETE ADJACENT DUPLICATES FROM <internaltable> COMPARING ALL FIELDS.

Then..

LOOP AT <internaltable> INTO <workarea>.

WRITE: / <workarea>-name, <workarea>-age.

ENDLOOP.

Former Member
0 Kudos

Hi sreekant,

One way is doing is as my friends above said sorting and deleting

and the the option is manually doing it by putting some logic

like this..................

data : v_name(30),

v_age(30).

sort itab by name age.

loop at itab.

if v_name = itab-name and v_age = itab-age.

delete itab.

else.

v_name = itab-name.

v_age = itab-age.

write : itab.

endif.

endloop.

Hope this will be helpful.

Regards,

Karthik

Former Member
0 Kudos

Hi,

Sort internal table by name.

delete adjacent duplicates from internal table.

loop at internal table.

write: / internal table.

endloop.

former_member386202
Active Contributor
0 Kudos

Hi,

While selecting data from database table use SELECT DISTINCT otherwise

sort itab by name.

DELETE ADJACENT DUPLICATES

from itab copmaring name.

then display it

Regards,

Prashant