14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4

ABAP Test Cockpit

4.3.4 SELECT with DELETE (14/9/2)

The SELECT with DELETE check is all about situations in which you bring back

more records from the database than you really want and then get rid of the surplus

ones in your code, which, as you’ll see, is a silly thing to do. To understand

how this check works, take a look at an example. Listing 4.6 retrieves some database

records into an internal table and then deletes the rows you do not like.

SELECT *

FROM ztvc_monstr_beds

INTO CORRESPONDING FIELDS OF TABLE lt_beds

FOR ALL ENTRIES IN lt_monsters

WHERE monster_number EQ lt_monsters-monster_number.

DELETE lt_beds WHERE monster_number > 500.

Listing 4.6 Select Too Many Records and Delete the Unwanted Ones

As you will no doubt have guessed, this is not the optimal way to perform this

task. Instead of getting every single bed and then discarding the records relating

to certain monsters within the code, the restriction condition should be in the

SELECT statement itself, thus minimizing the amount of data transferred between

the database and the server. (You might also say no one would ever do this, but I

have seen something similar more times than I would like.) Fortunately, there is

now a Code Inspector check to detect such nonsense. Figure 4.22 shows the check

(Search SELECT Statement with DELETE Statement ), and Figure 4.23 shows

the result of the check.

Figure 4.22 Code Inspector: SELECT with DELETE Check

Figure 4.23 SELECT with DELETE Error Message

198

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!