0
点赞
收藏
分享

微信扫一扫

abap 中 for all entries in 中的 distinct 功能

李雨喵 2023-09-18 阅读 10


用for all entries in 做查询的时候,能够进行自动的distinct,


请看如下的例子:

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 = '000000000000034590'.
       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.

 

输出:

34590              ZH 小狗
34590              EN little dog

 

 

如果代码改成:

 

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 = '000000000000034590'.
       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.

 

输出为:

 

34590

 

第一段代码中输出两条数据,而第二段代码只输出了一条。因为第二段中查询的时候只查询了 matnr ,二两条数据的matnr是一样的,其中的一条被 distinct 掉了。所以就剩下一条了。

举报

相关推荐

0 条评论