Skip to Content
Technical Articles
Author's profile photo Abhishek Sharma

How to Read Domain values using ABAP CDS Entity view

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

 

Assigned Tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Matt Dion
      Matt Dion

      Hi Abhishek,

       

      Thanks for sharing! I think there are a couple fundamentals here that should be corrected though:

      1. DDCDS_CUSTOMER_DOMAIN_VALUE : Return single row (structure)
      2. DDCDS_CUSTOMER_DOMAIN_VALUE_T : Return records in Table format multiple values

      DDCDS_CUSTOMER_DOMAIN_VALUE actually returns all fixed values associated with the domain provided via the parameter value.

      The _T prefix of the other view entity means 'Text', not 'Table'. This provides all the language dependent translations of the fixed values. If you were to maintain another translation for your fixed value descriptions, then you would end up having issues in your value help.

      Since both view entities require a parameter to be passed and since it's a little complicated to deal with that, we wrapped these two views with this:

      define view entity XXXXXXXXXXX
      with parameters
        p_domain_name : sxco_ad_object_name --abap.char(30)
      as select from DDCDS_CUSTOMER_DOMAIN_VALUE( p_domain_name : $parameters.p_domain_name ) as Value
      association [0..1] to DDCDS_CUSTOMER_DOMAIN_VALUE_T as _text on 
         Value.domain_name = _text.domain_name and 
         Value.value_position = _text.value_position and 
         _text.language = $session.system_language  
      {
        key Value.domain_name as Name,
        key Value.value_position as ValuePosition,
            Value.value_low as Value,
            _text( p_domain_name : $parameters.p_domain_name ).text as Description
      }

      This approach ensures that the values are returned, even if a description in the user's logon language has not been maintained.

      We then use this view in a similar manner as you did above to build domain specific value helps (although typically we decide on text only dropdowns).

      Hope this helps!

      Author's profile photo Abhishek Sharma
      Abhishek Sharma
      Blog Post Author

      Hi Matt,

      Thanks much for valuable comments, I have done a quick update to post..

       

      Thanks-

      Author's profile photo Mainak Aich
      Mainak Aich

      Hello @Matt Dion and @Abhishek Sharma,

      Once you declare the value help CDS view as parameterized CDS view as you did in your example here, can you please guide how will you pass the value of the parameter inside the annotation below?

      @Consumption.valueHelpDefinition: 

      Thanks,
      Mainak

      Author's profile photo Anil Dasari
      Anil Dasari

      Hi Matt and Abhishek,

      Are these Objects (DDCDS_CUSTOMER_DOMAIN_VALUE and DDCDS_CUSTOMER_DOMAIN_VALUE_T) still relevant for S/4HANA 2021 FPS 002? I have tried created CDS entities but I don't see it is pulling fixed values maintained under Domain.

      Definition

      Definition

       

      Data%20Preview

      Data Preview

      Thanks,

      Anil

      Author's profile photo Elizabeth Kinanga Daniel
      Elizabeth Kinanga Daniel

      Hi Anil,

      could you found out, why the view is empty?

       

      Thank you in advance

      Elizabeth

      Author's profile photo Suzanne Alivand
      Suzanne Alivand

      https://blogs.sap.com/2022/08/02/how-to-read-domain-values-using-abap-cds-entity-view/comment-page-1/#comment-671446

      Author's profile photo Elizabeth Kinanga Daniel
      Elizabeth Kinanga Daniel

      Hello Matt, hello Abhishek,

      I used this object and don't see any entries. DDCDS_CUSTOMER_DOMAIN_VALUE_T and don't see any entriesPleas could help.

      thank you

      Elizabeth

      Author's profile photo Suzanne Alivand
      Suzanne Alivand

      Hi

      I had the same issue, I'm using S/4 On Premise and CDS DDCDS_CUSTOMER_DOMAIN_VALUE_T is not supported in S/4 On Premise.
      I created a new CDS that directly reads from the table dd07t.

      I put an example here and hope it could helps:

      define view entity yem_i_employee_status
        as select from dd07t
      {
            @ObjectModel.text.element: ['Text']
        key cast ( domvalue_l as yem_status ) as Status,
      
            @Semantics.text: true
            ddtext                                   as Text       
      }
      where
            domname    = 'YEM_EMPLOYEE_STATUS'
        and ddlanguage = $session.system_language
      

      yem_status is Data Element and YEM_EMPLOYEE_STATUS is Domain Name