Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Code Inspector: DELETE statement for result of SELECT statement found

Former Member
0 Likes
7,917

DELETE statement for result of SELECT statement found

  SELECT plnum,
         rsnum,
         meins,
         ' ' AS xdel
    FROM plaf AS a
   WHERE plnum IN @gt_wb
    AND  paart EQ @gc_pe
    AND  pstmp IN @gr_pstmp
    AND
    EXISTS ( SELECT *
               FROM resb AS b
              WHERE rsnum    EQ a~rsnum
                AND plnum    EQ a~plnum
                AND werks    EQ @p_werks
                AND matnr    IN @s_matnr
                AND zzspparf IN @s_tfam
                AND zzspsgrp IN @s_vergr )

    INTO TABLE @DATA(lt_plaf).

  IF sy-subrc <> 0.

  ENDIF.

  DELETE lt_plaf
    WHERE plnum(3) NE 'VH_'.

Any inputs on the fix?

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
3,974

Add the plnum LIKE 'VH_%' in the SELECT WHERE clause, or delete those from @gt_wb before SELECT.

DELETE statement for result of SELECT statement found

  SELECT plnum,
         rsnum,
         meins,
         ' ' AS xdel
    FROM plaf AS a
   WHERE plnum IN @gt_wb
    AND  paart EQ @gc_pe
    AND  pstmp IN @gr_pstmp
    AND
    EXISTS ( SELECT *
               FROM resb AS b
              WHERE rsnum    EQ a~rsnum
                AND plnum    EQ a~plnum
                AND werks    EQ @p_werks
                AND matnr    IN @s_matnr
                AND zzspparf IN @s_tfam
                AND zzspsgrp IN @s_vergr )

    INTO TABLE @DATA(lt_plaf).

  IF sy-subrc <> 0.

  ENDIF.

  DELETE lt_plaf
    WHERE plnum(3) NE 'VH_'.

Any inputs on the fix?

4 REPLIES 4
Read only

Sathya_Gunasekaran
Contributor
3,974

It suggests that instead of selecting some records & deleting them, your select should exlude them. Can't you just add the condition ( plnumb LIKE 'VH_%) to the where clause ?

Read only

RaymondGiuseppi
Active Contributor
3,975

Add the plnum LIKE 'VH_%' in the SELECT WHERE clause, or delete those from @gt_wb before SELECT.

Read only

Former Member
0 Likes
3,974

Thank you raymond.giuseppi it worked. I thought 'LIKE' would impact performance issue but it did not.

Read only

Former Member
0 Likes
3,974

Posted another two on the wrong thread. My apologies.

I have remaining errors with the same concern.

1.)

  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.

2.)

  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.

Really appreciate all the help!