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:
Then the consumption CDS view:
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:
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.
Redefine method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITYSET of your DPC_EXT:
The method fill_status_text is responsible for filling the field order_status_text.
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: