ABAP: Find unique values in internal table

Ever since 7.40 SP08 there is a short way to find unique values in an internal table without looping and comparing the whole table.

DATA: lt_unique TYPE STANDARD TABLE OF fieldtype.
lt_unique = VALUE #(
  FOR GROUPS value OF <fs_line> IN it_itab
  GROUP BY <fs_line>-field WITHOUT MEMBERS ( value ) ).
1
2
3
4

The <fs_line>-field is your unique key by which you want to reduce the table. Only the unique values of <fs_line>-field will be present in the table afterwards. If you have more than one field that makes up your unique key, you'll have to alter the statement.

DATA: lt_unique TYPE STANDARD TABLE OF fieldtype.
lt_unique = VALUE #(
  FOR GROUPS value OF <fs_line> IN it_itab
  GROUP BY ( key1 = <fs_line>-field1 key2 = <fs_line>-field2 ) WITHOUT MEMBERS ( field1 = value-key1 field2 = value-key2 ) ).
1
2
3
4

The fields key1 & key2 are a fixed part of the statement, but field1 & field2 would correspond to your real fields. Instead of an upfront declaration you could use a tabletype instead of the hashtag in the VALUE statement.