14
Getting Started Newsletters Store Products Services & Support About SCN Downloads Industries Training & Education Partnership Developer Center Lines of Business University Alliances Events & Webinars Innovation Log On Join Us Hi, Guest Search the Community Activity Communications Actions Browse ABAP Development 0 Tweet 14 Recap With ABAP 7.40, SP05 the ABAP Core Data Services, short ABAP CDS, were introduced. The ABAP Core Data Services implement the general CDS concept of SAP (that is also available for HANA as HANA CDS) for AS ABAP. They use a DDL to define CDS views that implement a semantic data model in the ABAP Dictionary. The power of ABAP CDS is, that it is open, meaning database independent (with some exceptions if the databases do not yet cover all the functionalities as e.g. views with parameters). You can use the DDL of ABAP CDS in Eclipse based ADT to create rather complex views that exceed the capabilities of the classical database views created in SE11 by far. Technically, from the source code of a CDS view, a classical database view is generated. We call this the CDS database view. You can display the fields of this view in SE11 but not change them. Especially, you can see the real database object the SQL view that is created from the view definition on the database in SE11. But this CDS database view serves mainly the internal technical purpose to realize the view in the dictionary. You can, but you should not use it in ABAP programs. Instead, you work with the CDS entitiy, whose name is defined behind DEFINE VIEW. Only the entity carries the full capabilities of the CDS view, like semantical information, client handling, connection to authority checks (planned), and so on. You can use the CDS entity behind TYPE for declaring work areas and in Open SQL in ABAP programs. You use these views for the famous code push down in order to put more analytic work to the database. If the functionality of a view is only needed once, of course you can still use Joins, SQL expressions, subqueries, ... in Open SQL for this code push down. But if you want to reuse a view, need semantical or technical capabilities of CDS that exceed those of Open SQL (but we try to keep the technical capabilities on the same level, e.g., CDS knows UNION, Open SQL will know UNION with SP12) or you just want to push down the full data model to the database, you use CDS. And in fact I've seen very, very extensive sophisticated views already now (oh boy ...). But I'm a simple mind, not a business modelling guru. In order to understand the basics, I work with simple examples. Just to give you two of those: @AbapCatalog.sqlViewName: 'DEMO_CDS_JOIN' define view demo_cds_scarr_spfli (id, carrier, flight, departure, destination) as select from spfli join scarr on scarr.carrid = spfli.carrid { key spfli.carrid, key scarr.carrname, key spfli.connid, spfli.cityfrom, spfli.cityto } This is a simple join as you could also define it in classical SE11. The name of the CDS entity is demo_cds_scarr_spfli and the name of the generated CDS database view is DEMO_CDS_JOIN. One difference to a classical view is the fact, that a CDS entity that uses client dependent data sources is client dependent by default but never has a client field. The client handling is done implicitly without shining through here. Another view, that does exactly the same as the above one but shows a new kind of modelling capability: @AbapCatalog.sqlViewName: 'DEMO_CDS_ASSOC' define view demo_cds_association (id, carrier, flight, departure, destination ) as select from spfli association [1..1] to scarr as spfli_scarr on $projection.carrid = spfli_scarr.carrid { key spfli.carrid, key spfli_scarr.carrname, ABAP News for 7.40, SP08 ABAP Core Data Services (CDS) Posted by Horst Keller in ABAP Development on Oct 10, 2014 11:05:43 AM Share 5 2 Like

ABAP News for 7.40, SP08 - ABAP Core Data Servi

Embed Size (px)

DESCRIPTION

ABAP Core Data Ser

Citation preview

Page 1: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 1/14

Getting Started Newsletters Store

Products Services & Support About SCN Downloads

Industries Training & Education Partnership Developer Center

Lines of Business University Alliances Events & Webinars Innovation

Log On Join UsHi, Guest Search the Community

Activity Communications Actions

Browse

ABAP Development

0 Tweet 14

Recap With ABAP 7.40, SP05 the ABAP Core Data Services, short ABAP CDS, were introduced. The ABAP Core DataServices implement the general CDS concept of SAP (that is also available for HANA as HANA CDS) for AS ABAP.They use a DDL to define CDS views that implement a semantic data model in the ABAP Dictionary. The power of ABAP CDS is, that it is open, meaning database independent (with some exceptions if the databases donot yet cover all the functionalities as e.g. views with parameters). You can use the DDL of ABAP CDS in Eclipsebased ADT to create rather complex views that exceed the capabilities of the classical database views created inSE11 by far. Technically, from the source code of a CDS view, a classical database view is generated. We call this theCDS database view. You can display the fields of this view in SE11 but not change them. Especially, you can see thereal database object the SQL view that is created from the view definition on the database in SE11. But this CDSdatabase view serves mainly the internal technical purpose to realize the view in the dictionary. You can, but youshould not use it in ABAP programs. Instead, you work with the CDS entitiy, whose name is defined behind DEFINEVIEW. Only the entity carries the full capabilities of the CDS view, like semantical information, client handling,connection to authority checks (planned), and so on. You can use the CDS entity behind TYPE for declaring workareas and in Open SQL in ABAP programs. You use these views for the famous code push down in order to put more analytic work to the database. If thefunctionality of a view is only needed once, of course you can still use Joins, SQL expressions, subqueries, ... in OpenSQL for this code push down. But if you want to reuse a view, need semantical or technical capabilities of CDS thatexceed those of Open SQL (but we try to keep the technical capabilities on the same level, e.g., CDS knows UNION,Open SQL will know UNION with SP12) or you just want to push down the full data model to the database, you useCDS. And in fact I've seen very, very extensive sophisticated views already now (oh boy ...). But I'm a simple mind, not a business modelling guru. In order to understand the basics, I work with simple examples.Just to give you two of those: @AbapCatalog.sqlViewName: 'DEMO_CDS_JOIN'

define view demo_cds_scarr_spfli

(id, carrier, flight, departure, destination)

as select from spfli

join scarr on scarr.carrid = spfli.carrid

key spfli.carrid,

key scarr.carrname,

key spfli.connid,

spfli.cityfrom,

spfli.cityto

This is a simple join as you could also define it in classical SE11. The name of the CDS entity isdemo_cds_scarr_spfli and the name of the generated CDS database view is DEMO_CDS_JOIN. One difference to aclassical view is the fact, that a CDS entity that uses client dependent data sources is client dependent by default butnever has a client field. The client handling is done implicitly without shining through here. Another view, that does exactly the same as the above one but shows a new kind of modelling capability:

@AbapCatalog.sqlViewName: 'DEMO_CDS_ASSOC'

define view demo_cds_association

(id, carrier, flight, departure, destination )

as select from spfli

association [1..1] to scarr as spfli_scarr

on $projection.carrid = spfli_scarr.carrid

key spfli.carrid,

key spfli_scarr.carrname,

ABAP News for 7.40, SP08 ABAP Core DataServices (CDS)Posted by Horst Keller in ABAP Development on Oct 10, 2014 11:05:43 AM

Share 5 2Like

Page 2: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 2/14

key spfli.connid,

spfli.cityfrom,

spfli.cityto

The join is replaced by an association, which is a more elegant way to code reusable joins. Associations can beadressed inside the view using path expressions (spfli_scarr.carrname is the most simple one) and can bepublished (not shown here) for usage in other views and in Open SQL (planned for SP12). In an ABAP program you can read the views with Open SQL: SELECT *

FROM demo_cds_association

ORDER BY id, carrier, flight

INTO TABLE @DATA(result1).

SELECT *

FROM demo_cds_scarr_spfli

ORDER BY id, carrier, flight

INTO TABLE @DATA(result2).

ASSERT result1 = result2.

To find out more, see the CDS documentation (it contains an authorization concept already, but the release of that waspostponed to SP12). After this recap, now the most important News for CDS with 7.40, SP08 Besides many smaller enhancements, the most important news are: Many new builtin functions Besides the function already introduced with SP05, you can use standard functions as COALESCE, CONCAT,REPLACE, ABS, DIV, DIVISION, FLOOR, MOD and ROUND now and as in Open SQL the searched CASE wasintroduced. Special functions CURRENCY_CONVERSION, UNIT_CONVERSION und DECIMAL_SHIFT allow you to deal withdata of the (in)famous SAP specific dictionary types CURR, CUKY, QUAN and UNIT. @AbapCatalog.sqlViewName: 'DEMO_CDS_CRRCNV'

define view demo_cds_currency_conversion

with parameters to_currency:abap.cuky(5),

exc_date:abap.dats

as select from demo_prices

id,

currency_conversion( amount => amount,

source_currency => currency,

round => 'X',

target_currency => :to_currency,

exchange_rate_date => :exc_date,

error_handling => 'SET_TO_NULL' ) as amount,

:to_currency as currency

Parameter views On databases that support it (not all up to now, but SAP HANA does) you can add importing parameters to a view thatcan be used in the SELECT statement of the view and that can be supplied when using the view in Open SQL. Example for such a view: @AbapCatalog.sqlViewName: 'DEMO_CDS_PARA'

define view demo_cds_parameters

with parameters p_distance_l:S_DISTANCE,

p_distance_o:S_DISTANCE,

p_unit:S_DISTID

as select from spfli

key carrid,

key connid,

cityfrom,

cityto,

distance,

distid

where distid = :p_unit and

distance between :p_distance_l

and :p_distance_o;

Usage in Open SQL:

Page 3: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 3/14

Average User Rating

(8 ratings)

0 Tweet 14

IF cl_abap_dbfeatures=>use_features(

EXPORTING

requested_features =

VALUE #( ( cl_abap_dbfeatures=>views_with_parameters ) ) ).

SELECT *

FROM demo_cds_parameters( p_distance_l = @from_distance,

p_distance_o = @to_distance,

p_unit = @unit )

ORDER BY carrid, connid

INTO TABLE @DATA(result).

cl_demo_output=>display( result ).

ELSE.

cl_demo_output=>display(

'Database system does not support views with parameters' ).

ENDIF.

Extending views Classical views delivered by SAP or partners can be extended with the well known clasical append views. In order toachieve the same for CDS views a new DDL statement is introduced: @AbapCatalog.sqlViewAppendName: 'DEMO_CDS_EXTENS'

extend view demo_cds_original_view with demo_cds_view_extension

spfli.distance,

spfli.distid as unit ;

It adds new fields to the existing view fields. Technically, a classical append view its name defined behind theannotation @AbapCatalog.sqlViewAppendName is generated in the ABAP Dictionary for that purpose.

8958 Views

Share 5 2Like

35 Comments

Like (0)

Paul Hardy Oct 25, 2014 7:15 AM

In regard to parameter transactions, up until now if we define a view in SE11 which joins, say, VBAKand VBAP and call the view ZV_SALES_ORDERS. We could then write the following: SELECT * FROM zv_sales_orders INTO lt_sales_orders WHERE werks EQ p_werks AND erdat IN s_erdat. I take it you cannot do this with a CDS view ? Is this because it is not a "real" SE11 view? You have to do the trick with the parameters instead? Cheersy Cheers Paul

Peter Inotai Oct 27, 2014 1:45 PM (in response to Paul Hardy)

Page 4: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 4/14

Like (0)

You can pass parameters without any problem for the select statement.This is an example in 7.40 SP4 (so very limited functionality):CDS definition in Eclipse:

Actually it can be displayed in SE11:

And you can write SELECT with WHERE condition:

Peter

Jacques Nomssi Oct 27, 2014 2:22 PM (in response to Peter Inotai)

it is recommended to only use the CDS entity ZPI_TEST in Open SQL statements(instead of the CDS database view ZPI_TEST_CDS).In your simple case, the only difference is that the CDS entity does not have aMANDT field; you can select with WHERE conditions directly on the CDS entityZPI_TEST. regards,

Page 5: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 5/14

Like (0)

Jacques Nomssi

Like (0)

Peter Inotai Oct 27, 2014 2:28 PM (in response to Jacques Nomssi)

Hi Jacques,Thanks for the info.Do you mean "SELECT * FROM zpi_test ...." statement?In our system (only SP4) it doesn't seem to work. Thanks,Peter

Like (1)

Jacques Nomssi Oct 27, 2014 2:40 PM (in response to Peter Inotai)

Hi Peter, I am on SP05 and the following works: [email protected]: 'Y_CDS_PO_DATA'define view y_po_viewas select from ekko as po inner join ekpo as item on po.ebeln = item.ebeln left outer join lfa1 as vendor on po.lifnr = vendor.lifnr key po.ebeln as ebeln, key item.ebelp as ebelp, po.bukrs as bukrs, po.bstyp as bstyp, vendor.name1 as vendor_name ComsumptionREPORT y_cds_consumption.DATA gs_sel TYPE ekko.SELECTOPTIONS so_bstyp FOR gs_selbstyp. DATA lt_result TYPE STANDARD TABLE OF y_po_view WITHNONUNIQUE key ebeln. SELECT * UP TO 100 ROWS FROM y_po_view INTO TABLE @lt_result WHERE bstyp in @so_bstyp. cl_demo_output=>display_data( lt_result ). DATA lt_data TYPE STANDARD TABLE OF y_cds_po_dataWITH NONUNIQUE key ebeln. SELECT * UP TO 100 ROWS FROM Y_CDS_PO_DATA INTO TABLE @lt_data WHERE bstyp in @so_bstyp. cl_demo_output=>display_data( lt_data ). best regards, JNN

Like (0)

Peter Inotai Oct 27, 2014 2:48 PM (in response to JacquesNomssi)

Hi JNN,Thanks a lot for the detailed answer.Probable testing in SP04 is not a good idea, I shouldsomehow get to SP05 or even better to SP08,Cheers,Peter

Horst Keller Nov 13, 2014 7:00 PM (in response toPeter Inotai)

CDS for ABAP was released with SP05.Before it was an undocumented prereleasefor SAPinternal use only. And yes, no accessto the CDS entities before SP05. As of SP05this access is possible and the generateddatabase views visible in SE11 are regarded

Page 6: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 6/14

Like (2)

as internal technical necessities but shouldn´tbe used in Open SQL. A mixing of CDS entities with classical SE11databases and views in one Open SQLstatement will be possible in an upcoming SPand the usage of the CDS DB views in OpenSQL will be declared as obsolete. Pls see the comprehensive explanation here: http://help.sap.com/abapdocu_740/en/index.htm?file=abenddic_cds_views.htm

Like (0)

Peter Inotai Nov 14, 2014 9:12 AM (inresponse to Horst Keller)

Hi Horst,Thanks for the info.Peter

Like (0)

Horst Keller Nov 13, 2014 6:37 PM (in response to Paul Hardy)

I´ve chosen a simple example. You can use the parameters at many operand positions in CDS view definitions, not onlybehind WHERE. E.g., you can pass parameters to functions of the view in order to controltheir behavior. In fact, I´ve shown that in the currency conversion example above ...

Like (0)

Paul Hardy Oct 25, 2014 7:47 AM

And whilst I am asking questions..... A CDS view is written in "DDL" (data defintion lanaguage) whilst a stored procedure is written in SQLScript? Have I got that correct? They look a bit the same, but I presume that SQLSCript has a much greater depth of functionalityavailable than something written in DDL? Cheersy Cheers Paul

Like (1)

Jacques Nomssi Oct 26, 2014 12:58 AM (in response to Paul Hardy)

Hello Paul, 1) you can restrict the selection from a CDS view with additional conditions in the WHEREconditions (I tested this on SP05). 2) you should be able to use both parameters and WHERE conditions in a HANA systemwith SP08 (I have not tested this). 3) CDS is database indepedent. My understanding is that you should be able to do: DDL (Data Definition) QL (Query) DML (Data Manipulation) DCL (Authorization)on any supported database in the same way, with the aim is to eventually cover the SQL92functionality. (cf. opensap course ABAP on HANA slides) 4) AMDB is stored in the language of the database. Currently only HANA DB is supported,i.e. the language is SQLScript or the SAP internal L language. So in my view it is native SQL, but with a much better ABAP integration: it is in your transport request you just call an ABAP method (with VALUE parameters) Special Disclaimer: I am not Horst Keller, so I might be wrong on all counts. regards, JNN

