Skip to Content
0
Nov 19, 2020 at 06:55 PM

SAP CDS how to add Hierarchy annotations sap:hierarchy-node-for sap:hierarchy-level-for

3233 Views

Through a CDS view how can we add the annotations for:

  • sap:hierarchy-node-for
  • sap:hierarchy-level-for
  • sap:hierarchy-parent-node-for
  • sap:hierarchy-drill-state-for

I do not see these specific annotations:

I need to generate the metadata to look like

<EntityType Name="Node">
	<Key>
	     <PropertyRef Name="NodeID" />
	</Key>
	<Property Name="NodeID" Type="Edm.Int32" Nullable="false" edmanno:StoreGeneratedPattern="Identity" sap:hierarchy-node-for="NodeID"/>
	<Property Name="HierarchyLevel" Type="Edm.Int32" Nullable="false" sap:hierarchy-level-for="NodeID"/>
	<Property Name="WBSDescription" Type="Edm.String" MaxLength="40" sap:label="WBS Element Name" sap:quickinfo="PS: Short description (1st text line)"/>
	<Property Name="ParentNodeID" Type="Edm.Int32" Nullable="true" sap:hierarchy-parent-node-for="NodeID"/>
	<Property Name="DrillState" Type="Edm.String" Nullable="false" MaxLength="10" Unicode="true" FixedLength="false" sap:hierarchy-drill-state-for="NodeID" />
</EntityType>



I tried the following annotations but it is not working:

@Hierarchy.parentChild: { name: 'WBSHierarchy',
                            recurse : { 
                                parent: [ 'ParentNodeID'],
                                child: ['NodeID'] }

My fields in the CDS are defined as:

    //NodeID
    key concat( _Project.Project, _WBSElementHierarchy.HierarchyNode) as NodeID,


    //HierarchyLevel - Need to zero sequence the Hierarchy
    _WBS.WBSElementHierarchyLevel - 1 as Hierarchylevel,
    
    //ParentNodeID
    case 
        when (_WBS.WBSElementHierarchyLevel > 1)
            then concat( _Project.Project, _WBSElementHierarchy.ParentNode)
        else
            '' 
    end as ParentNodeID,
    _WBSParent,


    //DrillState
    cast( 'expanded' as abap.sstring(10) ) as DrillState,

Is there a way to add those exact annotations to the Node, Hierarchy Level, Parent and Drillstate to the individual fields?

Thanks,

Jay