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.

2

New Language Features in ABAP 7.4

Tip

In the SQL version of GROUP BY, you can only use column names. Because the internal

table version of GROUP BY is processed wholly within ABAP, you can do all sorts of

groovy things in addition—comparison, method calls, and the like, for example:

LOOP AT lt_monsters INTO DATA( ls_monsters )

GROUP BY( type = ls_monsters-type

crackers = is_it_mad( ls_monsters-number )

ASSIGNING FIELD-SYMBOLS( <ls_monster_group> ).

This takes quite a bit of experimentation before you get comfortable with it. The most

difficult part, as with all of these new constructs, is marrying new abilities to real-world

problems, such as the customer open item example presented earlier.

2.6.9 Extracting One Table from Another

There are two new ways of extracting on e internal table from another that were

introduced with 7.4, and both use the constructor operator FILTER. The next subsection

will talk first about using the FILTER operator with conditional logic and

then as a FOR ALL ENTRIES operation on an internal table.

FILTER with Conditional Logic

To understand the process of extracting one table from another in ABAP 7.4,

return to the monsters example. Once again, you have a big table of all the monsters,

and you want to extract a smaller internal table with just the averagely mad

monsters. Normally, you would just loop through the big table and append lines

to your new table, as shown in Listing 2.65.

LOOP AT lt_all_monsters INTO ls_all_monsters

WHERE sanity > 25

AND sanity < 75.

CLEAR ls_averagely_mad_monsters.

MOVE-CORRESPONDING ls_all_monsters TO ls_averagely_mad_monsters.

APPEND ls_averagely_mad_monsters TO lt_averagely_mad_monsters.

ENDLOOP. "All Monsters

Listing 2.65 Extracting One Table from Another before 7.4

As of ABAP 7.4 (SP 8), you can do the same thing by using the constructor operator

FILTER in the fashion shown in Listing 2.66.

124

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

Saved successfully!

Ooh no, something went wrong!