关于 FOR ALL ENTRIES
- 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.
运行结果如下:
- FOR ALL ENTRIES 的表不能为空,不详述,select 前需要判断内表是否为空。
- FOR ALL ENTRIES 表去重复,排序,效率问题。