Distinct function in ABAP for all entries in

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.