Page 7: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 7/14

Like (0)

Paul Hardy Oct 26, 2014 3:33 AM (in response to Jacques Nomssi)

First off, thanks very much for responding. I had hoped that you could use WHERE conditions when referring to a CDS view.My undertanding is that a CDS view has two faces the name that appears inSE11 which is the SQL view, and the "entity" name which is the one you aresupposed to use in your SELECT statements in your ABAP programs. It would seem logical that when referring to the SQL view you could use extraWHERE coditions, but in all the examples I have thus far seen, when referring tothe "entity" in an ABAP SELECT no parameters are even supplied. If you can in fact use WHERE conditions when referring to the "entity" (sounds likean alien monsters) or a mixture of WHERE conditions and parameters, then I amfinding it difficult to work out the reason for the parameters in the first place whynot just use more WHERE conditions? Could this be something to with referring toa CDS view within a stored procedure or something? I am just guessing. In a presentation by Rich Heilman from SAP he seemd to imply that the CDS viewwas the DDL subset of SQLSCRIPT (which might explain why you create anartifact called a "DDL" from the ABAP in Eclipse when creating a CDS view) but Imay have totally misunderstood. Again, in all the examples I have seen of CDSviews they look like one big SQL statement, albeit with tons of fancy features. AndHorst seems to imply that one day the new extended Open SQL capabilities inABAP will catch up with wat is possible in a CDS view, which would seem to makeit redundant in the long term. Again, I have probably got all this wrong. Now, moving on to ADMP, I thought the only language possible was SQLSCRIPTat this time but you mention also the internal SAP "L" language. On reading this I thought "what the L?" Is this just a language SAP use inhouse?

