3

I am comparing the SELECT FOR ALL ENTRIES vs LOOP SELECT SINGLE and I am having a big difference between results.

Somebody can help me with this? What is the difference?

SELECT ekko~ebeln
    ekpo~ebelp
    ekko~bstyp
    ekko~bsart
    ekko~lifnr
    ekko~ekgrp
    ekko~aedat
    ekko~knumv
    ekko~zterm
    ekko~zbd1t
    ekpo~matnr
    ekpo~txz01
    ekpo~menge
    ekpo~meins
    ekpo~netpr
    ekpo~peinh
    ekpo~knttp
    ekpo~afnam
    ekpo~wepos
INTO TABLE t_ekpo
FROM ekko
INNER JOIN ekpo ON
    ekpo~ebeln EQ ekko~ebeln
WHERE ekko~lifnr IN s_lifnr
    AND ekko~ekgrp IN s_ekgrp
    AND ekko~ebeln IN s_ebeln
    AND ekko~aedat IN s_aedat
    AND ekko~bsart IN s_bsart
    AND ekko~bstyp EQ 'F'
    AND ekko~loekz EQ space
    AND ekpo~matnr IN s_matnr
    AND ekpo~ebelp IN s_ebelp
    AND ekpo~loekz EQ space.

SELECT FOR ALL ENTRIES returns 9.528 records

SELECT ebeln
    ebelp
    zekkn
    vgabe
    gjahr
    belnr
    buzei
    budat
    menge
    shkzg
FROM ekbe
INTO TABLE t_ekbe
FOR ALL ENTRIES IN t_ekpo
WHERE ebeln EQ t_ekpo-ebeln
    AND ebelp EQ t_ekpo-ebelp
    AND vgabe IN ('1','2').

LOOP SELECT SINGLE returns 7.336 records

LOOP AT t_ekpo INTO gs_ekpo.

    CLEAR gs_ekbe.

    SELECT SINGLE  ebeln
                 ebelp
                 zekkn
                 vgabe
                 gjahr
                 belnr
                 buzei
                 budat
                 menge
                 shkzg
    FROM ekbe
    INTO gs_ekbe
    WHERE ebeln EQ gs_ekpo-ebeln
        AND ebelp EQ gs_ekpo-ebelp
        AND vgabe IN ('1','2').

    APPEND gs_ekbe TO T_ekbe.

ENDLOOP.
4

2 回答 2

9

EKBE有更多的关键字段,而不仅仅是EBELNand EBELP,所以一个唯一的EBELN/EBELP对可以有更多的条目。使用 theSELECT SINGLE您将不会获得这些额外的条目,而使用 the 您会获得FOR ALL ENTRIES。根据您的需要,只有其中之一将为您提供正确的数据集。

于 2013-10-09T20:03:03.223 回答
2

只想补充。 SELECT SINGLE里面LOOP是非常糟糕的主意。如果您需要ebeln+ ebelpfromekpo只需将这两个选择到附加表中lt_ekpo(不要忘记DISTINCT在此选择中)并将其用于FOR ALL ENTRIES.

于 2013-10-30T21:13:31.903 回答