Skip to Content

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

Annotation.PNG

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Renjith Michael

    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

    (0) 
    1. Michael Dräyer
       lo_ann_target = vocab_anno_model->create_annotations_target( 'YOUR_ENTITYSET' ).
       lo_ann_target->set_namespace_qualifier( 'YOUR_SERVICE' ).
       lo_annotation = lo_ann_target->create_annotation( iv_term = 'com.sap.vocabularies.UI.v1.LineItem' ).
       lo_collection = lo_annotation->create_collection( ).
      
       lo_record = lo_collection->create_record( iv_record_type = 'com.sap.vocabularies.UI.v1.DataField' ).
       lo_property = lo_record->create_property( 'Label' ).
       lo_simp_value = lo_property->create_simple_value( ).
       lo_simp_value->set_string( 'YOUR_LABEL' ).
       lo_property = lo_record->create_property( 'Value' ).
       lo_simp_value = lo_property->create_simple_value( ).
       lo_simp_value->set_path( 'YOUR_ENTITYSET_PROPERTY' ).
       lo_annotation = lo_record->create_annotation( iv_term = 'com.sap.vocabularies.UI.v1.Importance'  ).
       lo_simp_value = lo_annotation->create_simple_value( ).
       lo_simp_value->set_enum_member_by_name( iv_value = 'com.sap.vocabularies.UI.v1.ImportanceType/High' ).

      You have to redefine the “DEFINE_VOCAB_ANNOTATIONS” in your MPC_EXT class and just insert the above code for each “record”.

       

      Regards Mike

       

      (0) 
  2. Mauricio Pinheiro Predolim

    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!

     

     

     

     

     

     

     

     

     

    (0) 

Leave a Reply