02-14-2019 9:27 AM
Is it possible to customize the messages for an OData-service generated from CDS views? The question has the following concrete background: We use a value help, through which the user can search for a customer (article, plant, ...). The value help pulls its data from a CDS view. If the user gives an invalid customer number and presses Enter, the OData service responds with the following message:
Resource not found for segment "Z_I_CustomerVHType".
Unfortunately, the user can not do much with this message. In order to get a readable message, my workaround has been to redefine the respective method in the DPC_EXT of the OData service and to replace the error case with a separate message. With multiple entities this quickly leads to a coding-mess, furthermore this approach is only possible, if I redefine my service via SEGW.
Is there a better solution to this problem?
Appendix: OData error message
02-14-2019 3:52 PM
Hi Benedikt,
when entering a non existing value for a value help in SAP Fiori Elements List Report Template you get a warning in the UI that you have entered a wrong value.
Technically a GET request is sent to the backend that returns with an empty response.
GET SEPMRA_I_ProductCategory?search-focus=ProductCategory&$filter=ProductCategory%20eq%20%27k%27
HTTP/1.1
As discussed in your case you are sending a GET request with the entered value as a key to the backend.
In order to avoid having the need to implement each single GET_ENTITY method for each value help you can redefine the generic method
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITY
that itself calls the entity specific Methods
METHOD /iwbep/if_mgw_appl_srv_runtime~get_entity.
DATA lv_entityset_name TYPE string.
DATA lr_entity TYPE REF TO data.
lv_entityset_name = io_tech_request_context->get_entity_set_name( ).
TRY.
CALL METHOD super->/iwbep/if_mgw_appl_srv_runtime~get_entity
EXPORTING
iv_entity_name = iv_entity_name
iv_entity_set_name = iv_entity_set_name
iv_source_name = iv_source_name
it_key_tab = it_key_tab
it_navigation_path = it_navigation_path
io_tech_request_context = io_tech_request_context
IMPORTING
er_entity = er_entity
es_response_context = es_response_context.
CATCH /iwbep/cx_mgw_busi_exception .
"CATCH /IWBEP/CX_MGW_TECH_EXCEPTION .
CASE lv_entityset_name.
WHEN 'ValueHelp1Set' or 'ValueHelp2Set'.
"do some value help specific error handling
WHEN OTHERS.
ENDCASE.
ENDTRY.
ENDMETHOD.
02-14-2019 3:52 PM
Hi Benedikt,
when entering a non existing value for a value help in SAP Fiori Elements List Report Template you get a warning in the UI that you have entered a wrong value.
Technically a GET request is sent to the backend that returns with an empty response.
GET SEPMRA_I_ProductCategory?search-focus=ProductCategory&$filter=ProductCategory%20eq%20%27k%27
HTTP/1.1
As discussed in your case you are sending a GET request with the entered value as a key to the backend.
In order to avoid having the need to implement each single GET_ENTITY method for each value help you can redefine the generic method
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITY
that itself calls the entity specific Methods
METHOD /iwbep/if_mgw_appl_srv_runtime~get_entity.
DATA lv_entityset_name TYPE string.
DATA lr_entity TYPE REF TO data.
lv_entityset_name = io_tech_request_context->get_entity_set_name( ).
TRY.
CALL METHOD super->/iwbep/if_mgw_appl_srv_runtime~get_entity
EXPORTING
iv_entity_name = iv_entity_name
iv_entity_set_name = iv_entity_set_name
iv_source_name = iv_source_name
it_key_tab = it_key_tab
it_navigation_path = it_navigation_path
io_tech_request_context = io_tech_request_context
IMPORTING
er_entity = er_entity
es_response_context = es_response_context.
CATCH /iwbep/cx_mgw_busi_exception .
"CATCH /IWBEP/CX_MGW_TECH_EXCEPTION .
CASE lv_entityset_name.
WHEN 'ValueHelp1Set' or 'ValueHelp2Set'.
"do some value help specific error handling
WHEN OTHERS.
ENDCASE.
ENDTRY.
ENDMETHOD.