Like (4)

Horst Keller Nov 14, 2014 9:19 AM (in response to Paul Hardy)

Hi Paul, Most of your questions are answered by JNN and Peter. To summarize:

Best Horst

CDS views are entities of the ABAP CDS in the ABAP Dictionary that are much moreadvanced than the classical SE11 views. E.g., you can influence CDS views withparameters that can be used at different positions of the DCL. As for classical SE11views, for a CDS view a platform dependent runtime object is generated at thedatabase that you can examine in SE11. When accessing a (CDS) view with OpenSQL, the database interface accesses this runtime object. As always ST05 can beused to analyze such accesses further. A CDS view is created with a source codebased editor in Eclipse using a DDL (that has nothing to do with SQLScript). Fortechnical reasons, from the source code a classical DB view is generated in SE11 thatyou can access like any classical view, but you shouldn't. Instead the so called CDSentity should be accessed because it carries more meaning than the mere technicalDB view and involves new kind of client handling. In an upcoming release the directacces to the DB view of a CDS view will be declared as obsolet.

You use CDS to model large parts of your application in the Dictionary and use simpleOpen SQL SELECTs in ABAP for read access instead of having to create therespective joins and subqueries in each ABAP program over and over again. One dayOpen SQL might have the same power like CDS but it doesn't mean that those areredundant. Already before CDS you had the choice between creating a reusable viewin SE11 or programming a join in Open SQL. As a rule of thumb you created a view if itis used in more than one program and programmed a join when you needed it onlyonce. That is very similar for CDS, but with much more possibilities for modelingsemantically rich models for reuse in ABAP programs.

