‎2020 Aug 12 2:18 PM
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
‎2020 Aug 12 2:35 PM
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...
‎2020 Aug 12 3:02 PM
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
‎2020 Aug 12 4:31 PM
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.
‎2020 Aug 12 7:11 PM
‎2020 Aug 12 7:44 PM
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.
‎2020 Aug 12 8:29 PM
Hi Sandra,
Looks better the code but not helping to erase the code inspector error.
‎2020 Aug 12 9:13 PM
‎2020 Aug 13 6:36 AM
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).
‎2020 Aug 13 7:16 AM
‎2020 Aug 13 7:45 AM
FOR ALL ENTRIES already forces a SELECT DISTINCT.
‎2020 Aug 13 7:56 AM
FOR ALL ENTRIES forces distinct based on the fields list, as there is a SELECT * there is no distinct
‎2020 Aug 13 10:43 AM
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ł