Automatic distinct can be performed when you use for all entries in for queries,
See the following example:
Report z_ljc222.
Types: Begin of ty_mm,
Matnr type Mara-matnr,
End of ty_mm.
Types: Begin of ty_makt,
Matnr type Mara-matnr,
Spras type Makt-spras,
Maktx type Makt-maktx,
End of ty_makt.
Data mm type table of ty_mm with header line.
Data Makt type table of ty_makt with header line.
Mm-matnr = '000000 '.
Append mm.
Select
Matnr
Spras
Maktx
From Makt
Into corresponding fields of table Makt
For all entries in mm
Where matnr = mm-matnr.
Loop at Makt.
Write :/
Makt-matnr
,
Makt-spras
,
Makt-maktx
.
Endloop.
Output:
34590 ZH puppy
34590 en little dog
If the code is changed:
Report z_ljc222.
Types: Begin of ty_mm,
Matnr type Mara-matnr,
End of ty_mm.
Types: Begin of ty_makt,
Matnr type Mara-matnr,
Spras type Makt-spras,
Maktx type Makt-maktx,
End of ty_makt.
Data mm type table of ty_mm with header line.
Data Makt type table of ty_makt with header line.
Mm-matnr = '000000 '.
Append mm.
Select
Matnr
* Spras
* Maktx
From Makt
Into corresponding fields of table Makt
For all entries in mm
Where matnr = mm-matnr.
Loop at Makt.
Write :/
Makt-matnr
*,
* Makt-spras
*,
* Makt-maktx
.
Endloop.
Output:
34590
The first code outputs two pieces of data, and the second code outputs only one piece. Because only matnr is queried during the second query, matnr is the same for the second two data, and one of them is dropped by distinct. So there is one left.