Reputation: 73
I implemented some CDS views with associations on a SAP NETWEAVER 7.5 SP 19 (09/2020) system.
I used in the SEGW transaction the reference by data source feature to automatically create the ODATA types and associations from the CDS views and add them to a existing SEGW ODATA project.
Then I use that ODATA service in a SAPUI5 app.
Here is one of the guides i used: https://www.saplearners.com/create-odata-service-abap-cds-views-segw/
CDS view
The CDS view is named like /ID/VIEW_NAME_CDS.
The associations are renamed with as and get an underscore before the name. The name is then _assication_name. The underscore seems to be a convention by SAP to make the navigation property readable.
Result
In the SEGW project the wizard creates a Entity Type with the name: xidxview_name_cdsType Every slash will be replaced by an x and at the end Type will be added.
The navigation property is named to_assication_name.
The association gets a name like assoc_0D6ADC4B279EADE543738376111F7216.
Goal
I want to change the name of the entity types, associations and navigation properties because I want some readable names in the sapui5 app
Clarification 2020/11/30: The name should also be changed in the SEGW transaction itself so that they are the same in SEGW and SAPUI5 because some months in the future annother developer will not think that I changed the names in the MPC_EXT class. At least I wouldn't think of that. :-)
Is this possible with annotations in the CDS view? Or any other way?
Example
@AbapCatalog.sqlViewName: 'ZTEST'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'A test'
define view /ABC/SYSTEM_RESULT_CDS as
select from system as system
association [1..*] to /abc/s_mon_result as _monitoring_results on _monitoring_results.system_id = $projection.system_id
{
key system.system_id,
system.name,
_monitoring_results
}
group by system.system_id
Entity Type: xabcxsystem_result_cdsType
This a mix of camel case style and snake case. Not very readable.
Navigation Properties: to_monitoring_results
Is ok but i would like to have the oportunity to rename it.
Association: assoc_0D6ADC4B279EADE543738376111F7216
Not readable. Only if you click on it you see the 2 entities to which the association belongs.
Upvotes: 1
Views: 6354
Reputation: 10621
You have to redefine DEFINE
method of MPC_EXT
class, the runtime artifact after service generation:
super->define( ).
DATA: lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
lo_entity_set TYPE REF TO /iwbep/if_mgw_odata_entity_set,
lo_property TYPE REF TO /iwbep/if_mgw_odata_property.
" for entity type
lo_entity_type = model->get_entity_type( 'C_Cfd_UsageType' ).
lo_entity_type->set_name( iv_name = 'CFDUsage' ).
" for association
lo_entity_type = model->get_association( 'C_CFD_Assoc' ).
lo_entity_set->set_name( iv_name = 'CFDAssociation' ).
" for entity set
lo_entity_set = model->get_entity_set( 'C_Cfd_Usage' ).
lo_entity_set->set_name( iv_name = 'CFD' ).
After that new names will be reflected in the service $metadata:
Upvotes: 1