2

I want to modify an element inside a cds view in order to change the way it is displayed. I tried using virtual elements and it works fine if I take the data from a separate element (storing the original data) and put it into a new virtual element.

However I cannot figure out how to modify the element itself without displaying an redundant one in my table. If I try to hide the original one, the data is not loaded correctly. If I try to make the original element virtual it loses it's own data.

What is the correct way to achieve what I want?

Stefan Blamberg
  • 816
  • 9
  • 24
  • What is your use case? can you just build another CDS view on top of that view with additional display logic for that element? – Haojie Aug 31 '17 at 07:15
  • @Allen No, unfortunately not. The modification of the elements requires ABAP code, the cds modification functions are not enough – Stefan Blamberg Sep 01 '17 at 06:23
  • One way you can provide UI.hidden: true annotation for your original element. – Haojie Sep 01 '17 at 09:10
  • @Allen When you hide the element through this annotation, the virtual element doesn't receive data. The original element has to be displayed.. – Stefan Blamberg Sep 01 '17 at 10:51
  • 1
    You could try SET_FIELD_CONTROL for the original element in your mpc_ext to hide the element in front end. https://wiki.scn.sap.com/wiki/display/EmTech/SAP+Annotations+for+OData+Version+2.0#SAPAnnotationsforODataVersion2.0-Property_field_controlAttributesap:field-control – Haojie Sep 04 '17 at 09:34
  • @Allen I cannot edit the mpc_ext because the OData service is auto-generated (at lease I do not find it). However, isn't the field control the same as setting UI.hidden: true in the backend? – Stefan Blamberg Sep 05 '17 at 09:37
  • If you are using virtual elements, I believe you use RDS to expose your CDS views as virtual elements are SADL implemented. UI.hidden is to exclude the field from RDS mapping. – Haojie Sep 05 '17 at 09:45
  • @Allen I modified the mpc_ext but I am not sure how to set the field control. I tried something like this: `lo_procstatus = lo_entity_type->get_property( iv_property_name = 'procstatus'). lo_procstatus_annotation = lo_procstatus->/iwbep/if_mgw_odata_annotatabl~create_annotation( iv_annotation_namespace = /iwbep/if_mgw_med_odata_types=>gc_sap_namespace ). lo_procstatus->set_field_control( '0' ).` – Stefan Blamberg Sep 07 '17 at 11:51
  • Hello, is it working? if not, try lo_procstatus_annotation->add( iv_key = 'field-control' iv_value = '0' ). – Haojie Sep 08 '17 at 01:07
  • Hi, it doesn't work, I get the following error: `HTTP request failed404,Not Found,{"error":{"code":...,"message":{"lang":"en","value":"Resource not found for the segment '0'."}` – Stefan Blamberg Sep 08 '17 at 07:55
  • How do you want to modify it? Give the sample and give your CDS – Suncatcher Oct 27 '19 at 21:27

1 Answers1

0

I just did my own testing regarding how to exclude your original column on SmartTable. Below is working on my testing demo.

To exclude your original column from showing in the Column tab of Table setting dialog, there is an annotation sap:visible = false.

Redefine the Define method of your mpc_ext:

data: 
lo_entity_type type ref to /iwbep/if_mgw_odata_entity_typ,
lo_property    type ref to /iwbep/if_mgw_odata_property,
lo_annotation  type ref to /iwbep/if_mgw_odata_annotation.

super->define( ).

lo_entity_type = model->get_entity_type( 'YOUR_ENTITY_TYPE' ).

lo_property = lo_entity_type->get_property( 'YOUR_ORIGINAL_COLUMN' ) .

lo_annotation = lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( /iwbep/if_mgw_med_odata_types=>gc_sap_namespace ).
lo_annotation->add(
    iv_key    = 'visible'
    iv_value  = 'false'
).
Haojie
  • 5,665
  • 1
  • 15
  • 14
  • I tried this before but my virtual elements don't receive data anymore when I use this approach to hide the original elements – Stefan Blamberg Sep 11 '17 at 06:33
  • Hello, i just double checked. I have both the sap:visible annotation and data. There is something you missed? – Haojie Sep 11 '17 at 06:46