0% found this document useful (0 votes)
512 views

CDS Views Concepts New

CDS (Core Data Services) views can be used to create database tables and views without using transaction SE11. To create a CDS view, right click on the user name in the ABAP Workbench and select "New" > "Other ABAP Repository Object". Select "Core Data" and "Data Definition" to generate the basic structure of the CDS view. Annotations are used in CDS views to define properties like the database table, view name, and keys. CDS views can then be used to build OData services and Fiori apps by adding additional annotations.

Uploaded by

asifmuzaffar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
512 views

CDS Views Concepts New

CDS (Core Data Services) views can be used to create database tables and views without using transaction SE11. To create a CDS view, right click on the user name in the ABAP Workbench and select "New" > "Other ABAP Repository Object". Select "Core Data" and "Data Definition" to generate the basic structure of the CDS view. Annotations are used in CDS views to define properties like the database table, view name, and keys. CDS views can then be used to build OData services and Fiori apps by adding additional annotations.

Uploaded by

asifmuzaffar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 54

On Cloud , we use CDS to create DB table because no GUI is available on CLOUD.

But on Premise and in


ABAP on HANA we still use SE11.
HOW TO CREATE CDS VIEW:
1- Right Click on USER NAME and ->NEW->Other ABAP REPOSITORY OBJECT
2- Type Core Data and click on Data Definition

3-Give Name and Description and click NEXT and Then FINISH.
4- This is what you get.

 All the things which starts with @ are called annotations.


 First annotation is for DDIC View and HANA View Name(Run Time) and it has to be less than 16
Chars
 Preserve Key annotation tells the system that use the Database table Key as Key for CDS View
 Line 6 name is Design Time (Entity Name).

 Hit Control Space and ENTER


HOW TO USE CDS VIEW IN ABAP PROGRAM:
USE OF EXPRESSION IN CDS VIEW:
Simple CASE EXPRESSION:

EXTENSION CDS:
Suppose we have standard CDS which SAP Provided. And if we want to
add a new field, we can use existing CDS View and just add new field.
Click NEXT->NEXT and then you get option Extend View
Remove last line and hit control space and you will get all fields. Select
fields to add.

VIEW ON VIEW:
Suppose we want to use our view on another view and that on other view we want to pass a parameter
to existing view. Right click on Data Definition and create new view.
Give name and hit next.

Define View
Give SQL View Name and select from original view and give where clause. You can Create N number of
view on View. Here is hard coded Currency Code.

Parametrized View: we will pass Currency Code as Parameter.

When we execute, it will ask Currency Parameter to pass Value.


Lets see how to pass this parameter on VIEW ON VIEW again.

Give SQL name and Pass Parameter to Original View on View CDS View.
DDIC VIEWS vs CDS VIEWS:
USE OF SYMANTICS:

CDS View With Aggregation:


JOINS in CDS Views:
Another Example

ASSOCIATION in CDS View:


For example, when we develop a FIORI app for sales order data, We have a CDS view for Header and for
items and then We use a third View to join these two so that when a SALES ORDER is selected in FIORI
app its related item data is displayed. BUT a join is not good idea as it will display all the items for all the
sales order. That is where ASSOCIATION comes handy. ASSOICATION provides data on demand, it does
not provide data at all time.

This Type of Association is called ADHOC ASSOCIATION and work like a JOIN.

It is recommended not to use Adhoc Association because of join being performed. Rather use

EXPOSED ASSOCIATION:

Just Put Association Name.


It Will Fetch only from Table on Left and no field from Table on right

So in FIORI app, Items will be shown on Left side.

Now if you want to show product details on right side of Fiori App for selected Item on Left side
Right Click on ITEM and select follow Association

Now it shows ASSOCIATION. You double click and it shows you one single product because of
CARDINALITY 0..1

Same way it works in FIORI APP


ANOTHER EXAMPLE WITH BUINSESS PARTNER AND INVOICE HEADER:

SUPER VIEW WHICH WILL USE ITEM AND HEADER VIEWS TO DISPLAY FIROI APP:
Put HEADER Association View in Select FROM and ITEM association View in TO Section with Cardinality
1..* as we wan to select all item for one header selection.

Header Detail is fetched

Upon right Clicking and selecting association, system will show items
We Create ODATA Service using WebIDE. For more information watch how to SET UP WEBIDE

https://www.youtube.com/watch?v=1KACIrCTo04

