Вы находитесь на странице: 1из 11

12/21/2018 Create a CDS view (ABAP)

Products
Products Industries
Industries Support
Support Training
Training Community
Community  
Group /
Developer
Developer Partner
Partner About
About
Tutorial

Create a CDS view (ABAP)

0% 1 2 3 4 5 6 7 8

Details Code Snippets

// Explore More Tutorials

Create a CDS
view (ABAP)
Julie
12/02/2018
Plummer
Beginner  15  ABAP
min. Development,
Tutorial, Beginner

You will learn how to use the Core Data


Services (CDS) tools in ABAP in
Eclipse.

You will learn


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:
https://developers.sap.com/india/tutorials/abap-dev-adt-create-cds-view.html 1/11
12/21/2018 Create a CDS view (ABAP)

Provide Feedback
SELECT
statement

CASE statement

WHERE clause

You can nd more information about


CDS in the ABAP keyword
documentation and the SAP
Community.

1
Step 1:
Create a
CDS view
1. In the context menu of your
package choose New and then
choose Other ABAP Repository
Object.
Object

2. Select Data De nition,


nition then
choose Next
Next.

3. Enter the following values, then


choose Next
Next:

Name =
Z_INVOICE_ITEMS

https://developers.sap.com/india/tutorials/abap-dev-adt-create-cds-view.html 2/11
12/21/2018 Create a CDS view (ABAP)

Description = Invoice
Items

4. Accept the default transport


request (local) by simply
choosing Next again.

5. Select the entry De ne View,


View
then choose Finish

2
Step 2:
Enter the
data source
The new view appears in an editor. In
this editor, enter the following values:

1. Enter ZINVOICEITEMS as the


SQL view name.
https://developers.sap.com/india/tutorials/abap-dev-adt-create-cds-view.html 3/11
12/21/2018 Create a CDS view (ABAP)

2. Enter the CDS view


sepm_sddl_so_invoice_item
as the data source for your view.

3. Use code completion (keyboard


shortcut CTRL+SPACE
CTRL+SPACE) to get
proposals for the data source.

Note: 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.

3
Step 3: Edit
the SELECT
statement
You will now insert the elds
currency_code and gross_amount
into the SELECT list as follows:

1. Trigger code completion in the


SELECT list (by clicking on the
SELECT list and using keyboard
shortcut CTRL+SPACE
CTRL+SPACE), then
double click on the entry Insert
all elements - template.
template All the
elements ( elds and

https://developers.sap.com/india/tutorials/abap-dev-adt-create-cds-view.html 4/11
12/21/2018 Create a CDS view (ABAP)

associations) of the underlying


data source are inserted into the
SELECT list.

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.

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
F2.

https://developers.sap.com/india/tutorials/abap-dev-adt-create-cds-view.html 5/11
12/21/2018 Create a CDS view (ABAP)

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.

5
Step 5: Add
elds from
existing
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.

1. Add the company_name of the


business partner to the SELECT
list using the associations
header and buyer in a path
expression

2. You will get an error, “Field


header must be included in the
selection list together with eld
SEPM_SDDL_SO_INVOICE_ITEM.S
Resolve this by adding the eld
sepm_sddl_so_invoice_item.s
to the Select statement.

https://developers.sap.com/india/tutorials/abap-dev-adt-create-cds-view.html 6/11
12/21/2018 Create a CDS view (ABAP)

3. Add the payment_status from


the invoice header to the
SELECT list using the
association header

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
You will now lter the results so that
only invoice items with
https://developers.sap.com/india/tutorials/abap-dev-adt-create-cds-view.html 7/11
12/21/2018 Create a CDS view (ABAP)

currency_code = 'EUR' are


retrieved.

1. Add a WHERE clause:

ABAP Copy

1 WHERE currency_code = '

2. Save and activate the data


de nition by choosing Save
(Ctrl+S) and Activate
(Ctrl+F3).

8
Step 8:
Check your
code and
view your
changes
Your CDS view should look like this:

ABAP Copy

1 @AbapCatalog.sqlViewName: 'ZI
2 @AbapCatalog.compiler.compare
3 @AccessControl.authorizationC
@EndUserText.label: 'CDS View
https://developers.sap.com/india/tutorials/abap-dev-adt-create-cds-view.html 8/11
12/21/2018 Create a CDS view (ABAP)

4 define view Z_Invoice_Items_2


5 as select from sepm_sddl_so
6 {
7 //sepm_sddl_so_invoice_item
8
9 header.buyer.company_name,
10 sepm_sddl_so_invoice_item.s
11 sepm_sddl_so_invoice_item.c
12 sepm_sddl_so_invoice_item.g
13
14 case header.payment_status
15 when 'P' then 'X'
16 else ' '
17 end
18
19 as payment_status,
20
21 //* Associations *//
22 header
23 }
24
25 where currency_code = 'EUR'
26

Open the CDS View in the Data


Preview by choosing F8
F8. Your CDS
View should look like this:

Next Steps

Display a CDS view


using ALV with IDA
15 min.

https://developers.sap.com/india/tutorials/abap-dev-adt-create-cds-view.html 9/11
12/21/2018 Create a CDS view (ABAP)

This tutorial is part of these groups


and missions:

Beginner

 30 min.
4 tutorials
NEW
ABAP Development: Work
with Core Data Services…
These tutorials show you how to
retrieve data from the database and
display it in a SAP List Viewer (AL…

 ABAP Development

Developer Products

ABAP Platform

SAP Cloud Platform

SAP Data Hub

SAP HANA

SAP Web IDE

All Products

Trials & Downloads

ABAP Development Tools

SAP NetWeaver AS ABAP 7.51 SP02 Developer Edition on ASE

SAP Cloud Platform

SAP Data Hub, developer edition

https://developers.sap.com/india/tutorials/abap-dev-adt-create-cds-view.html 10/11
12/21/2018 Create a CDS view (ABAP)

SAP HANA

SAP Web IDE Full-Stack

All Trials & Downloads

Site Information

Privacy

Terms of Use

Legal Disclosure

Copyright

Trademark

Cookie Preference

Sitemap

Text View

Newsletter

Share & Follow

https://developers.sap.com/india/tutorials/abap-dev-adt-create-cds-view.html 11/11

Вам также может понравиться