In the following example we are analyzing the performance between JOIN and For All Entries.
PARAMETERS p_ebeln TYPE ekko-ebeln.
"--Fetching Join timing
GET RUN TIME FIELD DATA(t1).
SELECT a~ebeln, a~bukrs, a~bsart,
b~ebelp, b~matnr, b~menge,
c~maktx,
d~mtart
FROM ekko AS a
INNER JOIN ekpo AS b ON b~ebeln = a~ebeln
INNER JOIN makt AS c ON c~matnr = b~matnr AND
c~spras = @sy-langu
INNER JOIN mara AS d ON d~matnr = b~matnr
INTO TABLE @DATA(itab)
WHERE a~ebeln = @p_ebeln.
GET RUN TIME FIELD DATA(t2).
TYPES: BEGIN OF ty_out,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
bsart TYPE ekko-bsart,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
maktx TYPE makt-maktx,
mtart TYPE mara-mtart,
END OF ty_out.
DATA: wa_out TYPE ty_out,
it_out TYPE TABLE OF ty_out.
"--Fetching For All Entries timing
GET RUN TIME FIELD DATA(t3).
SELECT ebeln, bukrs, bsart
FROM ekko INTO TABLE @DATA(t_ekko)
WHERE ebeln = @p_ebeln.
IF sy-subrc = 0.
SELECT ebeln, ebelp, matnr, menge
FROM ekpo INTO TABLE @DATA(t_ekpo)
FOR ALL ENTRIES IN @t_ekko
WHERE ebeln = @t_ekko-ebeln.
IF sy-subrc = 0.
SELECT matnr, maktx
FROM makt INTO TABLE @DATA(t_makt)
FOR ALL ENTRIES IN @t_ekpo
WHERE matnr = @t_ekpo-matnr.
SELECT matnr, mtart
FROM mara INTO TABLE @DATA(t_mara)
FOR ALL ENTRIES IN @t_ekpo
WHERE matnr = @t_ekpo-matnr.
ENDIF.
ENDIF.
SORT: t_ekko BY ebeln,
t_makt BY matnr,
t_mara BY matnr.
LOOP AT t_ekpo ASSIGNING FIELD-SYMBOL(<w_ekpo>).
wa_out-ebelp = <w_ekpo>-ebelp.
wa_out-matnr = <w_ekpo>-matnr.
wa_out-menge = <w_ekpo>-menge.
READ TABLE t_ekko ASSIGNING FIELD-SYMBOL(<w_ekko>)
WITH KEY ebeln = <w_ekpo>-ebeln BINARY SEARCH.
IF sy-subrc = 0.
wa_out-ebeln = <w_ekko>-ebeln.
wa_out-bukrs = <w_ekko>-bukrs.
wa_out-bsart = <w_ekko>-bsart.
READ TABLE t_makt ASSIGNING FIELD-SYMBOL(<w_makt>)
WITH KEY matnr = <w_ekpo>-matnr BINARY SEARCH.
IF sy-subrc = 0.
wa_out-maktx = <w_makt>-maktx.
ENDIF.
READ TABLE t_mara ASSIGNING FIELD-SYMBOL(<w_mara>)
WITH KEY matnr = <w_ekpo>-matnr BINARY SEARCH.
IF sy-subrc = 0.
wa_out-mtart = <w_mara>-mtart.
ENDIF.
ENDIF.
APPEND wa_out TO it_out.
CLEAR wa_out.
ENDLOOP.
GET RUN TIME FIELD DATA(t4).
"--Compare Join vs For All Entries
DATA(join) = t2 - t1.
DATA(fae) = t4 - t3.
WRITE: /'Join:', join,
/'FAE:', fae.
PARAMETERS p_ebeln TYPE ekko-ebeln.
"--Fetching Join timing
GET RUN TIME FIELD DATA(t1).
SELECT a~ebeln, a~bukrs, a~bsart,
b~ebelp, b~matnr, b~menge,
c~maktx,
d~mtart
FROM ekko AS a
INNER JOIN ekpo AS b ON b~ebeln = a~ebeln
INNER JOIN makt AS c ON c~matnr = b~matnr AND
c~spras = @sy-langu
INNER JOIN mara AS d ON d~matnr = b~matnr
INTO TABLE @DATA(itab)
WHERE a~ebeln = @p_ebeln.
GET RUN TIME FIELD DATA(t2).
TYPES: BEGIN OF ty_out,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
bsart TYPE ekko-bsart,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
maktx TYPE makt-maktx,
mtart TYPE mara-mtart,
END OF ty_out.
DATA: wa_out TYPE ty_out,
it_out TYPE TABLE OF ty_out.
"--Fetching For All Entries timing
GET RUN TIME FIELD DATA(t3).
SELECT ebeln, bukrs, bsart
FROM ekko INTO TABLE @DATA(t_ekko)
WHERE ebeln = @p_ebeln.
IF sy-subrc = 0.
SELECT ebeln, ebelp, matnr, menge
FROM ekpo INTO TABLE @DATA(t_ekpo)
FOR ALL ENTRIES IN @t_ekko
WHERE ebeln = @t_ekko-ebeln.
IF sy-subrc = 0.
SELECT matnr, maktx
FROM makt INTO TABLE @DATA(t_makt)
FOR ALL ENTRIES IN @t_ekpo
WHERE matnr = @t_ekpo-matnr.
SELECT matnr, mtart
FROM mara INTO TABLE @DATA(t_mara)
FOR ALL ENTRIES IN @t_ekpo
WHERE matnr = @t_ekpo-matnr.
ENDIF.
ENDIF.
SORT: t_ekko BY ebeln,
t_makt BY matnr,
t_mara BY matnr.
LOOP AT t_ekpo ASSIGNING FIELD-SYMBOL(<w_ekpo>).
wa_out-ebelp = <w_ekpo>-ebelp.
wa_out-matnr = <w_ekpo>-matnr.
wa_out-menge = <w_ekpo>-menge.
READ TABLE t_ekko ASSIGNING FIELD-SYMBOL(<w_ekko>)
WITH KEY ebeln = <w_ekpo>-ebeln BINARY SEARCH.
IF sy-subrc = 0.
wa_out-ebeln = <w_ekko>-ebeln.
wa_out-bukrs = <w_ekko>-bukrs.
wa_out-bsart = <w_ekko>-bsart.
READ TABLE t_makt ASSIGNING FIELD-SYMBOL(<w_makt>)
WITH KEY matnr = <w_ekpo>-matnr BINARY SEARCH.
IF sy-subrc = 0.
wa_out-maktx = <w_makt>-maktx.
ENDIF.
READ TABLE t_mara ASSIGNING FIELD-SYMBOL(<w_mara>)
WITH KEY matnr = <w_ekpo>-matnr BINARY SEARCH.
IF sy-subrc = 0.
wa_out-mtart = <w_mara>-mtart.
ENDIF.
ENDIF.
APPEND wa_out TO it_out.
CLEAR wa_out.
ENDLOOP.
GET RUN TIME FIELD DATA(t4).
"--Compare Join vs For All Entries
DATA(join) = t2 - t1.
DATA(fae) = t4 - t3.
WRITE: /'Join:', join,
/'FAE:', fae.
It is very clear that in this example JOIN works faster than For All Entries.
No comments:
Post a Comment