Skip to Content

How to add a custom namespace in OData Metadata?

Hi,

We have a requirement where we have to achieve a Tree Table data binding.

Like this: TreeTable

but the problem here is data is appearing in a list like manner since we don't have "edmanno" in a metadata.

xmlns:edmanno="http://schemas.microsoft.com/ado/2009/02/edm/annotation"

We have tried modifying the MPC_EXT class but unable to achieve the namespace "edmanno" and the namespace should point to liberary http://schemas.microsoft.com/ado/2009/02/edm/annotation

MPC_EXT Code and Metadata is mentioned below:

  method DEFINE.
    super->define( ).
    DATA:

      lo_annotation   TYPE REF TO /iwbep/if_mgw_odata_annotation, "#EC NEEDED

      lo_entity_type  TYPE REF TO /iwbep/if_mgw_odata_entity_typ, "#EC NEEDED

      lo_complex_type TYPE REF TO /iwbep/if_mgw_odata_cmplx_type, "#EC NEEDED

      lo_property     TYPE REF TO /iwbep/if_mgw_odata_property, "#EC NEEDED

      lo_entity_set   TYPE REF TO /iwbep/if_mgw_odata_entity_set. "#EC NEEDED

    lo_entity_type = model->get_entity_type( iv_entity_name = 'ProductTree' ).

    lo_property = lo_entity_type->get_property( iv_property_name = 'Node' ).

    lo_annotation = lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation(

    iv_annotation_namespace =  /iwbep/if_mgw_med_odata_types=>gc_sap_namespace ).

    lo_annotation->ADD(
      exporting
        IV_KEY      = /iwbep/if_ana_odata_types=>GCS_ANA_ODATA_ANNOTATION_KEY-HIERARCHY_NODE_FOR        IV_VALUE    = 'Node'

*        IV_REF_ANNO = ABAP_TRUE

    ).
   lo_property = lo_entity_type->get_property( iv_property_name = 'NodeLevel' ).



    lo_annotation = lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( iv_annotation_namespace =  /iwbep/if_mgw_med_odata_types=>gc_sap_namespace ).

    lo_annotation->add(

       exporting

        iv_key      = /iwbep/if_ana_odata_types=>GCS_ANA_ODATA_ANNOTATION_KEY-HIERARCHY_LEVEL_FOR

        iv_value    = 'Node' ).





    lo_property = lo_entity_type->get_property( iv_property_name = 'Parent' ).



    lo_annotation = lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( iv_annotation_namespace =  /iwbep/if_mgw_med_odata_types=>gc_sap_namespace ).



    lo_annotation->add(

       exporting

        iv_key      = /iwbep/if_ana_odata_types=>GCS_ANA_ODATA_ANNOTATION_KEY-HIERARCHY_PARENT_NODE_FOR

        iv_value    = 'Node' ).

*

    lo_property = lo_entity_type->get_property( iv_property_name = 'Drillstate' ).



    lo_annotation = lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( iv_annotation_namespace =  /iwbep/if_mgw_med_odata_types=>gc_sap_namespace ).



    lo_annotation->add(

       exporting

        iv_key      = /iwbep/if_ana_odata_types=>GCS_ANA_ODATA_ANNOTATION_KEY-HIERARCHY_DRILL_STATE_FOR

        iv_value    = 'Node' ).

  endmethod.
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"xmlns:sap="http://www.sap.com/Protocols/SAPData" Version="1.0">
<edmx:DataServices m:DataServiceVersion="2.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="ZPLM_PH_SRV" xml:lang="en" sap:schema-version="1">
<EntityType Name="ProductTree" sap:content-version="1">
<Key>
<PropertyRef Name="Node"/>

</Key>


<Property Name="Mandt" Type="Edm.String" Nullable="false" MaxLength="3" sap:unicode="false" sap:label="Client" sap:creatable="false" sap:updatable="false" sap:sortable="false"sap:filterable="false"/>
<Property Name="Node" Type="Edm.String" Nullable="false" MaxLength="32" sap:hierarchy-node-for="Node" sap:unicode="false" sap:label="Hierarchy ID" sap:creatable="false"sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="NodeName" Type="Edm.String" Nullable="false" MaxLength="300" sap:unicode="false" sap:label="node name" sap:creatable="false" sap:updatable="false"sap:sortable="false" sap:filterable="false"/>
<Property Name="NodeDescr" Type="Edm.String" Nullable="false" MaxLength="600" sap:unicode="false" sap:label="node description" sap:creatable="false" sap:updatable="false"sap:sortable="false" sap:filterable="false"/>
<Property Name="MaterialNo" Type="Edm.String" Nullable="false" MaxLength="40" sap:unicode="false" sap:label="Material" sap:creatable="false" sap:updatable="false"sap:sortable="false" sap:filterable="false"/>
<Property Name="MaterialDesc" Type="Edm.String" Nullable="false" MaxLength="300" sap:unicode="false" sap:label="material description" sap:creatable="false" sap:updatable="false"sap:sortable="false" sap:filterable="false"/>
<Property Name="NodeLevel" Type="Edm.String" Nullable="false" MaxLength="1" sap:hierarchy-level-for="Node" sap:unicode="false" sap:label="Node level" sap:creatable="false"sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Parent" Type="Edm.String" Nullable="false" MaxLength="32" sap:hierarchy-parent-node-for="Node" sap:unicode="false" sap:label="Hierarchy ID" sap:creatable="false"sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Drillstate" Type="Edm.String" Nullable="false" MaxLength="30" sap:hierarchy-drill-state-for="Node" sap:unicode="false" sap:label="tree" sap:creatable="false"sap:updatable="false" sap:sortable="false" sap:filterable="false"/>

</EntityType>


<EntityContainer Name="ZPLM_PH_SRV_Entities" m:IsDefaultEntityContainer="true" sap:supported-formats="atom json xlsx">
<EntitySet Name="ProductTreeSet" EntityType="ZPLM_PH_SRV.ProductTree" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:pageable="false" sap:content-version="1"/>

</EntityContainer>


<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="self" href="https://hpifctcs01.hec.hpicorp.net:44300/sap/opu/odata/sap/ZPLM_PH_SRV/$metadata"/>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="latest-version" href="https://hpifctcs01.hec.hpicorp.net:44300/sap/opu/odata/sap/ZPLM_PH_SRV/$metadata"/>

</Schema>

</edmx:DataServices>



</edmx:Edmx>



Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • May 03 at 09:03 AM

    Hi,

    Did you look at this wiki : https://wiki.scn.sap.com/wiki/display/EmTech/SAP+Annotations+for+OData+Version+2.0

    It will give you the rigth annotation to build a correct model. Read the last section EntitySet with hierarchy.

    Forget the edmanno, I would suspect that it is not relevant for hierarchy entityset.

    Regards,

    Joseph

    Add comment
    10|10000 characters needed characters exceeded