CDS is mainly open. It is not restricted to HANA (but performance can be different!).AMDP is simply a frame work that facilitates the handling of Native DB procedures. Upto now only DB procedures of HANA written in SQLScript are supported (the low levellanguage L is for SAPinternal use only; parts of SQLScript are implemented in L).Other platforms might follow.

Have a look at my From ADBC to AMDP example, that shows the evolution. Fromgenerating a DB procedure yourself wih ADBC over calling it with CALL DATABASEPROCEDURE we finally can generate and call it purely in ABAP. Of course, thefunctionality of that example is nonsense, because you can do the same with the sameor even better performance in Open SQL. Another example is more realistic inshowing how a SQLScript currency conversion function is used on the databaseinstead of calling an ABAP function module. It is clear, that working directly on thedatabase should perform better here.

Page 8: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 8/14

Like (1)

Jacques Nomssi Nov 14, 2014 3:51 PM (in response to Horst Keller)

thanks to Horst Keller, documentalist extraordinaire!

and some questions 1) Will CDS view with parameter be supported on all certified DB soon?I mean, checking the underlying database for available features is idiosyncratic forcustom developments. 2) Should I expect a change in performance while fetching data from a base CDSentity when Ia) consume the base CDS entity in an ABAP SELECT statement with WHEREclause, compared to when Ib) extend the CDS entity with a WHERE restriction and then consume theextended CDS entity without WHERE clause. best regards, JNN

