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

How to avoid Delete after select error in Code Inspector

svasi_08
Participant
0 Likes
4,491

I have written below logic, its showing as error in SCI as "DELETE statement for result of SELECT statement found" ,

how can I fix this ?

  IF lt_inact_data[] IS NOT INITIAL.
    SELECT * FROM zpaheadcount INTO TABLE @DATA(lt_hcount)
    FOR ALL ENTRIES IN @lt_inact_data
    WHERE kostl = @lt_inact_data-cc(4).
  ENDIF.

  SORT lt_hcount BY kostl.

  DELETE ADJACENT DUPLICATES FROM lt_hcount COMPARING kostl.

What should be written to avoid this Code insepector error? I mean how can I replicated delete under

12 REPLIES 12
Read only

Sandra_Rossi
Active Contributor
3,710

When I see your code, I wonder what lt_hcount contains if lt_inact_data is initial. I guess Code Inspector has the same interrogation...

Read only

Szczerbowski
Contributor
3,710

Hi,

With the code pushdown, you should probably force the Sort/delete on the database.
So select distinct and order by in the SQL rather than ABAP.

And if your code needs to stay like this, use a pragma dedicated to hiding this error (usually the ATC error description mentions which pragma hides the error).

Regards,
Michal

Read only

svasi_08
Participant
0 Likes
3,710

Hi Sandra,

"When I see your code, I wonder what lt_hcount contains if lt_inact_data is initial. I guess Code Inspector has the same interrogation..." 

Dont think thats the issue. Good point any way I have moved code inside the if else condition, but still error exists.

Hi Michal

Hi,
With the code pushdown, you should probably force the Sort/delete on the database.
So select distinct and order by in the SQL rather than ABAP.

And if your code needs to stay like this, use a pragma dedicated to hiding this error (usually the ATC error description mentions which pragma hides the error).

I am not sure how to get only specific data based on the order when I am using distinct and order by, any code help is highly appreiacted.

and there is no Pragma for this to hide, thank you.

Read only

svasi_08
Participant
0 Likes
3,710

Lifting for answers

Read only

Sandra_Rossi
Active Contributor
3,710

Don't you think this would be better:

  IF lt_inact_data[] IS NOT INITIAL.
    SELECT * FROM zpaheadcount INTO TABLE @DATA(lt_hcount)
      FOR ALL ENTRIES IN @lt_inact_data
      WHERE kostl = @lt_inact_data-cc(4).
    IF sy-subrc = 0.
      SORT lt_hcount BY kostl.
      DELETE ADJACENT DUPLICATES FROM lt_hcount COMPARING kostl.
    ENDIF.
  ENDIF.
Read only

svasi_08
Participant
0 Likes
3,710

Hi Sandra,

Looks better the code but not helping to erase the code inspector error.

Read only

svasi_08
Participant
0 Likes
3,710

Looking for some answers, thank you.

Read only

FredericGirod
Active Contributor
3,710

it would be helpful to have the exact structure of this db table.

maybe you could play with subquery

SELECT *  
       FROM zpaheadcount
       WHERE [the_key] EQ ( SELECT [the_key] 
                                    FROM zpaheadcount
                                    FOR ALL ENTRIES IN ...
                                    WHERE kostl = ....  )
      ORDER BY kostl
      INTO TABLE @data(something_with_real_name).
                                    
 
Read only

TheGokke
Active Participant
0 Likes
3,710

select distinct?

Read only

0 Likes
3,710

FOR ALL ENTRIES already forces a SELECT DISTINCT.


Kind regards,
Mateusz
Read only

3,710

FOR ALL ENTRIES forces distinct based on the fields list, as there is a SELECT * there is no distinct

Read only

Szczerbowski
Contributor
0 Likes
3,710

Well, as other people indicated, FOR ALL already implies distinct, so...

Do you really need all them columns, or just a specific one and cost center for key?
Why do you have duplicates in that table for CC, and why don't you care which line you get?

Then maybe group by would help, but then you need to change that for all into ranges IN maybe?

Regards,
Michał