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.

2

New Language Features in ABAP 7.4

Tip

Note that the code includes a TYPE declaration. To save time, some programmers would

just define the internal table as being of the data dictionary type. However, this is a bit

of a waste of memory.

In older versions of ABAP, if you declared a TYPE and then suddenly wanted to

retrieve an extra field, then you would need to make the change in two places: in

the definition and in the SELECT statement. You might forget to make one of those

changes—I know I have—and although the syntax check will warn you of this it

might slip through the net.

In 7.4, however, you can not only skip the TYPE definition but the internal table

declaration as well. An example of this is shown in Listing 2.6.

SELECT monster_name monster_number sanity

FROM zt_monsters

WHERE monster_name = 'FRED'

INTO TABLE DATA(lt_monsters).

Listing 2.6 Defining an Internal Table Based on the SQL Query

As you can see, there is no need to declare either a TYPE or an internal table. The

table is created on the spot at the instan t the database is read, and the format of

the table is taken from the types of the data fields you are retrieving. This way,

there is no way that two lists of fields can get out of sync, because there is only

one list.

This new technique also works for structures if you are doing a SELECT SINGLE on

multiple database fields and for elemen tary data elements if you are doing a

SELECT SINGLE on just one database field. Furthermore, if you use a construct

such as KUNNR AS SHIP_TO in your select statement, then the name of the column

in your internal table will be ship_to. (This sort of thing is useful, because you

might be doing a join, for example, and KUNNR might have different meanings in

different tables: the customer in VBAK and the ship-to in LIKP.)

2.1.4 Inner Join Improvements

If you’ve ever coded before (and if you’ re reading this book, I guess you have!),

then you know that it’s fairly common to need to read every single field of one

database table and also one or two fiel ds from another related table. The most

88

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

Saved successfully!

Ooh no, something went wrong!