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.

Database Access 2.1

efficient way to do this is by way of an inner join. However, it is somewhat

tedious to list all of the fields from the main table, as you can see in Listing 2.7.

SELECT zt_monsters~monster_name zt_monsters~monster_number

zt_monsters~sanity zt_monsters~strength

zt_monsters~hat_size zt_monsters~number_of_heads

zt_hats~bar_code

FROM zt_monsters

INNER JOIN zt_hats

ON zt_monsters~hat_size = zt_hats~hat_size

INTO CORRESPONDING FIELDS OF TABLE lt_monsters

WHERE monster_name = 'FRED'.

Listing 2.7 All Fields from Main Table

The preceding code reads everything from the monster table but just one minor

detail from the hat table. In 7.4, you can achieve th e same thing in a different

way, as shown in Listing 2.8.

SELECT zt_monsters~*

zt_hats~bar_code

FROM zt_monsters

INNER JOIN zt_hats

ON zt_monsters~hat_size = zt_hats~hat_size

WHERE monster_name = 'FRED'

INTO DATA(lt_monsters).

Listing 2.8 Reading Everything from One Table during an Inner Join

The key here is the asterisk. It acts just like the wild card in SELECT * and as such

can be abused if you really want not all the fields of the table, but just half of

them.

Warning: Houston, We Have a Problem

As always, using asterisks in such cases is the easy way out, but it slows down database

performance and—when you are creating the table at the same time—memory consumption

as well. This just proves that the more tools are at one’s disposal, the greater

the damage you can do with them if they are not used properly.

In addition to the asterisk functionality in ABAP 7.4, the syntax of inner joins has

also been extended so that now you have much more flexibility in defining the

relationship between the tables. An example of this is shown in Listing 2.9.

INNER JOIN zt_monster_pets

ON zt_monster_pets~owner EQ zt_monsters~monster_number

89

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

Saved successfully!

Ooh no, something went wrong!