Create A CDS View (ABAP)
Create A CDS View (ABAP)
Products
Products Industries
Industries Support
Support Training
Training Community
Community Developer
Developer Partner
Partner
Tutorial Navigator /
About
About
Tutorial
0% 1 2 3 4 5 6 7 8
You will learn how to use the Core Data Services (CDS) tools
in ABAP in Eclipse.
In the following exercise you will learn how to use the new
Core Data Services (CDS) tools in ABAP in Eclipse. CDS is an
extension of the ABAP Dictionary that allows you to de ne
semantically rich data models in the database and to use
these data models in your ABAP programs. CDS is a central
part of enabling code push-down in ABAP applications.
You will add the following:
SELECT statement
CASE statement
WHERE clause
1
Step 1: Create a CDS
view
1. In the context menu of your package choose New and
then choose Other ABAP Repository Object.
https://developers.sap.com/tutorials/abap-dev-adt-create-cds-view.html#78121904-e31b-4235-910f-c43a84282573 1/7
9/30/2018 Create a CDS view (ABAP)
Name = Z_INVOICE_ITEMS
https://developers.sap.com/tutorials/abap-dev-adt-create-cds-view.html#78121904-e31b-4235-910f-c43a84282573 2/7
9/30/2018 Create a CDS view (ABAP)
2
Step 2: Enter the data
source
The new view appears in an editor. In this editor, enter the
following values:
3
Step 3: Edit the
SELECT statement
You will now insert the elds currency_code and
gross_amount into the SELECT list as follows:
https://developers.sap.com/tutorials/abap-dev-adt-create-cds-view.html#78121904-e31b-4235-910f-c43a84282573 3/7
9/30/2018 Create a CDS view (ABAP)
4
Step 4: Use an
existing CDS
association
You will now model the relationships between data sources by
using some existing CDS associations. You can use
associations in path expressions to access elements ( elds
and associations) in related data sources without specifying
JOIN conditions. You can now display the element info by
positioning the cursor on the data source name
sepm_sddl_so_invoice_item and choosing F2.
5
Step 5: Add elds
from existing
https://developers.sap.com/tutorials/abap-dev-adt-create-cds-view.html#78121904-e31b-4235-910f-c43a84282573 4/7
9/30/2018 Create a CDS view (ABAP)
associations
You will now add elds of related data sources to the SELECT
list of Z_Invoice_Items, using the associations in path
expressions. Each element in the path expression must be
separated by a period.
6
Step 6: Add a CASE
statement
If the invoice has been paid, you want to set the
payment_status to X (true). Do this by implementing a CASE
statement
ABAP Copy
1 case header.payment_status
2 when 'P' then 'X'
3 else ' '
4 end as payment_status
7
Step 7: Add a WHERE
clause
https://developers.sap.com/tutorials/abap-dev-adt-create-cds-view.html#78121904-e31b-4235-910f-c43a84282573 5/7
9/30/2018 Create a CDS view (ABAP)
You will now lter the results so that only invoice items with
currency_code = 'EUR' are retrieved.
ABAP Copy
8
Step 8: Check your
code and view your
changes
Your CDS view should look like this:
ABAP Copy
1 @AbapCatalog.sqlViewName: 'ZINVOICEITEMS2'
2 @AbapCatalog.compiler.compareFilter: true
3 @AccessControl.authorizationCheck: #NOT_REQUIRED
4 @EndUserText.label: 'CDS View for "Use-cds-view" t
5 define view Z_Invoice_Items_2
6 as select from sepm_sddl_so_invoice_item
7 {
8 //sepm_sddl_so_invoice_item
9
10 header.buyer.company_name,
11 sepm_sddl_so_invoice_item.sales_order_invoice_ke
12 sepm_sddl_so_invoice_item.currency_code,
13 sepm_sddl_so_invoice_item.gross_amount,
14
15 case header.payment_status
16 when 'P' then 'X'
17 else ' '
18 end
19
20 as payment_status,
21
22 //* Associations *//
23 header
24 }
https://developers.sap.com/tutorials/abap-dev-adt-create-cds-view.html#78121904-e31b-4235-910f-c43a84282573 6/7
9/30/2018 Create a CDS view (ABAP)
25
26 where currency_code = 'EUR'
Open the CDS View in the Data Preview by choosing F8. Your
CDS View should look like this:
https://developers.sap.com/tutorials/abap-dev-adt-create-cds-view.html#78121904-e31b-4235-910f-c43a84282573 7/7