# 提高[FOR ALL ENTRIES]查询的效率

DATA: it_mara TYPE STANDARD TABLE OF mara,
wa_mara TYPE mara,
it_makt TYPE STANDARD TABLE OF makt,
wa_makt TYPE makt,
it_temp_mara TYPE STANDARD TABLE OF mara,
wa_temp_mara TYPE mara.
* Get all the records from MARA
SELECT *
FROM mara
INTO TABLE it_temp_mara.
IF sy-subrc = 0.
IF NOT it_temp_mara[] IS INITIAL.
* 具有重复数据的内表
DO 100 TIMES.
APPEND LINES OF it_temp_mara TO it_mara.
ENDDO.
IF NOT it_mara[] IS INITIAL.
* Select MAKT
PERFORM select_makt.
* 排过序的内表
SORT it_mara BY matnr.
PERFORM select_makt.
* 删除了重复数据的内表
DELETE ADJACENT DUPLICATES FROM it_mara COMPARING matnr.
PERFORM select_makt.
ENDIF.
ENDIF.
ENDIF.
*&---------------------------------------------------------------------*
*& Form select_makt
*&---------------------------------------------------------------------*
* Select data friom MAKT
*----------------------------------------------------------------------*
FORM select_makt .
DATA: t1 TYPE i,
t2 TYPE i,
tmin TYPE i.
REFRESH it_makt[].
GET RUN TIME FIELD t1.
SELECT *
FROM makt
INTO TABLE it_makt
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr.
GET RUN TIME FIELD t2.
tmin = t2 - t1.
tmin = tmin .
WRITE:/ ' Time(ms) = ', tmin.
ENDFORM.
*----------------------------------------------------------------------*

2007/03/22 Program ZTEST00100 1

Time(ms) = 1,087,713 "具有重复数据的内表
Time(ms) = 1,077,911 "排过序的内表
Time(ms) = 11,610 "删除了重复数据的内表

·使用FOR ALL ENTRIES 时内表中不要有重复的数据

·对内表进行排序

• 博文量
167
• 访问量
124755