Show TOC

Adding Custom Fields to Extension View Locate this document in the navigation structure

This topic demonstrates how you can extend the syntax of the original CDS view with a view extension to provide some additional custom fields.

Adding predefined fields from original data source

In our example, by far not all fields from the original data source have been adopted into the data model. For example, details on the exact address of the organizations are missing. As a substitute for further address data, we will adopt the field CountryName into the list of line items:

  ...
	  -- Adding predefined field
	  @UI.lineItem: { label: 'Country', position: 35 }
	  Organization.CountryName
  ...			
Adding a calculated field

Fields that were not foreseen and result only after a calculation based on other defined fields are a very good example of the use of view extensions. In the following listing, a new field named party_role has been introduced. The values of this field are determined first within the case statement. In this way, the specification of the role Customer or Supplier can be output for each individual organization.

  ...		
	  -- Adding calculated field
	  @UI.lineItem:  { label: 'Role', position: 25}
	  case Organization.PartyRole
				when '01' then 'Customer'
				when '02' then 'Supplier'
				else 'Unspecified '
	  end   as party_role				
  ...
						
Results

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

	@AbapCatalog.sqlViewAppendName: 'ZSQL_PARTY_EXT'
	@EndUserText.label: 'Party Adress Data Extended'

	extend view DEMO_PARTY_ORIG with ZDEMO_PARTY_EXT
	{

	  -- Adding predefined field
       @UI.lineItem: { label: 'Country', position: 35 }
  	@Search.defaultSearchElement: true
  	Organization.CountryName,

  	-- Adding a calculated field
  	@UI.lineItem:  { label: 'Role', position: 25}
  	@Search.defaultSearchElement: true
  	case Organization.PartyRole
    		when '01' then 'Customer'
    		when '02' then 'Supplier'
    		else 'Unspecified'
  	end   as party_role

	}
						
After successful activation of the data definition, two ABAP Dictionary objects are created for the CDS view extension and are automatically added to the same ABAP package (and therefore the same transport request) as the underlying DDL source:
  • The actual CDS view extension that is specified after the EXTEND VIEW keyword
  • The CDS append view for a classic append view that is specified in quotation marks after the @AbapCatalog.sqlViewAppendName annotation. The new append view extends the CDS SQL database view of the extended CDS view.
    Caution The name given to the append view can no longer be changed after the CDS view has been transported into a follow-on system.