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

However, in version 7.4, you can use the VALUE statement and thus achieve the

same effect with fewer lines of code (Listing 2.13).

TYPES: l_typ_plant_type TYPE RANGE OF zsmm_plant_master.

lt_plants = lo_plant_query(

VALUE l_typ_plant_type(

option = ‘EQ’

sign = ‘I’

low = ‘L’ ) ) ). "Laboratory

Listing 2.13 Database Query with VALUE

You could add more than one line to the query table if you wanted—for example,

if you were interested in retrieving gr aveyard data as well. You’ve avoided the

need for an intermediate internal table ( LR_PLANT_TYPE) and avoided the work

area to build up the lines of that intermediate table.

2.2.5 Filling Internal Tables from Other Tables Using FOR

How well I remember starting to prog ram when I was 14, with the good old

ZX81. The BASIC language I programmed in then had constructs like FOR x = 1 TO

10, which meant you were going to loop ten times, with the variable X increasing

by one each time. Well, the FOR command has now arrived in the ABAP world;

take a look at what it is for (if you’ll forgive the pun).

You read about the VALUE statement in the last section; you can use this to fill an

internal table, as in Listing 2.14.

DATA: lt_monsters TYPE STANDARD TABLE OF ztvc_monsters.

lt_monsters = VALUE#(

( monster_name = 'FRED' monster_number = 1 )

( monster_name = 'HUBERT' monster_number = 2 ) ).

Listing 2.14 Fill Internal Table

That’s great as an example, but in real life you either fill internal tables from the

database or from other internal tables; almost never do you fill them with hardcoded

values. Prior to 7.4, you could only fill one internal table from another

table if the two tables had identical column structures, and you had to add all the

lines of one table to another:

APPEND LINES OF lt_green_monsters TO lt_all_monsters.

94

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

Saved successfully!

Ooh no, something went wrong!