01-02-2008 3:51 AM
Hi expert anyone know how to retrieve distinct value of a column from a internal table?
01-02-2008 3:54 AM
Hi,
No you cannot.
Make the column as key fields for doing so!!
Cheers,
Hakim
mark all useful answers
01-02-2008 4:07 AM
Is possible! Try this:
Data: begin of itab occurs 0,
name(20) type c,
end of itab.
Data: name1(20) type c,
name2(20) type c.
Data: begin of itab1 occurs 0,
fullname(20) type c,
end of itab1.
Below are some record i had create in the internal table, note there are some repeated record for testing.
itab-name = 'peter'.
append itab.
itab-name = 'gary'.
append itab.
itab-name = 'john'.
append itab.
itab-name = 'john'.
append itab.
itab-name = 'peter'.
append itab.
itab-name = 'gary'.
append itab.
itab-name = 'ken'.
append itab.
sort itab.
loop at itab.
name1 = itab-name.
if name2 <> name1.
append itab1.
endif.
name2 = name1.
endloop.
Below itab1 is the distinct record for the itab. itab contain duplicated record. itab1 contain ONLY distinct record.
Loop at itab1.
write: / itab1-fullname.
endloop.
Reward point if any help
01-10-2008 5:44 AM
Hey gary what is the value for name2?
What does the if statement do?
I don't quite understand the middle part of the coding.
01-10-2008 5:56 AM
See the following ex:
types: begin of ty_itab1,
field1 type c,
field2 type c,
end of ty_itab1.
data: itab1 type standard table of ty_itab1 with header line,
itab2 type standard table of ty_itab1 with header line.
select * from
into table itab1.
itab2[] = itab1[].
sort itab1 by field1.
delete adjacent duplicates from itab1 comparing field1.
*******Now itab1 containes the distinct field1 values
01-10-2008 6:00 AM
Hello Joce,
There are two types where we can solve this problem.
One deleting the duplicate entries in that internal table itself through the following code.
-
DATA: BEGIN OF it_bkpf OCCURS 0,
belnr LIKE bkpf-belnr,
END OF it_bkpf.
SELECT belnr INTO TABLE it_bkpf
FROM bkpf.
SORT it_bkpf BY belnr.
DELETE ADJACENT DUPLICATES FROM it_bkpf.
-
Or you can do one more thing if you dont want to delete the duplicate entries. Create one more internal table copy all the content of first internal table into the second and delete the duplicate entries in that.