CDS and Domain Fixed Values as Value Help

"Fiori Elements" is a great opportunity for rapid application development for simple scenarios. In lot of cases ABAP developers maintain domain fixed values to have a drop-down list automatically generated by one of the UI technologies like GUI and WebDynpro. Domain fixed value often represent a Status or something like that, where we can say the values are static. In case of OData services and UI5 such control is not generated automatically, but you need to put annotations in your CDS View to make this working. With the below snippets we'll use CDS Views, to retrive domain low fixed values and their description. The approach below is not the only one, which can lead to the same result. At the end the Object Page template in Fiori Elements ( or your app importing annotation file) will consider the annotations and display a proper value help.

Step 1 - Create a basis CDS View to retrieve domain fixed values (low) and their texts

This view can be reused as basis. Do it once, and use it in every Modeled Value Help View created for your domains. Create a new CDS data definition ZCDS_DOMAIN_FIX_LOW in eclipse, and include the below snippet.

@AbapCatalog.sqlViewName: 'ZV_DOMFIXL'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Search.searchable: true
@EndUserText.label: 'Domain fixed value help'
define view Zcds_Domain_Fix_Low
  as select from    dd07l as FixedValue
    left outer join dd07t as ValueText on  FixedValue.domname    = ValueText.domname
                                       and FixedValue.domvalue_l = ValueText.domvalue_l
                                       and FixedValue.as4local   = ValueText.as4local

  key FixedValue.domname    as DomainName,
  key FixedValue.as4local   as Status,
      @Search.defaultSearchElement: true
      @Search.fuzzinessThreshold: 0.8
  key FixedValue.domvalue_l as Low,
      @Semantics.text: true -- identifies the text field
      ValueText.ddtext      as Text

      FixedValue.as4local  = 'A' --Active
  and ValueText.ddlanguage = $session.system_language 

Step 2 - Create a Modeled Value Help View for the domain

At the end in the WHERE clause, put your domain name. You can customize the text to override the standard label. 

@AbapCatalog.sqlViewName: 'ZV_MYDOMAIN_VH'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'My Value Help'
@Search.searchable: true define view Zcds_My_Domain_Vh as select from Zcds_Domain_Fix_Low { @UI.hidden key Zcds_Domain_Fix_Low.DomainName, @EndUserText.label: 'Status' -- Custom label text key Zcds_Domain_Fix_Low.Low, @Semantics.text: true -- identifies the text field @Search.defaultSearchElement: true @Search.fuzzinessThreshold: 0.8 Zcds_Domain_Fix_Low.Text } where Zcds_Domain_Fix_Low.DomainName = 'ZYOURDOMAINNAME'

Step 3 - Refer the Value Help in your Consumption View

In the CDS View exposed as OData service, where you want to use the value help, associate the Modeled Value Help View, and annotate the field based on the domain.

association [0..1] to Zcds_My_Domain_Vh as _MyValueHelp on $projection.Area = _MyValueHelp.Low

@UI.selectionField.position: 30
@Consumption.valueHelp: '_MyValueHelp'
key YourEntity.YourField,