13/09/2018

Add more Annotation to metadata in already exist entity in Odata

Annotation is use to add the metadata property of column like a fiedcatlog  for SAP ALV. We  need to add some property like Edit , Hotspot the column , visibility etc. Need to add the Code in MPC Extension  method  name DEFINE. Use the below code .

Before adding your code Metadata Looks like .


DATA:

lo_entity_type             TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
lo_property                 TYPE REF TO /iwbep/if_mgw_odata_property,
lr_med_exception       TYPE REF TO /iwbep/cx_mgw_med_exception,
lo_private_annotation TYPE REF TO /iwbep/if_mgw_odata_annotation,
lo_model                     TYPE REF TO /iwbep/cl_mgw_odata_model,
lt_entities                     TYPE /iwbep/if_mgw_med_odata_types=>ty_t_med_entity_types,
lt_properties                TYPE /iwbep/if_mgw_med_odata_types=>ty_t_med_properties,
lv_entity                       TYPE string.

lv_entity = Entity Name.

"To call super class method for already exist entity.

super->define( ). 

lo_entity_type = model->get_entity_type(   lv_entity ).
lo_model ?=  model.
lt_entities = lo_model->mt_entities.

IF line_exists( lt_entities[ name = lv_entity ] ).
lt_properties = lt_entities[ name = lv_entity ]-properties.

       LOOP AT lt_properties ASSIGNING FIELD-SYMBOL(<ls_property>).

lo_property = lo_entity_type->get_property( <ls_property>-external_name ).
lo_private_annotation = lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( /iwbep/if_mgw_med_odata_types=>gc_sap_namespace ).
lo_private_annotation->add( iv_key = 'Hotspot' iv_value = 'true' ).
lo_private_annotation->add( iv_key = 'Visible' iv_value = 'true' ).
lo_private_annotation->add( iv_key = 'Edit' iv_value = 'false' ).

ENDLOOP.
ENDIF.



  After adding the code metadata looks like .

No comments:

Post a Comment