‎2020 Mar 09 3:59 PM
I think I need to make a new thread. Thanks for the help with my previous quesiton.
I have two DELETE statements showing in code inspector. Why would it be a performance issue?
Any suggestions?
SELECT ordid
FROM /bmw/ts_1143_log AS a
WHERE ordid IN @s_ordid
AND order_comp_flag EQ @space
AND
EXISTS ( SELECT *
FROM zmrp
WHERE cno_order EQ a~ordid
AND cid_status IN @s_status
AND cno_assyl IN @s_assyl )
INTO TABLE @gt_log.
IF sy-subrc EQ 0.
SORT gt_log
BY ordid.
DELETE ADJACENT DUPLICATES FROM gt_log
COMPARING ordid ##CI_SORTED.
ENDIF.
and
LOOP AT lt_plaf
ASSIGNING FIELD-SYMBOL(<fs_plaf>).
READ TABLE lt_zmrp
INTO DATA(ls_zmrp)
WITH KEY cno_order = <fs_plaf>-plnum+3(7).
IF sy-subrc NE 0.
MOVE abap_true TO <fs_plaf>-xdel .
ENDIF.
ENDLOOP.
DELETE lt_plaf
WHERE xdel EQ abap_true.
‎2020 Mar 09 4:26 PM
DELETE Statement 1:
You are again transferring data from the database to the application server which you don't need. You SELECT the field ORDID and you eliminate duplicated entries right after. The SELECT statement can do exactly that directly in the database: SELECT DISTINCT ordid ...
DELETE Statement 2:
If you have a NW 7.40 or newer system please do not use the MOVE statement any more. The code is way more readable if the target is always on the left side and the source on the right side.
But to the problem: Actually you don't need the additional flag. As you don't need to do anything with the <fs_plaf> after setting the flag, you can delete the line from the internal table right away:
LOOP AT lt_plaf
ASSIGNING FIELD-SYMBOL(<fs_plaf>).
READ TABLE lt_zmrp
WITH KEY cno_order = <fs_plaf>-plnum+3(7)
TRANSPORTING NO FIELDS.
IF sy-subrc NE 0.
DELETE lt_plaf.
ENDIF.
ENDLOOP.Additionally I removed the data copying from the READ statement. You don't need the result so you can omit the data transfer.
The best way would be to never read those lines and do a join with the statement where lt_zmrp is read.
‎2020 Mar 09 4:26 PM
DELETE Statement 1:
You are again transferring data from the database to the application server which you don't need. You SELECT the field ORDID and you eliminate duplicated entries right after. The SELECT statement can do exactly that directly in the database: SELECT DISTINCT ordid ...
DELETE Statement 2:
If you have a NW 7.40 or newer system please do not use the MOVE statement any more. The code is way more readable if the target is always on the left side and the source on the right side.
But to the problem: Actually you don't need the additional flag. As you don't need to do anything with the <fs_plaf> after setting the flag, you can delete the line from the internal table right away:
LOOP AT lt_plaf
ASSIGNING FIELD-SYMBOL(<fs_plaf>).
READ TABLE lt_zmrp
WITH KEY cno_order = <fs_plaf>-plnum+3(7)
TRANSPORTING NO FIELDS.
IF sy-subrc NE 0.
DELETE lt_plaf.
ENDIF.
ENDLOOP.Additionally I removed the data copying from the READ statement. You don't need the result so you can omit the data transfer.
The best way would be to never read those lines and do a join with the statement where lt_zmrp is read.