Show TOC

Implement the CDS View as Data ModelLocate this document in the navigation structure

Context

In this step, you will implement a projection view as a new data model using a data source that is already predefined in the EPM demo scenario.

Procedure

  1. If you have not yet already done so, open the newly created DDL source in the text-based DDL editor.
  2. Specify the names of the...
    1. SQL view to be generated in the ABAP Dictionary: ZDEMO_SOI
    2. Actual CDS view: ZDEMO_CDS_SalesOrderItem
  3. In the SELECT statement, enter the predefined CDS view SEPM_I_SalesOrderItem_E as data source and define Item as alias name for the data source.
    ... select from SEPM_I_SalesOrderItem_E as Item {
  4. Add the Item fields to the SELECT list (as they are required for new projection view) and assign the alias names to each item field as follows:
    Tip Whenever you insert table or view fields in the SELECT list, you can avail of the Content Assist functionality in the DDL editor.
    Inserting fields by means of semantic auto-completion
    Figure 1: Inserting fields by means of semantic auto-completion
    		
    	Item.SalesOrder                         as SalesOrderID, 
    	Item.SalesOrderItem                     as ItemPosition, 
    	Item._SalesOrder._Customer.CompanyName  as CompanyName,
    	Item.Product                            as Product, 
    	Item.TransactionCurrency                as CurrencyCode,
    	Item.GrossAmountInTransacCurrency       as GrossAmount, 
    	Item.NetAmountInTransactionCurrency     as NetAmount, 
    	Item.TaxAmountInTransactionCurrency     as TaxAmount,
    	Item.ProductAvailabilityStatus          as ProductAvailabilityStatus
    
    					
  5. To document the key semantics of the new data model, define the SalesOrderItem and the ItemPosition fields as KEY elements in the current CDS view:
    	...
    	key Item.SalesOrder            	    as SalesOrderID,     
    	key Item.SalesOrderItem          	  as ItemPosition,
    	...						
    					
  6. Add the currency semantics to the corresponding Item elements.
    Tip To insert an annotation, type the first letter(s) of the annotation and then press CTRL + Space.
    Adding @Semantics annotation to an element
    Figure 2: Adding @Semantics annotation to an element
    	...
    	@Semantics.currencyCode: true
    	Item.TransactionCurrency                	as CurrencyCode,
    	@Semantics.amount.currencyCode: 'CurrencyCode'
    	Item.GrossAmountInTransacCurrency       	as GrossAmount, 
    	@Semantics.amount.currencyCode: 'CurrencyCode'
    	Item.NetAmountInTransactionCurrency     	as NetAmount, 
    	@Semantics.amount.currencyCode: 'CurrencyCode'
    	Item.TaxAmountInTransactionCurrency     	as TaxAmount,
    	...
    					

Results

The resulting source code for the CDS view is the following:


	@AbapCatalog.sqlViewName: 'ZDEMO_SOI'
	@AbapCatalog.compiler.compareFilter: true
	@AccessControl.authorizationCheck: #CHECK
	@EndUserText.label: 'List Reporting for Sales Order Item'
	
	define view ZDEMO_CDS_SalesOrderItem 
	as select from SEPM_I_SalesOrderItem_E as Item 
	{
	key Item.SalesOrder                          as SalesOrderID, 
	key Item.SalesOrderItem                      as ItemPosition, 
	Item._SalesOrder._Customer.CompanyName  	as CompanyName,
	Item.Product                            	as Product, 
	@Semantics.currencyCode: true
	Item.TransactionCurrency                	as CurrencyCode,
	@Semantics.amount.currencyCode: 'CurrencyCode'
	Item.GrossAmountInTransacCurrency       	as GrossAmount, 
	@Semantics.amount.currencyCode: 'CurrencyCode'
	Item.NetAmountInTransactionCurrency     	as NetAmount, 
	@Semantics.amount.currencyCode: 'CurrencyCode'
	Item.TaxAmountInTransactionCurrency     	as TaxAmount,
	Item.ProductAvailabilityStatus          	as ProductAvailabilityStatus
	}   
	
			

The source code above is used to define quite a simple CDS view named ZDEMO_CDS_SalesOrderItem. This view is implemented by means of a query for performing a SELECT statement, where the predefined CDS view SEPM_I_SalesOrderItem_E is used as the data source. The select list includes a set of fields that are relevant for the new sales order item projection view. The KEY elements in the selection list are used to define the key field semantic of the CDS view. The element CurrencyCode is defined as currency key using the annotation @Semantics.currencyCode: true. The annotation @Semantics.amount.currencyCode: 'CurrencyCode' defines each amount element as a currency field.

When the DDL source is activated, the following objects are created in ABAP Dictionary:

  • The actual entity of the CDS view ZDEMO_CDS_SalesOrderItem
  • An SQL view ZDEMO_SOI