Monday 10 October 2022

Create a CDS view with joins using eclipse

What is CDS View?


CDS stands for Core Data Service which are virtual data models of SAP HANA which allow direct access to underlying tables of the HANA database. SAP CDS Views came into being with SAP’s new programming model. SAP CDS Views aim to push logic from the application server to the client side and database.

Let’s Begin to open your Eclipse and Follow the Steps that I write Blow for CDS View creation.

Step 1: Login to your development server and add your development Package

Right-click on the favorite package and select add a package

SAP CDS, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP CDS, SAP ABAP Certification, SAP ABAP CDS Exam

A popup window opens and search your development package

SAP CDS, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP CDS, SAP ABAP Certification, SAP ABAP CDS Exam

Step 2: Create Your CDS View Data Definition

After your package is added right click on your package and click on new then click on the “Other ABAP Repository object”.

SAP CDS, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP CDS, SAP ABAP Certification, SAP ABAP CDS Exam

After clicking on “Other ABAP Repository object” a popup window open then search “Data Definition”.

SAP CDS, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP CDS, SAP ABAP Certification, SAP ABAP CDS Exam

Select the “Data Definition” object to define your View Name starting with “Z”

SAP CDS, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP CDS, SAP ABAP Certification, SAP ABAP CDS Exam

After defining your view name create a request to transport it from DEV to QAS and QAS to PRD.

SAP CDS, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP CDS, SAP ABAP Certification, SAP ABAP CDS Exam

Step 3: Select Your CDS View Template

After request creation select prebuild CDS View templates that you want to create a CDS View I select “define view with Join”.

SAP CDS, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP CDS, SAP ABAP Certification, SAP ABAP CDS Exam

After selecting your template name your @abapCatalog.sqlViewName:’ ‘ the name must be starting with “Z” e.g. ZABC

SAP CDS, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP CDS, SAP ABAP Certification, SAP ABAP CDS Exam

Step 4: Write Your CDS View Code to join tables and fetch data from the Database

SAP CDS, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP CDS, SAP ABAP Certification, SAP ABAP CDS Exam

Code:

@AbapCatalog.sqlViewName: 'ZCDS_SOD'
@AbapCatalog.compiler.CompareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Sale Order Detail'
define view ZCDS_SO_DATA as select from vbak
left outer join vbap
    on vbak.vbeln = vbap.vbeln {
    
key vbak.vbeln,
    vbap.matnr,
    vbap.arktx,
    sum(vbap.kwmeng) as Order_Qty,
    vbap.netpr,
    vbap.netwr
    
}
group by
    vbak.vbeln,
    vbap.matnr,
    vbap.arktx,
    vbap.netpr,
    vbap.netwr

After writing your code save and activate your code by using (CTRL+F3 ) keys and preview data using the F8 key.

SAP CDS, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP CDS, SAP ABAP Certification, SAP ABAP CDS Exam

No comments:

Post a Comment