Skip to Content
Author's profile photo Maksim Alyapyshev

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!

Assigned Tags

      12 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Ceyhun Alp
      Ceyhun Alp

      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.

      @AbapCatalog.sqlViewName: 'ZahmmDDL006I2'
      @Analytics.dataCategory: #FACT
      @VDM.viewType: #BASIC
      @EndUserText.label: 'Demo'
      
      define view Zahmm_DDL006_I2 as select from ekpo
      association to rseg as _rseg
       on ekpo.ebeln = _rseg.ebeln and
          ekpo.ebelp = _rseg.ebelp
          
      association to rbkp as _rbkp
      on $projection.belnr = _rbkp.belnr and
         $projection.gjahr = _rbkp.gjahr
         
      association to lfm1 as _lfm1
      on $projection.lifnr = _lfm1.lifnr   
        
      {
      --key
      key ekpo.ebeln,
      key ekpo.ebelp,
      key _rseg.belnr,
      key _rseg.gjahr,
      key _rseg.buzei,
      --ekpo   
          ekpo.menge as menge_ekpo,
          ekpo.netwr as netwr,
          ekpo.meins,
      --rseg 
          _rseg.matnr,
          _rseg.wrbtr,
           _rseg.menge,
      //--rbkp
          _rbkp.lifnr,
      --Association  
          _lfm1,
          _rbkp,
          _rseg
      }

      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

       

      Author's profile photo Maksim Alyapyshev
      Maksim Alyapyshev
      Blog Post Author

      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.

       

      Author's profile photo Maddirevula N Sathish Kumar Reddy
      Maddirevula N Sathish Kumar Reddy

      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

      Author's profile photo Maksim Alyapyshev
      Maksim Alyapyshev
      Blog Post Author

      Hi!

      Annotation @Analytics.dataCategory: ‘<Value>’

      • By specifying the data category, the developer can give directives and hints to the analytics manager on how to interpret individual entities.
      • Possible values: #DIMENSION, #FACT, #CUBE or #AGGREGATIONLEVEL.

      Consider what category of data you are going to select in view.

      • If there are master data: attributes, text, hierarchies – use #DIMENTION category.
      • If there are transactional data – use #FACT or #CUBE type. In #CUBE you could add associations to #DIMENTIONS, describing you transactional data. For transactional data category you always have some key figures and should describe how to aggregate this data (sum, max, min, avg etc.). In comparison for #DIMENTION category it isn’t needed and possible.

      More details in documentation.

      Author's profile photo Katja Plokhikh
      Katja Plokhikh

      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

       

      Author's profile photo Dmitry Kuznetsov
      Dmitry Kuznetsov

      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)

      Author's profile photo Jianhua Zhou
      Jianhua Zhou

      IF LV_DMBTR AND LV_MENGE 0.
      SELECT
      SUMDMBTR )
      SUMMENGE )
      INTO (LV_DMBTRLV_MENGE)
      FROM MSEG
      WHERE WERKS ‘2000’
      AND MATNR GW_SHOWMATNR
      AND BWART ‘101’
      AND CHARG GW_SHOWCHARG
      AND DMBTR <> 0  .
      ENDIF.

      IF LV_DMBTR AND LV_MENGE 0.
      SELECT
      SUMDMBTR )
      SUMMENGE )
      INTO (LV_DMBTRLV_MENGE)
      FROM MSEG
      WHERE WERKS ‘2000’
      AND MATNR GW_SHOWMATNR
      AND BWART ‘561’
      AND CHARG GW_SHOWCHARG
      AND DMBTR <> 0.
      ENDIF.

      *        RSEG, RBKP
      IF LV_DMBTR AND LV_MENGE 0.
      SELECT
      SUMWRBTR )
      SUMMENGE )
      INTO (LV_DMBTRLV_MENGE)
      FROM RSEG
      WHERE WERKS ‘2000’
      AND MATNR GW_SHOWMATNR
      AND WRBTR <> 0.
      ENDIF.

      IF LV_DMBTR AND LV_MENGE 0.
      SELECT
      SUMDMBTR )
      SUMMENGE )
      INTO (LV_DMBTRLV_MENGE)
      FROM EKBE
      WHERE WERKS ‘2000’
      AND MATNR GW_SHOWMATNR
      AND BWTAR GW_SHOWCHARG
      AND BWART ‘101’
      AND DMBTR <> 0.
      ENDIF.

       

      how to cds

       

      if????

      Author's profile photo Maksim Alyapyshev
      Maksim Alyapyshev
      Blog Post Author

      Use parameters instead of local variable, create needed select statements and (if needed) use case logic in select statement.

      Author's profile photo Nagendra Babu Uppala
      Nagendra Babu Uppala

      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.

       

      Author's profile photo Maksim Alyapyshev
      Maksim Alyapyshev
      Blog Post Author

      Hi, please have a look at s4h400, s4h410 sap courses. They are good and step by step.

      Author's profile photo Pankaj Raj
      Pankaj Raj

      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

      Author's profile photo Andrea Schlotthauer
      Andrea Schlotthauer

      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