Like (0)

Horst Keller Nov 17, 2014 4:18 PM (in response to Jacques Nomssi)

1) The database colleagues are working on it and it seems that with thenext major release 7.40, SP12 all database systems will supportparameter views. 2) I do not expect different performance. I expect the database systems docarry out the same SELECT in both cases.

Like (0)

Paul Hardy Oct 28, 2014 1:21 PM

OK, from the replies that Jacques and Peter have been kind enough to share it looks like in thehigher levels of 740 we can address the "entity" (view name) with not only variables in the WHEREparameter, but in SP08 view parameters as well. The question I still have is why do we need both? SAP would not have introduced parameters to CDSviews as a joke (I hope) so there must be some sort of use case for them which cannot be acheivedby the normal WHERE parameters in ABAP. My guess remains that this is something to fo with using a CDS view in a stored procedure. Also I am still wondering about this "L" language.....

Like (0)

Peter Inotai Oct 28, 2014 1:31 PM (in response to Paul Hardy)

Even before CDS you had the possibility to add conditions to the view in SE11 (SelectionConditions tab) or do it via ABAP WHERE condition in the SELECT statement, so it doesn'treally bother me.CDS views are also used for naive HANA development, this could be also a reason whyparameters are added.Guidelines would be good, which case to use them as in CDS or which case outside theCDS.

