Create A Simple ABAP CDS View in ADT
Create A Simple ABAP CDS View in ADT
in ADT
Table of Contents
Table of Contents 2
Overview 4
Overview
CDS is an extension of the ABAP Dictionary that allows you to define
semantically rich data models in the database and to use these data models in
2
your ABAP programs. CDS is a central part of enabling code push-down in ABAP
applications.
You can find more information about CDS in the ABAP keyword documentation
and the SAP Community.
In this documentation, you will learn how to create a CDS (Core Data Services)
view using ABAP Development Tools (ADT).
● How to use the new Core Data Services (CDS) tools in ABAP
Development Tools for Eclipse (ADT).
● How to use the following ABAP and SQL elements in a CDS view:
○ SELECT statement
○ CASE statement
○ WHERE clause
Throughout this tutorial, objects' names include the suffix XXX. Always replace
this with your group number or initials.
3
2. Select Data Definition, then choose Next.
4
4. Accept the default transport request (local) by simply choosing Next again.
5
Enter the data source
The new view appears in an editor. Ignore the error for now. In this editor, enter
the following values:
The SQL view name is the internal/technical name of the view which will be
created in the database. Z_Invoice_Items is the name of the CDS view which
provides enhanced view-building capabilities in ABAP. You should always use
the CDS view name in your ABAP applications.
1. Trigger code completion in the SELECT list (by clicking on the SELECT list
and using keyboard shortcut CTRL+SPACE), then double click on the
entry Insert all elements - template. All the elements (fields and
associations) of the underlying data source are inserted into the SELECT
list.
6
2. Remove all the elements in the SELECT list which were inserted by the
code completion apart from currency_code and gross_amount. Remember
to separate the elements in the SELECT statement with a comma.
To see the related data sources that can be accessed using associations, scroll
down.To see details about the target data source of the association header,
choose the hyperlink sepm_sddl_so_invoice_header.
7
Add fields from existing associations
You will now add fields 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.
2. You will get an error, “Field header must be included in the selection list
together with field
SEPM_SDDL_SO_INVOICE_ITEM.SALES_ORDER_INVOICE_KEY”.
Resolve this by adding the field
sepm_sddl_so_invoice_item.sales_order_invoice_key to the Select
statement.
3. Add the company_name of the business partner to the SELECT list using
the associations header and buyer in a path expression
8
4. Add the payment_status from the invoice header to the SELECT list using
the association header
ABAP
case header.payment_status
when 'P' then 'X'
else ' '
end as payment_status,
9
You will now filter the results so that only invoice items with currency_code =
'USD' are retrieved.
ABAP
WHERE currency_code = 'USD'
2. Save and activate the data definition by choosing Save (Ctrl+S) and
Activate (Ctrl+F3).
ABAP
@AbapCatalog.sqlViewName: 'ZITEMS_XXX'
@AbapCatalog.compiler.compareFilter: true
10
{
header.buyer.company_name,
sepm_sddl_so_invoice_item.sales_order_invoice_key,
sepm_sddl_so_invoice_item.currency_code,
'P' then 'X' else ' ' end as payment_status, //* Associations *// header
Open the CDS View in the Data Preview by choosing F8. Your CDS View should
look like this:
11