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.

15

ABAP Programming for SAP HANA

@ABAPCatalog.sqlViewName: 'ZV_MONSTERS_PARAMETERS'

Define view zcds_monster_parameters

with parameters p_sanity_low:ZDE_MONSTER_SANITY,

p_sanity_high:ZDE_MONSTER_SANITY,

p_color:ZDE_MONSTER_COLOR

As select from zt_monsters

{ key monster_number,

monster_name,

color,

sanity,

strength }

WHERE color = p_color AND

sanity between p_sanity_low and p_sanity_high;

Listing 15.8 Defining a CDS View with Parameters

From your program, you then write a statement like the one in Listing 15.9.

SELECT *

FROM zcds_monster_parameters(

p_color = @p_color,

p_sanity_low = @s_sanity-low

p_sanity_high = @s_sanity-high )

INTO TABLE @(lt_colorful_mad_monsters).

Listing 15.9 Calling a CDS View with Parameters

You could also have a mixture of parameters and normal WHERE clauses. The main

advantage of parameters is that inside CDS views you can call functions, and an

input parameter to the CDS view as a wh ole can be passed in to function calls

made within the CDS view. With WHERE clauses, you can only refer to the list of

database fields defined in the view; parameters can be anything you feel like.

As of ABAP version 7.4 SP 8, there is on ly support for some databases (e.g., SAP

HANA) to enable an ABAP program to do a SELECT on CDS views with parameters.

The roadmap from SAP says that, ultimately, all databases will be able to take

advantage of this feature.

View Appends

Another gap that has been plugged is that, previously, if SAP had created a view, then

in SE11 you could add an APPEND structure to it with some fields of your own (e.g., Z

fields you have added to VBAK). You could not do this in SAP-supplied CDS views until

ABAP 7.4 SP 8; thereafter, you can get the same result by creating a DDL as follows:

@AbapCatalog.sqlViewAppendName: 'ZA_STANDARD_EXTENSION'

extend view standard_thing with zcds_standard_extension

668

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

Saved successfully!

Ooh no, something went wrong!