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.

Top-Down Development 15.2

SELECT *

FROM zcds_monsters

INTO lt_specalized_monsters.

Listing 15.6 Calling a CDS View from within an ABAP Program

Latest CDS View Built-in Functions

Just to give an indication of how fast the functionality of CDS views are evolving, at the

time of writing two support packs were released in fairly quick succession: SP 8 and SP

9. In SP 8, a whole bunch of new built-in functions became available—for example,

FLOOR, REPLACE, MOD, ABS, ROUND, and COALESCE. Also in SP 8, support was added for

when the data in the database table is comprised of amounts in different currencies or

quantities in different units of measures. There are built-in functions CURRENCY_CON-

VERSION and UNIT_CONVERSION, which enable the database to convert all the currency

values into Vietnamese Dongs before sending the data back to the application server or

to convert everything into kilograms so that you get a meaningful total quantity.

In SP 9, improvements were made to the lifecycle management of CDS views: Before, it

was very difficult to change an existing CDS view when the existing database table had

data inside it, and now that problem has gone away. In addition, in SP 9 the concept of

an enumeration was introduced into the DDL syntax. Most other programming languages

have this concept; it can best be thought of as a domain with several possible

values for a data element, only defined inside a block of code as opposed to inside SE11.

It’s also possible to code a CDS view with parameters. Again, the process is

slightly different than in traditional ABAP. Transaction SE11 views allow you to

define selection parameters, but they are hard-coded (e.g., the monster color is

set as GREEN). When dynamic selections are required (e.g., the user chooses what

he wants on a selection screen), you would add WHERE clauses in your ABAP program

to restrict what the view brought back. An example of this is shown in Listing

15.7.

SELECT *

FROM zv_monster_views

WHERE color EQ p_color

AND sanity IN s_sanity.

Listing 15.7 Coding Parameters in Traditional ABAP

You can do the exact same thing when re ferring to a CDS view within your program,

but in addition, starting with SP 8, in CDS views you can define them with

parameters that are passed in via the ABAP program at runtime, as shown in Listing

15.8.

667

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

Saved successfully!

Ooh no, something went wrong!