我想把这个SELECT-ENDSELECT
转换成FOR ALL ENTRIES
,以获得更好的性能。
LOOP AT it_zgd_check_smc into wa_zgd_check_smc.
SELECT *
FROM ever
INTO wa_ever
WHERE anlage EQ wa_euiinstln-anlage
AND einzdat <= wa_zgd_check_smc_st-data_inizio
AND auszdat >= wa_zgd_check_smc_st-data_inizio.
ENDSELECT.
"---logic---"
ENDLOOP.
有两个表:EUIINSTLN
和IT_ZGD_CHECK_SMC
。如何将其转换为for all entries
?
谢谢所有。问候。
要去掉SELECT - ENDSELECT
,您可以简单地使用INTO TABLE
并在之后循环它。这通常更快,而且(几乎)每次都可以这样做。
data: lt_ever like table of wa_ever.
LOOP AT it_zgd_check_smc into wa_zgd_check_smc.
SELECT *
FROM ever
INTO TABLE lt_ever
WHERE anlage EQ wa_euiinstln-anlage
AND einzdat <= wa_zgd_check_smc_st-data_inizio
AND auszdat >= wa_zgd_check_smc_st-data_inizio.
LOOP AT lt_ever INTO wa_ever.
"Put here what was in the SELECT - ENDSELECT previously.
ENDLOOP.
ENDLOOP.
那么你可以使用FOR ALL ENTRIES
来摆脱一个外部循环。如果使用此功能,则可以简单地将工作区域替换为表格。但是您应该确保,您正在使用的表不是空的。否则,WHERE语句将表现得像一个空范围(换句话说,它将被忽略),因此它将提供数据库中的所有条目。所以它会给你这样的东西:
data: lt_ever like table of wa_ever.
IF it_zgd_check_smc_st IS NOT INITIAL.
SELECT *
FROM ever
INTO TABLE lt_ever
FOR ALL ENTRIES IN it_zgd_check_smc_st
WHERE anlage EQ wa_euiinstln-anlage
AND einzdat <= it_zgd_check_smc_st-data_inizio
AND auszdat >= it_zgd_check_smc_st-data_inizio.
loop at lt_ever into wa_ever.
"Put here what was in the SELECT - ENDSELECT previously.
endloop.
ENDIF.
您不能为所有条目使用第二个表,但是您可以为ANLAGE - field构建一个范围。。只要确保你不再使用空范围。
DATA: lt_ever LIKE TABLE OF wa_ever.
DATA: lr_anlage TYPE RANGE OF anlage.
DATA: lrs_anlage LIKE LINE OF lr_anlage.
lrs_anlage-sign = 'I'.
lrs_anlage-option = 'EQ'.
LOOP AT euiinstln INTO wa_euiinstln.
lrs_anlage-low = wa_euiinstln-anlage.
APPEND lrs_anlage TO lr_anlage.
ENDLOOP.
IF it_zgd_check_smc_st IS NOT INITIAL AND
lr_anlage IS NOT INITIAL.
SELECT *
FROM ever
INTO TABLE lt_ever
FOR ALL ENTRIES IN it_zgd_check_smc_st
WHERE anlage IN lr_anlage
AND einzdat <= it_zgd_check_smc_st-data_inizio
AND auszdat >= it_zgd_check_smc_st-data_inizio.
LOOP AT lt_ever INTO wa_ever.
"Put here what was in the SELECT - ENDSELECT previously.
ENDLOOP.
ENDIF.
我不知道代码应该做什么,所以我不知道这对你有多大用处。未构建范围并遍历euiinstln - table应该同样快,因为EVER - Database应该在分析字段上有一个索引。