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.

Recent Code Inspector Enhancements 4.3

DATA: lt_monsters TYPE STANDARD TABLE OF ztvc_monsters,

lt_selections TYPE RANGE OF zde_monster_number.

IF lt_selections[] IS NOT INITIAL.

SELECT *

FROM ztvc_monsters

INTO CORRESPONDING FIELDS OF TABLE lt_monsters

FOR ALL ENTRIES IN lt_selections

WHERE monster_number = lt_selections-low.

ENDIF.

Listing 4.3 Check for Empty Tables

If you rerun the Code Inspector, then you’ll find that the error message has vanished

like a phantom into the night.

4.3.2 SELECT * Analysis (14/9/2)

SELECT * analysis is a tool that identifies where you have used SELECT * in your

code so that you can then make sure th at you are only using it when absolutely

necessary. The reason you want to be careful with SELECT * is that it brings back

every single column from the database table being accessed—and this breaks the

golden rule of minimizing the amount of data being transferred from the database

to the application server.

In the example, a SELECT * has just been performed on the monsters table to bring

back every single column. Now, write some code as shown in Listing 4.4 to output

the desired result to the user.

LOOP AT lt_monsters INTO ls_monsters.

WRITE:/ ls_monsters-monster_number,

ls_monsters-hat_size.

ENDLOOP.

Listing 4.4 Ouputting the Result

Even though you’re only interested in two columns of the table, it turns out that

you’ve retrieved every single column from the database. This is naughty, because

it puts undue strain on the system. You should be ashamed of yourself.

Fortunately, you can use the Code Inspector default variant to fix this. Figure 4.18

shows the Search Problematic SELECT * Statements option; all you have to do

is make sure this option is checked in your system.

195

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

Saved successfully!

Ooh no, something went wrong!