FOR ALL ENTRIES 的使用技巧

关于 FOR ALL ENTRIES

  1. for all entries select 主键要添加全,否则会丢失数据。例:
    MARC 原始数据如下,关于物料 281713124000 共有记录5条。
    在这里插入图片描述
DATA: BEGIN OF ls_mara,
matnr LIKE mara-matnr,
END OF ls_mara.
DATA: lt_mara LIKE TABLE OF ls_mara.

DATA: BEGIN OF ls_marc,
matnr LIKE marc-matnr,
pstat LIKE marc-pstat,
END OF ls_marc.


DATA: lt_marc LIKE TABLE OF ls_marc.
ls_mara-matnr =  '000000281713124000'.
APPEND ls_mara TO lt_mara.


SELECT matnr
       pstat
FROM marc
INTO CORRESPONDING FIELDS OF TABLE lt_marc
FOR ALL ENTRIES IN lt_mara
WHERE matnr = lt_mara-matnr.


LOOP AT lt_marc INTO ls_marc.
  WRITE:/ ls_marc-matnr, ls_marc-pstat.
  CLEAR: ls_marc.
ENDLOOP.

运行结果如下,只有两条,重复的 ‘281713124000’ 'A ’ 已经被过滤。
在这里插入图片描述
全部主键添加,换成select * 之后

DATA: BEGIN OF ls_mara,
matnr LIKE mara-matnr,
END OF ls_mara.
DATA: lt_mara LIKE TABLE OF ls_mara.

DATA: BEGIN OF ls_marc,
matnr LIKE marc-matnr,
pstat LIKE marc-pstat,
END OF ls_marc.


DATA: lt_marc LIKE TABLE OF ls_marc.
ls_mara-matnr =  '000000281713124000'.
APPEND ls_mara TO lt_mara.
APPEND ls_mara TO lt_mara.
APPEND ls_mara TO lt_mara.
APPEND ls_mara TO lt_mara.


SELECT *
FROM marc
INTO CORRESPONDING FIELDS OF TABLE lt_marc
FOR ALL ENTRIES IN lt_mara
WHERE matnr = lt_mara-matnr.


LOOP AT lt_marc INTO ls_marc.
  WRITE:/ ls_marc-matnr, ls_marc-pstat.
  CLEAR: ls_marc.
ENDLOOP.

运行结果如下:
在这里插入图片描述

  1. FOR ALL ENTRIES 的表不能为空,不详述,select 前需要判断内表是否为空。
  2. FOR ALL ENTRIES 表去重复,排序,效率问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值