Several days ago I wrote a blog How to build a drop down list using Smart template + CDS view which introduces how to create a drop down list based on values from a backend table.


For example, the status list in above screenshot comes from the three entries in database table ZSTATUS_FIXEDVAL.


And now a new requirement is to use the fixed value defined in an ABAP domain instead.


Here below are steps to achieve it.

1. Create an ABAP domain named ZORDER_STATUS_DOMAIN containing status list as displayed in previous screenshot.

Then create an ABAP data element based on this domain.

Create one header database table as root,


and another database table as item.

2. create two CDS views based on the two database tables accordingly:

@AbapCatalog.sqlViewName: 'zorheader'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'header view'
define view Z_I_Order_Header as select from zorder_header
association [0..*] to Z_I_Order_Item as _Item
on $projection.object_id = _Item.parent_id
  key zorder_header.object_id,
  @ObjectModel.association.type: #TO_COMPOSITION_CHILD
@AbapCatalog.sqlViewName: 'zorITem'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'order item detail'
define view Z_I_Order_Item as select from zorder_item {
  @UI.lineItem : [{position:10, label : 'Parent ID'}]
  key zorder_item.parent_id,
  @UI.lineItem : [{position:20, label : 'Item Number'}]
  key zorder_item.item_id,
  @UI.lineItem : [{position:30, label : 'Item Description'}]

Then the consumption CDS view:

@AbapCatalog.sqlViewName: 'zjorderview'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Jerry order consumption view'
@Search.searchable: true
@OData.publish: false
@ObjectModel: {
   compositionRoot: true,
   type: #CONSUMPTION,
   transactionalProcessingDelegated: true,
  typeName:       'Jerry Service Order',
  typeNamePlural: 'Jerry Service Orders',
  title: { value: 'object_id' },
  description: { value: 'description' }
define view Z_C_Order as select from Z_I_Order_Header {
  @UI.lineItem : [{position:10, label : 'Service Order ID'}]
  @UI.identification: [ { position: 10,  label : 'Service Order ID' } ]
  @Search:{ defaultSearchElement: true, ranking: #HIGH, fuzzinessThreshold: 0.8 }
  @UI.selectionField: [ { position: 20, label : 'Service Order ID' } ]
  key Z_I_Order_Header.object_id,
  @UI.lineItem : [{position:20, label : 'Service Order Description'}]
  @UI.identification: [ { position: 20,  label : 'Service Order Description' } ]
  @Search:{ defaultSearchElement: true, ranking: #HIGH, fuzzinessThreshold: 0.8 }
  @UI.selectionField: [ { position: 10, label : 'Description' } ]
  @UI.identification: [ { position: 30,  label : 'Order Status' } ]
  @ObjectModel.association.type: [#TO_COMPOSITION_CHILD]

Now all are done except remaining work in ABAP side.

3. Create a new project via tcode SEGW and include the activated consumption CDS view created in step2. If you don’t know how to do it, refer to this blog Enable CRM Service Order application with edit functionality.

Generate runtime artifacts. Now both DPC and MPC classes are generated.

3.1 Redefine DEFINE method of your MPC_EXT class:


super->define( ).
      io_odata_model = model
      io_vocan_model = vocab_anno_model
      iv_namespace = 'sap'
      iv_entitytype = 'Z_C_OrderType'
      iv_property = 'order_status'
      iv_search_help = space
      iv_search_supported = abap_false
      iv_search_help_field = space
      iv_valuelist_entityset = 'OrderStatusEntitySet'
      iv_valuelist_property = 'Code' ##NO_TEXT
      )->add_display_parameter( iv_valuelist_property  = 'Text' ).
    data(lo_txt_property) = model->get_entity_type( 'Z_C_OrderType' )->get_property( 'order_status' ).
    lo_txt_property->set_value_list( /iwbep/if_mgw_odata_property=>gcs_value_list_type_property-fixed_values ).
    data(lo_text_anno) = lo_txt_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ).
    lo_text_anno->add( iv_key = 'text' iv_value = 'order_status_text').
    lo_txt_property = model->get_entity_type( 'OrderStatus' )->get_property( 'Code' ).
    lo_txt_property->set_value_list( /iwbep/if_mgw_odata_property=>gcs_value_list_type_property-fixed_values ).
    lo_text_anno = lo_txt_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ).
    lo_text_anno->add( iv_key = 'text' iv_value = 'Text').

The code above will generate the highlighted annotations which could be found in metadata:


3.2 Since in 3.1, the entity set OrderStatusEntitySet and entity type OrderStatus do not exist in SEGW project yet, so now we have to create them manually.

Just create them from context menu by clicking Entity Types and Entity Sets in SEGW:


Create properties for entity type:


And assign entity type to newly created entity set. After that regenerate runtime artifacts.


3.3 Since now framework knows it should display the value of order_status_text to render the drop down list, so we are responsible to provide framework with correct content.


 METHOD /iwbep/if_mgw_appl_srv_runtime~get_entityset.
    CASE iv_entity_name.
      WHEN 'OrderStatus'.
        get_Status_list( IMPORTING er_entityset = er_entityset ).
            CALL METHOD super->/iwbep/if_mgw_appl_srv_runtime~get_entityset
                iv_entity_name           = iv_entity_name
                iv_entity_set_name       = iv_entity_set_name
                iv_source_name           = iv_source_name
                it_filter_select_options = it_filter_select_options
                it_order                 = it_order
                is_paging                = is_paging
                it_navigation_path       = it_navigation_path
                it_key_tab               = it_key_tab
                iv_filter_string         = iv_filter_string
                iv_search_string         = iv_search_string
                io_tech_request_context  = io_tech_request_context
                er_entityset             = er_entityset
                es_response_context      = es_response_context.
          CATCH /iwbep/cx_mgw_busi_exception .
          CATCH /iwbep/cx_mgw_tech_exception .
        IF iv_entity_name = 'Z_C_OrderType'.
          fill_status_text( CHANGING cr_entityset = er_entityset ).

The method fill_status_text is responsible for filling the field order_status_text.

All the source code of ABAP classes could be found from this link:

Note: if you comment out the line 40 and 46,


The annotation for order_status_text will become “standard”, instead of previous “fixed-values”.


In this case, this field will be rendered as F4 value help instead:



To report this post you need to login first.


You must be Logged on to comment or reply to a post.

Leave a Reply