View Definitions in ABAP Core Data Services (ABAP CDS)
ABAP Code Data Services, or ABAP CDS for short, is an infrastructure for defining and consuming semantically rich data models in ABAP. They use a CDS DDL to define CDS entities that implement a semantic data model. The most important CDS entities are CDS View entities.
The CDS View definition contains re-usable SQL logic; sometimes as simple as a projection of table fields and sometimes more sophisticated with calculations, aggregations, joins, unions, and so on.
A CDS View definition can contain associations to reflect the relations of the data model. Consumers of the view can use the associations to retrieve related data.
Finally, annotations are used to semantically enrich the view definition. This metadata is evaluated by frameworks that build on top of CDS View definitions. One such framework is the ABAP RESTful Application programming model (ABAP RAP), for which we will discuss an example later in this course.
Let's watch examples of CDS view definitions.
You already learned how to use the Data Preview tool to display and analyze the content of a database table. This tool is also available for CDS view entities.
To open the Data Preview for a given CDS entity, right-click anywhere in the data definition and choose Open With > Data Preview. Alternatively, place the cursor anywhere in the database table definition and press Ctrl + F8.
The tool displays the data returned by the CDS entity. The same functions are available to sort or filter the data and adjust the display.
If the view definition contains one or more associations, you can use them to display related data. To do so, proceed in the following manner:
- Right-click on a row in the display.
- From the context menu, choose Follow Association.
- From the list of available associations, choose the one in which you are interested.
If you want to find all CDS Views with a certain database table as a source, you can utilize the Where-used List tool of ADT. To use this tool, proceed as follows:
- Open the definition of the database table.
- Right-click anywhere in the source code and choose Get Where-used List from the context menu. Alternatively, you can press Ctrl + Shift + G, or choose the button from the toolbar with the same symbol.
- The Search view displays a list of all development objects that directly use the database table.
You can apply filters to the Where-used List if, for example, you are only interested in objects from certain packages or objects of the specific object type. The example illustrates how to filter for CDS views that use the table.