Defining a Basic CDS View (2024)

Objectives

After completing this lesson, you will be able to:

  • Create a data definition.
  • Maintain the FROM clause and element list.

Creating a Data Definition

Defining a Basic CDS View (49)

To create a new data definition, proceed as follows:

  1. Right-click on your project in the Project Explorer.
  2. Choose NewABAP Repository Object …
  3. From the list, choose Core Data ServicesData Definitions.

    Hint

    You can use the input field below Project to type a search term, for example data def.

  4. Choose Next.
  5. Enter the name of an existing package, and a name and description for the new data definition.

    Hint

    If you enter the name of a database table or the name of a CDS View entity as Referenced Object, the new view will read all fields from that referenced object.

Defining a Basic CDS View (50)

Defining a Basic CDS View (51)

If your package already contains a data definition, you can use the following shortcut:

  1. In the Project Explorer, expand the subnode Core Data ServicesData Definitions of the favorite package.
  2. Right-click Data Definitions and choose New Data Definition.

Data Definition Templates

Defining a Basic CDS View (52)

When you create a new data definition, you can begin with a blank page. Alternatively, you can use one of several available templates as a starting point. The recommended template when defining a simple view is Define View Entity.

Usually, a respective dialog appears after you assign the new data definition to your transport request. But you can always return to the template selection later in the editing process.

Defining a Basic CDS View (53)

To choose a template later, go to the Templates tab in the tabstrip below the editor window.

Note

You may define your own templates in the editor preferences. Go to WindowPreferences and search for "Data Definition Templates".

The FROM Clause

Defining a Basic CDS View (54)

A CDS view never stores data by itself. It always references one or more data sources from which it reads the data.

The data foundation of a CDS view is specified in the define statement after keyword FROM. Here you can specify database tables and other CDS views.

Hint

When you press Ctrl + Space to enter the data source using code completion, the editor only suggests development objects that are suitable as data sources.

The Element List

The Element List

Play the video to learn about the element list.

Defining a Basic CDS View (55)

The keyword KEY makes a view element part of the views key. The key elements have to be placed in one block at the beginning of the element list.

For a CDS view, it is not mandatory to define a key but it is strongly recommended. You will see a warning from the syntax check if the view does not contain at least one key element.

There is another warning if the key of the CDS view does not match the key of its data source. There can be reasons to ignore this warning but usually the key of the view should be identical to the key of the data source. There is one general exception though: If the data source is a database table with a client field, this client field should not be part of the element list of the view.

With the AS addition, you can define a name for an element. If an element is just a field of the data source, the AS addition is optional. In that case, the name stays the same as in the data source.

Hint

In database tables, the field names make no distinction between uppercase and lowercase. When a CDS view reads from a database table, it is common practice to increase readability by introducing alias names that consist of a mixture of uppercase and lowercase characters (mixed-case). In the example, employee_id became EmployeeID and first_name became FirstName.

Defining a Basic CDS View (56)

Instead of adding the fields of the data source one by one, you can press Ctrl + Space and choose Insert all elements. This template not only adds all fields of the data source (except for the client field) to the element list, it also takes over the key definition and suggests alias names in mixed-case for all fields.

Note

When you create a CDS view with a DB table or a CDS view as Referenced Object, the Insert all elements template is applied by default.

The DDL Formatter and Comments

Defining a Basic CDS View (57)

The syntax that we use in data definitions is called the CDS Data Definition Language (DDL). To increase readability you can let ADT format the DDL source. Place the cursor somewhere in the data definition and choose Source CodeFormat from the Eclipse menu or press Ctrl + F1.

By default, Eclipse uses a standard formatter profile that it derives from the ABAP system. You can define your own formatter profiles in the Eclipse Preferences dialog. Choose WindowPreferences from the eclipse menu and search for DDL Formatter.

Comments in CDS DDL

Play the video to learn about comments in CDS DDL.

How to Define a Basic CDS View

Play the video to see how to define a basic CDS view.

Define a Basic CDS View

You want to decouple the data access and the table definition. To do so, you define a CDS view entity that read

Template:

  • n.a.

Solution:

  • /LRN/R_EMPLOYEE (Data Definition)

Prerequisites

