Code snippet for adding annotations to your Gateway Service
Now that annotations are making UI5 development easier by using Smart controls, it is important to learn how to add these annotations to your service. SEGW does not yet allow you to add most of the annotations. Till SEGW inherently provides that feature, here is how you can do it using code.
Step 1. Goto you MPC_EXT class
Step 2. Redefine Define method.
Step 3. Write this code.
METHOD define.
DATA: lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
lo_property TYPE REF TO /iwbep/cl_mgw_odata_property,
lo_annotation TYPE REF TO /iwbep/if_mgw_odata_annotation.
super->define( ). "Ensure you call the parent metadata
lo_entity_type = model->get_entity_type( iv_entity_name = 'SESItem'). "Your Entity Name
lo_property ?= lo_entity_type->get_property( iv_property_name = 'Date'). "Property inside your Entity
CALL METHOD lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation
EXPORTING
iv_annotation_namespace = /iwbep/if_mgw_med_odata_types=>gc_sap_namespace
RECEIVING
ro_annotation = lo_annotation.
lo_annotation->add( iv_key = 'display-format' iv_value = 'Date' ). "Specific annotation you want to add.
ENDMETHOD.
This will result in
Hi,
Very useful document.
Can you please share any code snippet for adding the below:
<Annotation Term="UI.Importance" EnumMember="UI.Importance/High"/>
Thank you,
Regards,
Renjith Michael
You have to redefine the "DEFINE_VOCAB_ANNOTATIONS" in your MPC_EXT class and just insert the above code for each "record".
Regards Mike
thanks!
Hi guys!
Is it possible to sort/order an annotation?
Eg.: We have a search help field that its origins is an annotation composed by check tables (GBLND field - check table T005).
Smartfield has no sort/order by property
So, when the field is displayed, has no sort by LANDX(description) only by id (LAND1)
If i can't sort using annotation i'll have to rebuild the field using select statement on odata backend.
Best Regards!
Hi,
It was great blog 🙂
Can you please brief me how to achieve Smart-Chart Functionality using code based annotations.
Thank You,
Pankaj