14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Recent Code Inspector Enhancements 4.3

Let’s turn, once again, to the ongoing monster example. As you know, monsters

tend to hide under beds, so you want to do a database query to find out what

beds the monsters selected earlier have been hiding under (Listing 4.5).

DATA: lt_beds TYPE STANDARD TABLE OF ztvc_monstr_beds.

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.

Listing 4.5 SELECT * Check for Monsters under the Bed

If you take a look at this code, you can probably tell that an inner join is a better

choice than what’s been done here. Will ATC tell you the same thing? Set up the

check as in Figure 4.20 to find out.

Figure 4.20 Improving FOR ALL ENTRIES

Sure enough, the warning in Figure 4.21 tells you to improve the structure of

your code so that you only have one SELECT statement. The reason for the warning

is that if you were to take two pr ograms, both selecting the same data, one

using an inner join and one using a FOR ALL ENTRIES, and run them one at a time,

each time using Transaction ST05 to pe rform an SQL trace, then you would find

that an inner join has only one SQL entry no matter what, whereas a FOR ALL

ENTRIES has a large number of SQL entries increasing in a linear fashion with the

amount of data to be retrieved.

Figure 4.21 FOR ALL ENTRIES Error Message

197

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

Saved successfully!

Ooh no, something went wrong!