Like (0)

Peter Inotai Oct 30, 2014 8:41 PM (in response to Paul Hardy)

>Also I am still wondering about this "L" language.....It's mentioned in the "ABAP Development for SAP HANA" book.Once it's mentioned that it's for SAP internal use only (just like Language R).Somewhere it's mentioned that it's an intermediate representation for translating SQLScriptinto C++ language.

Jacques Nomssi Oct 30, 2014 9:10 PM (in response to Peter Inotai)

Hi Peter, information about L and even a code sample can be found in the AMDB section ofthe online help (Thanks Horst Keller). OTOH the R environment is a powerfull suite for data manipulation and display. Itis a free GNU project not related to SAP. I understand you can install an R serveron a linux machine and connect it to a HANA system. My understanding is that the DDL part of CDS (Views) will completely replace thedefinition of views in SE11. You can extend views (Append), create associations(joins on demand) and use expressions, so I can imagine a use case where theparameter is not part of the projection list, so you cannot pass it as a WHEREcondition. best regards,

Page 9: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 9/14

Like (1)

JNN

Like (0)

Peter Inotai Oct 30, 2014 9:16 PM (in response to Jacques Nomssi)

Hi JNN,Thanks for the info!Cheers,Peter

Like (0)

Paul Hardy Oct 30, 2014 10:32 PM (in response to Jacques Nomssi)

So, when you define a CDS view you start off with a list of the fields forexport, which matches the list of fields you would define on the left handside of an SE11 view. Thereafter these fields are available for use in WHERE condtiions after aSELECT statmement against the "view entity". If you declared a parameter that was NOT in that list, then that parametercould be used somehow inside the "code" of the CDS view in a way that avalue passed in via a WHERE clause could not? If so, could you be kind enought to give some sort of example, even if thisis not actually possible at the moment in the current level of HANA?

Like (1)

Jacques Nomssi Oct 31, 2014 1:07 AM (in response to Paul Hardy)

from the ABAP on HANA online course (Week 03, FilteredAssociation): 1) normalized view of the EPM text table @AbapCatalog.sqlViewName: 'ZDDLS_CDS_33A'define view zcdsv_adv_filter_example_baseas select from snwd_textsparent_key as product_text_guid,language,text 2) Association between the product table and the textinformation encoded in first view @AbapCatalog.sqlViewName: 'ZDDLS_CDS_33B'define view zcdsv_adv_filter_example_l1as select from snwd_pd as pdassociation [1..*] to zcdsv_adv_filter_example_base as textson texts.product_text_guid = $projection.text_guidkey pd.product_id,pd.desc_guid as text_guid,texts 3) consume the association texts exposed in second view,filtering the language to the given input parameter value or adefault value @AbapCatalog.sqlViewName: 'ZDDLS_CDS_33C'define view zcdsv_adv_filter_example_l2with parameters lang : abap.langas select from zcdsv_adv_filter_example_l1 as product$parameters.lang as langu_filter_param,coalesce (product.texts[1: language = $parameters.lang ].text,product.texts[1: language = 'E' ].text) as product_description The following is untested, but I assume the consumption of the3rd view could look like SELECT * FROM zcdsv_adv_filter_example_l2( lang = p_langu) WHERE product_id IN so_prod INTO TABLE @DATA(lt_result) where P_LANGU and SO_PROD could be selection screenparameter / selectoptions.

Page 10: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 10/14

Like (1)

Paul Hardy Oct 31, 2014 11:35 PM (in response to JacquesNomssi)

