Hello,

In this blog post we are going to see how we can read Domain values using CDS Views.

Scenario :  When we have limited number of values which are not going to change (not dynamic), in that case we can use SAP Standard CDS View which will return all the values available in Domain.

 

 

Below is step by step guide :

 

Step 1 Create Domain

Create Domain which will have multiple values available  in this example we are maintaining Fixed values for gender :

 

Create%20Domain

Step 2 Create Entity View

Create new Entity View to get all values available in Domain we created in previous step 1…

To read Domain values there are 2 standard CDS Views available.

 

  1. DDCDS_CUSTOMER_DOMAIN_VALUE
  2. DDCDS_CUSTOMER_DOMAIN_VALUE_T

 

In our case since we have multiple values available in Domain (for Gender) we will be using Entity View DDCDS_CUSTOMER_DOMAIN_VALUE_T.

 

@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Domain Read'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
    serviceQuality: #X,
    sizeCategory: #S,
    dataClass: #MIXED
}
define view entity ZI_READ_DOMAIN 
       as select from DDCDS_CUSTOMER_DOMAIN_VALUE_T( p_domain_name: 'ZDOM_GENDER') {
    key domain_name,
    key value_position,
    @Semantics.language: true
    key language,
    value_low,
    @Semantics.text: true
    text
}

 

Step 3 Validate Domain Read

Once CDS View Entity is ready, we can test Entity View following below path. Right click on Entity View and follow below shown path.

 

validate%20domain%20read

 

Step 4 View Result

Output Domain values from Entity View

 

Output%20Domain%20values

 

 

 

 

Step 5 Add Value Help / F4 Help

If we need to get/access domain values on Fiori application front end. Changes are needed in Metadata Extension file (If created). Metadata Extension file is responsible to generate Fiori UI.

 

To add Domain values available on F4 for a field, we use @Consumption annotation which takes Entity Name (Entity View Name) and Element (Field which have the selection value).

 

  @Consumption.valueHelpDefinition: [{ entity:
  {name: 'ZI_READ_DOMAIN' , element: 'value_low' },
  distinctValues: true
  }]
  Gender;

 

Step 6 Output, F4 help with Domain values

 

Once Value help is added to field in Metadata Extension file. Final output looks like below when user click on F4 on field.

 

Field%20with%20F4

 

 

 

 

Field with F4

F4%20help%20with%20Domain%20values

 

Thanks-

https://www.youtube.com/channel/UCjXZ-tts_5gde1QvptsNbrQ?sub_confirmation=1

Abhishek

 

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x