Wednesday, June 8, 2022

1.Introduction

 CDS View

Mostly in S4 HANA the clients requirement will be in CDS views or in AMDP for reporting purpose.
  1. In HANA, every operation executed in database level. whereas in ECC systems we fetch the data from database to application layer before performing any operation.
  2. PUSH DOWN Technique: CDS view works by pushing code down to database for executing required operation. This is called code push down technique.

2.CDS views are consumed through.

  1. AFO Operation
  2. Extractors
  3. Fiori Tiles

AFO Operation

  1. AFO is a plugin to MS-OFFICE, with the help of CDS View we can fetch data from SAP system to MS OFFICE.
  2. MS Excel use CDS view it for various analytic purpose like pie chart preparation, graph preparation, sorting etc.
Note;
CDS view helps to view the data in third party system(ms-office).

Extractor:

CDS view helps to fetch data from SAP system to BODS Systems and BW systems for further processing.

Fiori Tiles:

CDS view with the help of ODATA Annotations it delivers the data from SAP system to FIORI tiles, Which will be further used by UI5/Fiori consultant for front end development.

2.Important terms in CDS.

  1. DDL - Data Definition Language (every thing in CDS view coding is ddl)
  2. DCL - Data Control Language(Defining authorization for CDS view are called DCL)
  3. CDS view has expression, association, annotation but normal views doesn't has these facilities. 
    • Expression: All the statement written in the CDS views are called expression.
    • Association: On demand joins can be achieved using association.
    • Annotation: Annotated codes are executed only at the run time. It will not be executed in hana studio or SAP gui, it will executed only at the time of accessing CDS view by fiori tiles or AFO operation or extractors.

3.Sample CDS view.

  1. SQL View name: Whenever we create CDS view, there will be SQL view created in background.
  2. Buffer specific annotation:  To decide whether to have single or multiple buffer.
  3. CDS view entity: CDS view name.
  4. Name list: Fields to be display in output. 
Note: 
  1. CDS view and SQL view name should not be same.
  2. All the operation in the above pic will be executed directly in the database.
  3. CDS view itself just a query, So we cannot debug.
  4. For simple calculation like just to display, normal reports itself enough. For a complex calculation like sorting, summary preparation, aggregation and group-by operation, etc CDS view shows good performance improvement than normal reports.
  5. Output of one CDS view can be consumed by another CDS view. we can use two or more cds views to achieve final task.
  6. We can see CDS view in SE11 using SQL view name but we cannot edit in SE11.
  7. Every CDS view will be in 1 to 1 relationship with SQL view.

4.HANA studio/ Eclipse configuration.

  1. Install HANA studio or Eclipse in your system
  2. Goto Help -> Install new software
  3. Copy the like from "SAP development tools" website and paste it in HANA studio.
  4. Select All -> Follow wizard -> click finish.
  5. Change perspective to ABAP.
  6. Add SAP system.
    • New -> ABAP Project -> select SAP system from the list.

5.To create CDS View.

  1. Press CTRL+N -> Select ABAP -> Select CDS -> Data Defnition.
  2. Enter Project, Package, Name, Desc
  3. Follow wizard.
  4. Enter Finish.

6.Simple CDS view.


Step 1
             //Default annotation                
                @AbapCatalog.sqlViewName: 'ZSALESORDERV' - SQL View name
                @AbapCatalog.compiler.compareFilter: true
                @AbapCatalog.preserveKey: true - To set key based on data source
                @AccessControl.authorizationCheck: #CHECK - Authorization option 
                @EndUserText.label: 'base view for sales order' - Description
Step 2
                //Select Condition
                define view zsalesorder_base
                  as select from  vbak
                {
Step 3
                //Display fields
                  vbeln                as SalesOrder,
                  erdat                 as OrderDate,
                  netwr                as ActualPrice,
                  waerk               as Currency, 
             }

6.Sample CDS view for sales order.

  • Using Joins
  • Using Aggregate function( SUM and Group By )
Step 1
                @AbapCatalog.sqlViewName: 'ZSALESORDERV' 
                @AbapCatalog.compiler.compareFilter: true
                @AbapCatalog.preserveKey: true 
                @AccessControl.authorizationCheck: #CHECK 
                @EndUserText.label: 'base view for sales order' 
Step 2
                //Join Condition
                define view zsalesorder_base
                  as select from    vbak as SalesHeader
                  left outer join vbap as SalesItem on SalesHeader.vbeln = SalesItem.vbeln 
                {
Step 3
                  SalesItem.vbeln                                    as SalesOrder,
                  SalesItem.posnr                                    as Item,
                  SalesItem.erdat                                    as OrderDate,
               SalesItem.matnr                                    as Material,
Step 4
            //Sum operation using keyword "sum"
                 sum(SalesItem.netwr) as ActualPrice,
                SalesItem.waerk                                    as Currency, 
            }
            //Need to add all the fields in Group By statement
            group by 
                SalesItem.vbeln, 
                SalesItem.posnr, 
                SalesItem.erdat, 
                SalesItem.matnr, 
                SalesItem.waerk

7.CDS view for sales order

  • Using fiori annotation for SUM operation.
  • Using fiori annotation for establishing FK btw currency field and actual price field.
  • Concatenate operation using concat keyword.
Code:

  1. @AbapCatalog.sqlViewName: 'ZSALESORDERV'
  2. @AbapCatalog.compiler.compareFilter: true
  3. @AbapCatalog.preserveKey: true
  4. @AccessControl.authorizationCheck: #CHECK
  5. @EndUserText.label: 'base view for sales order'
  6. //Join operaration
  7. define view zsalesorder_base
  8.   as select from    vbak as SalesHeader
  9.     left outer join vbap as SalesItem on SalesHeader.vbeln = SalesItem.vbeln
  10. {
  11.   //Fields to be displayed in OP
  12.   SalesItem.vbeln                  as SalesOrder,
  13.   SalesItem.posnr                  as Item,
  14.   SalesItem.erdat                   as OrderDate,
  15.   SalesItem.matnr                  as Material,
  16.   //Sum operation using annotation
  17.   @DefaultAggregation: #SUM
  18.   //creating FK rel btw actualprice and currency field
  19.   @Semantics.amount.currencyCode: 'Currency'
  20.   SalesItem.netwr                  as ActualPrice,
  21.   //currency field is key field for actual price
  22.   @Semantics.amount.currencyCode:true
  23.   SalesItem.waerk                 as Currency,
  24.   //concatenate price and currecny unit field
  25.   concat(cast(SalesItem.netwr as abap.char( 20 )), SalesItem.waerk ) as Price
  26. }


















No comments:

Post a Comment

5.F4 help and Select option in CDS view.

F4 help and Select option in CDS view  F4 Help implementation Using Association Using Basic and Consumption view Code: Basic view: @AbapCata...