and how to connect WEBIDE to GATWAY

SAP WebIDE Connect to Gateway

In Order to create Fiori App, You need to add annotation in your CDS View
STEPS TO ACTIVATE ODATA SERVISE:

1- Hit CTRL +6 to open GUI Windsow from ADT

2- Enter Transaction Code /n/iwfnd/maint_service and hit ADD SERVICE

3- Add Service Name. Service name is always CDS View name with _CDS at the end of name.

HIT ENTER
4- Select Service name and hit ADD SELECTED SERVICE

5- Add Package Name where CDS View and Service Activation is so that it can be Transported.

6- Hit OK button
7- Go Back one step and you can see your active service . HIT CALL BROWSER Button

8- It will ask credentials

8- You will see it has created ODATA Service out of the BOX. We have 3 Entity sets, 1, for BP, 2 nd for Item
and 3rd for Super Invoice
NOTE: THIS IS ONE OF THE WAY TO CREATE ODATA SERVICE

VIDEOS FOR REST FULL ABAP:

https://www.youtube.com/playlist?list=PLcxqFaocb9WInzqf42H2d3Rhmgze15pEQ

9- in the Browser remove $format=xml and add $metadata

You will see Association is exposed at ODATA metadata level.


10- Now Create FIORI APP from WebIDE

11- choose SAP Fiori Master-Detail Application and Hit NEXT


12- Give Details and Hit NEXT

13- Choose System and login

It Will Fetch all the Services. Choose created Service. Select the service and hit NEXT
CDS Security:
DCL: Data Control language

Lets Create a CDS View with Adhoc Association to better understand the security concept
Right now we are able to see all the data form all the countries. We will use DCL to limit this access

Keep the same name as of CDS View Name with DCL at the end
Provide CDS View name and Field Name

AUTH_ OBJECT CREATION IN ABAP:

Go to SU21 and Create Class


Select Class and Create New Object

Click Save, Add ACTVTY and click Field Maintenance

Now add Custom Field


Give Custom Field name and Data Element

Save and go back to initial and provide this field in field list

Save, Capture in TR and click on Permitted Activities


Now go back to DCL View and add the details

HOW TO CREATE A ROLE:

1- goto PFCG tcodeand give name of role an click on Create Single Role
2- Give Description, SAVE and then click on Authorization Tab and then click on Change Auth Data

3- Do not select Template


4- Click on MANUALLY button

5- Provide Authorization Object

6- It will show authority fields. Edit and add ACTIVITY and Field name as US.

7-SAVE and GENERATE Profile Button


Profile is Generated

8- Click on USER and give User Names


HOW TO SEE THE SAP PROVIDED CDS VIEW:

Go to www.api.sap.com and in Content Types in left hand menu, click on CDS Views

ANALYTICS Using CDS:


Lets say we have following sales data of last quarter.

VDM: Virtual Data Modeling:


There are 3 Types of VDM Views.

1- Private _P_ViewName: not advised to use because SAP can change them and will disrupt programs

2- Interface VDM Views: I_ViewName

These are of 2 types further

I. Basic: These are used for Master data


II. Composite: Used for Master and Transactional data.

3- Consumption VDM Views: _C_ViewName

Consumption Views are already exposed so can be used directly in ODATA Services. ODATA Enabled.
That means you do not have to build ODATA
EXAMPLE:
Will Create BASIC INTERFACE VIEW with Dimension

Click NEXT, then NEXT and then select define view and hit finish
Add Annotation and then put table name and association name and hit control space and enter all
fields.

Now Create another VIEW

Interface View Basic and Type TEXT Category


Now move to next VIEW which is PRODUCT VIEW
Execute it. And then check Associations if it bringing in Text by Right clicking on Node Key and follow
association.

Now we will Create a Composite View .i.e. Interface View for Invoices Category Type FACT
Lets Create another view to join BUPA INVOICE HEADER
NOW MOVE TO LEVEL 2.

NOTE: Composite View of TYPE CUBE is needed if we want to use for analytics.

For this level we need to have the COLUMN NAMES which we need to extract data from. And we will
get it from views created in level 1.
This Annotation is needed in all of the view in this example.

Now to create Analytics, use tcode below. Remember to put “2C” in front of view name.

otherwise we will get error when we will run this tcode.


It become KPI for analytics. Now click on Standard Query on top. Now Click on Standard Query

You see this screen now.


Click on filds on left to display Data

You might also like