As I suspected, the parameter gets passed into somesort of fucntion, which naturally cannot be the case witha value in a WHERE clause. You say this is a standard SAP example it has to besaid they are struggling to find a practical use for this,examples should really be along the lines of 1. Here is how we do it now2. Here is a new way to do it3. The new way is better because of XYZ The SAP language example does not cut the mustardas you can pass in SYLANGU in a WHERE clause. If the example is trying to do something more than justpass back the product description twice then maybe Iam barking up the wrong tree.

Like (1)

Jacques Nomssi Nov 1, 2014 11:15 PM (inresponse to Paul Hardy)

For each selected product the exampleshould return a single product description inthe desired language if maintained, otherwisethe product description in the defaultlanguage english. Since SP08 you can use SQL expressions inthe CDS view to implement logic that cannotbe achieved with a mere WHERE clause.COALESCE( A, B ) returns A if not NULL,otherwise B.I guess we could use COALESCE( ) again onthe result to return a Constant text if thedescription is not maintained in anylanguage. This is IMO a very practical example. I canremember having to implement this logic forMARA MAKT queries more than once. Withthis the ABAP logic is much simpler and CodePush Down is achieved. JNN

Like (0)

Mr Me Nov 17, 2014 12:57 PM

If I understand correctly I am a bit unsure, so please confirm transporting of the CDSobject and theABAP coding accessing it remain separate? What about the other way around, i.e. the possibility to utilize a classical ABAP dictionary object inHANA SQL? In my particular case I am working with an .hdbprocedure and would like to declare a table of a typealready existing in the ABAPdictionary. Is that possible? Great post BTW

Like (1)

Horst Keller Nov 18, 2014 9:43 AM (in response to Mr Me)

Hi, A CDS view as an ABAP program or any reposiory object is a normal transport objectgoverned by the classical transport tools. Of course they are different objects but they can betransported together. Nothing has changed here compared to classical dictionary objects. In fact, that´s one reason, why ABAP CDS is embedded in the ABAP Dictionary. Also the same as before. In Native SQL you cannot access the ABAP Dictionary as a metadata repository, but you should be able to access the runtime object generated from thedictionary definition on the database. Horst

Mr Me Nov 17, 2014 9:20 PM (in response to Horst Keller)

Horst,

Page 11: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 11/14

Like (0)

thank you for your answer and clarification.Unfortauntely it is not clear to me what you mean with "you should be able toaccess the runtime object generated from the dictionary definition on thedatabase". Does it mean that local variables can be declared in the procedure based on e.g.the types of the procedure parameters? Would it thereby be possible to declarelocal table variable based of type BOOKINGS and CONFIRMATIONS in theexample below? PROCEDURE DEMO (IN p1 BOOKINGS, OUT p2 CONFIRMATIONS) LANGUAGE SQLSCRIPT SQL SECURITY INVOKER READS SQL DATA ASBEGIN END; Thanx

Like (2)

Horst Keller Nov 18, 2014 10:01 AM (in response to Mr Me)

Hello, Database tables and database views defined in the ABAP Dictionary arecreated on the database in the database schema SAPsid. For this, nativeDDL statements are passed from AS ABAP to the database by theDatabase Interface (DBI). You can examine these objects using the database's tools and interfacesand you can use the programming language(s) of the database to accessthem. In case of SQLScript, please refer to the respective documentation (http://help.sap.com/hana/SAP_HANA_SQL_Script_Reference_en.pdf),how you can access the native views generated from an CDS source. But maybe it is a better idea to use AMDP in that case. When creating anAMDP method, in ABAP, you have direct access to the Dictionary typesused in an CDS view and you can let the AMDP framework generate theactual database procedure for you. Best Horst

Like (0)

Mr Me Nov 18, 2014 6:59 PM (in response to Horst Keller)

Thanks for your answer Horst.

please refer to the respective documentation (http://help.sap.com/hana/SAP_HANA_SQL_Script_Reference_en.pdfhow you can access the native views generatedfrom an CDS source.

I searched the guide for 'CDS' and 'native' but found nothing. Areyou refering to ADBC? Also: I am not using AMDP because I have understood that froman AMDP generated procedures only other AMDP generatedprocedures can be called (i.e. not stored procedures). This isone of the reasons why I am not going down the AMDProute.

Horst Keller Nov 19, 2014 8:32 AM (in response to Mr Me)

I searched the guide for 'CDS' and 'native'but found nothing.

Of course. SQLScript is DB level. DB level is nativefrom the ABAP point of view. DB level doesn't knowanything about 'native' and CDS, since it is native itselfso to say. You have to look up the artifact generated bythe AS ABAP in HANA studio and find out, how tohandle it with DB means if you really want to do so. Butthis is not a question to ABAP.

Page 12: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 12/14

Like (0)

I have understood that from an AMDPgenerated procedures only other AMDPgenerated procedures can be called (i.e.not stored procedures).

Who told you so? An AMDP procedure can call otherDB procedures.

So the questions remains, why you want to accessABAP features from DB level at all and why you do notwant to use a supporting framework (AMDP) for doingso.

When calling another AMDP procedure, the lattermust be listed behind USING.When calling a native DB procedure of the sameDB schema, it must be in the name space/1BCAMDP/ (see example). But his should berestricted to temporary procedures.There are no syntactical restrictions in callingnative DB procedures of other DB schemas. Butof course, you have to take care yourself, that theprocedures are available in any system and that'swhy it should be done in exceptional cases only.

Like (0)

Mr Me Nov 19, 2014 11:42 AM (in response toHorst Keller)

Thanks for your many answers to myquestions. The scenario I am struggling with is: I haveseveral BWDSO tables (ABAP generatedartifacts, right?) whose content I need tomanipulate by AFL/PAL functions (thru callsto catalog procedures). There are various of these proceduresrequiring different combinations of input andoutput parameters (always at least an IN andan OUT table). The reason behind my questions is that I amsearching for a solution where I can avoiddefining the structure of the DSOtablesmanually on a DB level. Why? Double workAND if the DSOs changes their structure inBW (ABAP AS) somebody must remeber tomake the change also on a DB level. Initially I tried AMDP, but found it a bit limitedfor the reasons you mentioned above ANDthe fact that the syntax seems to be restrictedvisavis normal procedures (e.g. no localtemporary tables permitted and otherrestrictions). This was the reason that I havebeen looking for an alternative by usingstored procedures (thru BW's HANA AnalysisProcess) from which the idea was to call theAFL/PAL procedures. I will take a look at the simplest option: userexit logic in BW transformation with loop overan ITAB inside which I first prepare the dataand then execute calls to the AFL/PALfunctions (which are located in anotherschema) by means of AMDP. As you state thisshould be done only in exceptional cases (Inormally try to avoid those), but in my case itseems as if it could be the 'right thing' to do. Thanks again for your assistance.

Uwe Fetzer Jan 9, 2015 9:12 PM

I'm currently playing with the association example of the ABAP Keyword Documentation and getting awarning "Association & can influence the cardinality of the resulting set". This also happens in all ofmy own examples.

Page 13: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 13/14

Like (1)

Do you know what this warning means and how to prevent it?(I'm on 7.40 SP9)

Like (2)

Horst Keller Jan 12, 2015 8:28 AM (in response to Uwe Fetzer)

The purpose of such warnings in CDS source code is to point out properties of a view thatmight be unexpected for the programmer. Warnings can come either from the syntax butalso from the ABAP Dictionary, where the respective database view is generated. Anexample for the latter would be "all fields are key fields". Unfortunately up to now, there is noway to hide such warnings (no CDS pragmas yet) but the problem is known and work is inprogress.

Like (0)

Anita Dixit Mar 30, 2015 8:22 AM

Hi,I have created a simple ABAP CDS view, using one input parameter for date. But I need to use it in 2different places in the 'where' condition. But I am getting this error. Can anyone help here please?

Dominik Rosch Apr 2, 2015 12:41 PM

Hi everyone, I'm having cosmetic problems with my CDSViews. I created them with EN as my default language;though I work for a german company in which everyone signs in using DE as default language. I provide the short description for my views using the following annotation:@EndUserText.label: '<Short Description>' When I try to look up my views in SE11 using F4Help in DElanguage, there are no shortdescriptions (due to them being written in English?), whereas when displaying the view in SE11, theshort description is available. Do you have any idea on how to provide said F4Help short descriptions in DE? Best,Dominik

Page 14: ABAP News for 7.40, SP08 - ABAP Core Data Servi

4/27/2015 ABAP News for 7.40, SP08 ABAP Core Data Servi... | SCN

http://scn.sap.com/community/abap/blog/2014/10/10/abapnewsfor740sp08abapcoredataservicescds 14/14

Follow SCNSite Index Contact Us SAP Help PortalPrivacy Terms of Use Legal Disclosure Copyright

Like (0)