Standard DEMO Examples of ABAP CDS views
Hi!
This post was created to show standard ABAP development package with could be very useful for:
- ABAP programmers starting to use CDS views functionality
- Application consultants (e.i. in case of customer CDS views enhancements should be done or some standard CDS view results don’t seem to be correct)
You could find a package SABAPDEMOS in HANA Studio ABAP perspective in case of S/4HANA system (or in SE80 t-code). There are a lot of useful things there.
In Core Data Services group you could find examples of:
- Usage of different annotations in CDS views
- CDS view based on Table function
- CDS view with parameters
- CDS views with different types of joins, union and associations
- CDS view with currency conversion and unit conversion
- Usage of SQL functions like numeric, string, date/time functions in CDS views
- Authorization check in CDS view and definition of Access Control using DCL
- Extension examples of CDS views
This list depends on NW version of your system, because some features like extension of CDS view with aggregate functions or union was not available before NW 7.51. This is a good post were you could find more detailed information about CDS ABAP Features.
List of available CDS examples of NW 7.51 SP00 is shown below:
Unfortunatly, I didn’t find there any examples of demonstration of hierarchy usage in CDS views. If you are interested in this case you see may post “How to build a Custom Hierarchy in ABAP CDS views”.
Also I couldn’t found examples of CDS views for analytical reporting purposes.
However this is great resource for learning by examples!
Thank you for attention!
Hello Maksim,
First of all, thank you for those all great posts. Very helpful..
I am trying to build an analytical model and a query than, using ekpo, rseg, rbkp and lfm1 tables.
When i try to use the fields of the 2nd association to make a newer 3rd association, things go worse.I get the error “Association _xxxx cannot be used locally within the view.” If I don’t use this association locally, I can’t make the relation through the lfm1 table.
Here is the error message;
Here is my cds.
I am not sure if associations have some other use cases but not for this. When I do the same logic with traditional join, it works as expected. Do i need to use join? If so, do you have a best practice advice when to use join and when to use association?
Thank you and regards,
Ceyhun
Hello!
In common associations are useful if you need to get some fields in upper ABAP CDS view, e.i. in case of star schema model fact with dimensions. In some cases fields from association table aren't needed and join willn't performed.
In your case I think normal joins could be used, because a join must be executed to get data from lfm1 table.
You could also try to see standard ABAP CDS view for Purchase Orders I_PurchaseOrder, I_PurcahseOrderItem to use them as templates.
Hi Maksim Alyapyshev,
I've a doubt in Basic view..
I created the Basic view like this. If I keep data category as dimension, view is executing. if i keep data category is cube, then also it is executing successfully. then what is the difference between dimension and cube in basic view
Hi!
Annotation @Analytics.dataCategory: ‘<Value>’
Consider what category of data you are going to select in view.
More details in documentation.
Hi Maksim,
Very useful post. I have a question about usage parameters in associations.
We would like to use parameters in composite view which has associations to some basic views. How can we pass parameters to associations (we want to get all fields from our associations)?
Unfortunately I didn't find any example in demo's.
Thanks in advance for your help.
Kind regards,
Kateryna
Hi,
You do that in brackets, e.g.
as select from Z_I_FIGL_PlanAndActual (P_CurrentYear:$parameters.P_CurrentYear, P_PreviousYear:$parameters.P_PreviousYear, P_PreviousFiscalPeriod:$parameters.P_PreviousFiscalPeriod)
IF LV_DMBTR = 0 AND LV_MENGE = 0.
SELECT
SUM( DMBTR )
SUM( MENGE )
INTO (LV_DMBTR, LV_MENGE)
FROM MSEG
WHERE WERKS = ‘2000’
AND MATNR = GW_SHOW–MATNR
AND BWART = ‘101’
AND CHARG = GW_SHOW–CHARG
AND DMBTR <> 0 .
ENDIF.
IF LV_DMBTR = 0 AND LV_MENGE = 0.
SELECT
SUM( DMBTR )
SUM( MENGE )
INTO (LV_DMBTR, LV_MENGE)
FROM MSEG
WHERE WERKS = ‘2000’
AND MATNR = GW_SHOW–MATNR
AND BWART = ‘561’
AND CHARG = GW_SHOW–CHARG
AND DMBTR <> 0.
ENDIF.
* RSEG, RBKP
IF LV_DMBTR = 0 AND LV_MENGE = 0.
SELECT
SUM( WRBTR )
SUM( MENGE )
INTO (LV_DMBTR, LV_MENGE)
FROM RSEG
WHERE WERKS = ‘2000’
AND MATNR = GW_SHOW–MATNR
AND WRBTR <> 0.
ENDIF.
IF LV_DMBTR = 0 AND LV_MENGE = 0.
SELECT
SUM( DMBTR )
SUM( MENGE )
INTO (LV_DMBTR, LV_MENGE)
FROM EKBE
WHERE WERKS = ‘2000’
AND MATNR = GW_SHOW–MATNR
AND BWTAR = GW_SHOW–CHARG
AND BWART = ‘101’
AND DMBTR <> 0.
ENDIF.
how to cds
if????
Use parameters instead of local variable, create needed select statements and (if needed) use case logic in select statement.
Hi Maksim,
This is quite a good stuff. I am actually a beginner to CDS view, I see different types of view and lot things going on with ABAP on HANA.
I was wondering what is the road map(concepts in order) that we need to actually focus on to become good at CDS views( basics to complex) .
Thanks in advance.
Hi, please have a look at s4h400, s4h410 sap courses. They are good and step by step.
Hi Maksim
Thanks for this post. Very useful.
Where can we find list of ABAP CDS Views which can be used for BW Extraction. E.g. In BW, there is standard Data Source 2LIS_11_VAITM, so what will be the corresponding ABAP CDS View for this Data source.
Regards
Pankaj
Hi,
SABAPDEMOS is the example package of the ABAP Keyword Documentation. These examples are all part of the ABAP F1 Help. Click F1 in your IDE and you find information on the keyword plus an example. You also find example descriptions and executable examples, for example, a CDS view that is accessed with ABAP SQL.
BR
Andrea