For this exercise, you need the database table for employee data that you created and filled in a previous exercise (suggested name was: Z##EMPLOY, where ## is your group number). If you have not finished that exercise, create a copy of the database table /LRN/EMPLOY_DEP .

Task 1: Define a CDS View Entity

Define a new CDS view entity that reads from your database table with employee data (suggested name: Z##_R_Employee, where ## is your group number). Use a template that adds all table fields to the element list of the view (except for the client field, the annual salary and the currency code) and that takes over the key definition from the database table.

Steps

  1. In your own package, create a new data definition (suggested name: Z##_R_EMPLOYEE, where ## is your group number). Specify your database table as Referenced Object and choose the Define View Entity template to generate the definition statement, some standard annotations and the element list.

    1. In the Project Explorer view, right-click your database table definition Z##EMPLOY to open the context menu.

    2. From the context menu, choose New Data Definition.

    3. Confirm that the Package field contains the name of your package and that the Referenced Object field contains the name of your database table definition.

    4. In the Name field, enter the name for the CDS view entity (Z##_R_Employee, where ## is your group number).

    5. Enter Employee (Entity) in the Description field and choose Next.

    6. Confirm the transport request and choose Next.

      Caution

      Make sure you don't choose Finish yet. If you do, you are not able to choose the template that you want to use.

    7. From the list of Templates, choose Define View Entity, then choose Finish.

  2. For the time being, comment elements AnnualSalary and CurrencyCode.

    1. Select both code rows and press Ctrl + < to add two slash signs (/) at the beginning of each row.

  3. Apply source code formatting.

    1. From the eclipse menu, choose Source CodeFormat. Alternatively, choose Shift + F1.

  4. Activate the data definition.

    1. Press Ctrl + F3 to activate the development object.

Task 2: Analyze the CDS View Entity

Analyze the technical implementation of the CDS view entity in the database and test the result.

Steps

  1. Display the SQL statement with which the technical representation of the view entity is created in the database.

    1. Right-click anywhere in the source code of the data definition and choose Show SQL CREATE Statement.

  2. Open the Data Preview for your CDS view.

    1. Right-click anywhere in the source code of the data definition and choose Open WithData Preview. Alternatively, place the cursor anywhere in the source code of the data definition and press F8.

Log in to track your progress & complete quizzes

Next lesson

Defining a Basic CDS View (2024)

References

Top Articles
The best 123movies alternatives in 2020
Ewing Irrigation Prd
How To Check Your Rust Inventory Value? 🔫
Atrium Attorney Portal
Spur H0 » Details Trix H0 Profi Club Modell 2009
Craigslist Cars For Sale San Francisco
Walmart Front Door Wreaths
True Or False Security Is A Team Effort
Northern Whooping Crane Festival highlights conservation and collaboration in Fort Smith, N.W.T. | CBC News
Un-Pc Purchase Crossword Clue
What Is a Food Bowl and Why Are They So Popular?
Nsu Occupational Therapy Prerequisites
Gamma-glutamyl Transferase (GGT) Test: MedlinePlus Medical Test
Housing Intranet Unt
Myzmanim Highland Park Nj
Cheap Motorcycles For Sale Under 1000 Craigslist Near Me
My Fico Forums
Nope 123Movies Full
Busted Newspaper Hampton County VA Mugshots
.Au Domain Godaddy
Sodexo Northern Portal
Who are Yasmin Le Bon Parents? Meet Iradj Parvaneh and Patricia Parvaneh
Truist Bank Open Saturday
Restored Republic August 10 2023
SEBO (UK) Ltd on LinkedIn: #sebouk #commercialcleaning #cleaning #floorcleaning #carpetcleaning
-apostila-de-ingles-cn-epcar-eam-essa-eear-espcex-afa-efomm-en-e-ita-pr f3476c8ab0af975f02f2f651664c5f13 - Matemática
Walgreens Shopper Says Staff “Threatened” And “Stalked” Her After She Violated The “Dress Code”
Wildflower | Rotten Tomatoes
We Take a Look at Dating Site ThaiFlirting.com in Our Review
Busted Paper Haysi Regional Jail
Walgreens Pharmacy On Jennings Station Road
Work with us | Pirelli
Ltlv Las Vegas
Lo que necesitas saber antes de desrizarte el cabello
Cheeksorpillows
Preventice Learnworlds
Dl Delta Extranet
Ignition Date Format
Otter Bustr
Shiawassee County 911 Active Events
Does Iherb Accept Ebt
Sound Of Freedom Showtimes Near Cinergy Midland
2005 Lund Boat For Sale in Ham Lake, MN Lot #67597***
Okeeheelee Park Pavilion Rental Prices
10439 Gliding Eagle Way Land O Lakes Fl 34638
Culver's Flavor Of The Day Little Chute
Hkx File Compatibility Check Skyrim/Sse
Busted Newspaper Zapata Tx
Fapello.ckm
EXTON: THE MOST BEAUTIFUL CHOCOLATE BOX VILLAGE IN RUTLAND
Lubbock Avalanche Journal Newspaper Obituaries
Sammyflood
Latest Posts
Article information

Author: Saturnina Altenwerth DVM

Last Updated:

Views: 6644

Rating: 4.3 / 5 (44 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Saturnina Altenwerth DVM

Birthday: 1992-08-21

Address: Apt. 237 662 Haag Mills, East Verenaport, MO 57071-5493

Phone: +331850833384

Job: District Real-Estate Architect

Hobby: Skateboarding, Taxidermy, Air sports, Painting, Knife making, Letterboxing, Inline skating

Introduction: My name is Saturnina Altenwerth DVM, I am a witty, perfect, combative, beautiful, determined, fancy, determined person who loves writing and wants to share my knowledge and understanding with you.