Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
JerryWang
Product and Topic Expert
Product and Topic Expert
27,237

In the blog Step by Step to create CDS view through SmartTemplate + WebIDE and Create a CRM Service Order Fiori application within a couple of minutes we get an Fiori application generated which needs several fine-tuning on appearance. For example, the status field is by default rendered as a pure input field with technical status code like "OPEN", "PROC" displayed. It is better to render it as a drop down list with human readable text like "Open", "In process" displayed as drop down list item.


I searched in SCN and could not find a working solution for it, so I spent some time for research and would like to share with you here.



Step1 Create a simple CDS view to hold status code and status description


@AbapCatalog.sqlViewName: 'zstatusfixed'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'fixed value'
define view Z_C_Status_Fixedvalue as select from zstatus_fixedval {
@EndUserText.label: 'status key for fixed value'
key zstatus_fixedval.status_code,
@EndUserText.label: 'status description for fixed value'
zstatus_fixedval.status_text
}

Previewed as below:



Here below is the table definition on top of which the CDS view above is created.



For demonstration purpose I create a Z table and only inserted three status items:




Step2 link the status field to the CDS view created in previous step


I have defined the consumption view Z_C_Service_Order_View with below source code:



define view Z_C_Service_Order_View as select from Z_i_Order_View
...
@UI.identification: [ { position: 50 } ]
@Consumption.valueHelp: '_statusfixedvalue'
@ObjectModel: { foreignKey.association: '_statusfixedvalue', mandatory: true }
Z_i_Order_View.txt04,
...

Where does the definition of "_statusfixedvalue" come from?


It is defined in view Z_i_Over_View:



define view Z_i_Over_View as select from XXXX
association [0..1] to Z_C_Status_Fixedvalue as _statusfixedvalue
on $projection.txt04 = _statusfixedvalue.status_code
{
...
_status_text.txt04,
...
@ObjectModel.association.type: #TO_COMPOSITION_CHILD
_statusfixedvalue
}

So far the work on CDS side is done.



Step3 create necessary annotation in ABAP code


Prerequisite: you should first create a project using tcode SEGW and then include your CDS consumption view via the context menu as below:


Redefine method DEFINE of your MPC_EXT class with following source code:



    super->define( ).
DATA lo_annotation TYPE REF TO /iwbep/if_mgw_odata_annotation.
DATA lo_property TYPE REF TO /iwbep/if_mgw_odata_property.
DATA lo_entity_set TYPE REF TO /iwbep/if_mgw_odata_entity_set.
lo_entity_set = model->get_entity_set( 'Z_C_Service_Order_View' ).
lo_annotation = lo_entity_set->create_annotation( 'sap' ).
lo_annotation->add( iv_key = 'semantics' iv_value = 'fixed-values').
DATA(lo_entitytype) = model->get_entity_type( 'Z_C_Service_Order_ViewType' ).
lo_entitytype->set_is_value_list( abap_true ).
data(lo_txt_property) = model->get_entity_type( 'Z_C_Service_Order_ViewType' )->get_property( 'txt04' ).
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 = 'to_statusfixedvalue/status_text').
lo_txt_property = model->get_entity_type( 'Z_C_Status_FixedvalueType' )->get_property( 'status_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 = 'status_text').

Note: those ABAP code is necessary, or else you will only get an ugly drop down list: only status code is displayed:




Final result


In display mode and in edit mode, the status description is displayed:



11 Comments
JK
Contributor
0 Kudos

thanks for sharing!

Former Member
0 Kudos
Hi Jerry,


Thanks for your valuable blog. Can we also do the OData Annotations model for @UI.lineitem.position ??


Regards,
Sujin
beat_birrer
Explorer
Hi Jerry,

is it also possible to set the annotation "sap:semantics: fixed-values" for the entity set directly in the CDS-View? I use the "OData.publish-Annotation" for the generation of the oData-Service and in this case there is no mpc_ext class available in the Service . At the moment I have a value list dialog instead of a drop down list.

Regards,

Beat
FabioPagoti
Active Contributor
I have the exact same scenario as you beat.birrer - were you able to do it without MPC_EXT class?
VladyslavShchur
Explorer
0 Kudos
Hi,

you need to create a new project in tcode SEGW with reference to your OData published CDS view, then generate run-time artifacts and you will get MPC_EXT class where you can redefine DEFINE method as described in this blog.

Hope this helps.

Vlad
FabioPagoti
Active Contributor
0 Kudos
In my scenario in the end I did exactly what you described: create a project in SEGW.

However the question was about CDS exposed as annotations and in such cases there is no SEGW project.

I haven't try but *maybe* there is hope on that extending class CL_SADL_GW_CDS_EXPOSURE_APC and adjusting the configuration in transaction /IWBEP/REG_VOCAN
freilinger
Participant
Hi Fabio,

redefining the class you mentioned was also our idea and indeed you are able to reach a few goals in this way. However SAP does not recommend to redefine the class and in the newer NW releases (like NW7.52) they decided to forbid this by setting the class to final.

The conclusion here is to really use the Auto-Exposure scenario with OData.publish only in very lightweight scenarios and at best for demos, trainings or stuff like this.

When it comes to productive usage, also SAP recommends to use SEGW with RDS (Remote Data Source) as this is implemented pretty quickly as well and you earn a lot of flexibility with the MPC_EXT and DPC_EXT classes.

In addition, one argument for SEGW/RDS is, that SAP announced the RESTful programming model for the future in cloud and OnPrem - to be able to integrate your existing implemention smoothfully there, the best way is to use SEGW/RDS right now.

Best regards,

Sebastian
lavanyar087
Associate
Associate
what is the view
Z_C_Service_Order_ViewType

 
RaminS
Active Participant
Hi sebastian.freilinger-huber3

It's been 3 years since your post and I was wondering, is your advice still valid now? Are we supposed to use oData.publish only for demos and training? And for real projects use SEGW/RDS?

With RAP model and Fiori Elements, we are not really supposed to manually code logic in DPC_EXT and MPC_EXT.

Are we?

 
0 Kudos
Hi Jerry,

 

I have a requirement where i want to update User staus (with number) of Notification. For that I have created a drop down which shows list of all user status with number.
But I want to restrict data in that drop down on basis of status profile of a particular notification.

For eg : Notification = 10000001 has profile = ZTEST1 which contains 3 User Status's.

Notification = 10000002 has profile = ZTEST2 which contains 2 User Status's.

So, if I select Notification 10000001 from app, only 3 status should appear in drop down based on  its profile. But currently I get all 5 values.

 

Can you please help?
Regards,

Shilpi
freilinger
Participant
0 Kudos

Hi @RaminS 

It's been 3 years since your post, therefore time to answer 🙂

From my perspective, if you are on NW7.50 this still applies as there are no downports expected. Just create a SEGW project, referencing your CDS View instead of using OData.publish: true. It takes 5 minutes during development and provides significantly more flexibility. 

When it comes to RAP, now the story is different anyway - we now have CDS Entities and if you want to achieve something like a DPC_EXT in the past, the way to go is with Custom CDS Entities. However if you need no ABAP Coding to be added to you data selection, CDS now comes with a significantly improved annotation set. Here I can outline the RAP Feature Showcase App

Best regards, 

Sebastian