cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Fiori Elements: Display Tree-Structure using OData Annotation (Code Based)

orianda_thomas
Discoverer
518

Hello,

I want to create a Tree Table with Fiori Elements using SEGW, but I'm not able to do so.

I try to follow this posts:
Fiori Elements: Display Tree-Structure using OData... - SAP Community
Fiori Elements Tree Table with SAP Annotations - SAP Community

This is my data table:

orianda_thomas_0-1753438761135.png

This are the fields:

orianda_thomas_1-1753438801530.png

 

These are my CDS Views:

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Intermediate View for Tree Structure'

define view entity ZCDS_I_TREE_STRUCTURE

as select from ztree_table

{

key id,

parentid,

hierlevel,

drilldownstate,

nodename,

nodedescription

}

 

@EndUserText.label: 'Konsumptions-View für ZTREE_TABLE'

@AccessControl.authorizationCheck: #NOT_REQUIRED

//@OData.publish: true

@UI.headerInfo: {

typeName: 'Knoten',

typeNamePlural: 'Knoten'

}

@Hierarchy.parentChild: [{

name: 'TreeHierarchy',

recurse: {

parent: ['parentid'],

child: ['id']

},

siblingsOrder: [{

by: 'nodename',

direction: #ASC

}],

rootNode: {

visibility: #ADD_ROOT_NODE_IF_DEFINED

},

orphanedNode: {

handling: #ROOT_NODES

}

}]

define view entity ZCDS_C_TREE_STRUCTURE

as select from ZCDS_I_TREE_STRUCTURE

{

 

key id,

parentid,

hierlevel,

drilldownstate,

@UI.lineItem: [{ position: 10, label: 'Node Name' }]

nodename,

@UI.lineItem: [{ position: 20, label: 'Node Description' }]

nodedescription

}

 

 

In SEGW I created a project and the did a right click on "Data Model"  then "Reference" / "Data Source" and chose my ZCDS_C_TREE_STRUCTURE. Icreated the runtime objects and redefined the method "define" in my *MPC_EXT class with the following code:


METHOD define.
  super->define( ).

  DATA: lr_entity    TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
        lr_property  TYPE REF TO /iwbep/if_mgw_odata_property,
        lr_annotation TYPE REF TO /iwbep/if_mgw_odata_annotation.

  lr_entity = model->get_entity_type( iv_entity_name = 'ZCDS_C_TREE_STRUCTUREType' ).
  IF lr_entity IS BOUND.

    " 1. id als Knoten-ID
    lr_property = lr_entity->get_property( iv_property_name = 'id' ).
    lr_annotation = lr_property->/iwbep/if_mgw_odata_annotatabl~create_annotation(
                        iv_annotation_namespace = /iwbep/if_mgw_med_odata_types=>gc_sap_namespace ).
    lr_annotation->add(
        iv_key = /iwbep/if_ana_odata_types=>gcs_ana_odata_annotation_key-hierarchy_node_for
        iv_value = 'id' ).

    " 2. RELATKEY als Parent Node
    lr_property = lr_entity->get_property( iv_property_name = 'parentid' ).
    lr_annotation = lr_property->/iwbep/if_mgw_odata_annotatabl~create_annotation(
                        iv_annotation_namespace = /iwbep/if_mgw_med_odata_types=>gc_sap_namespace ).
    lr_annotation->add(
        iv_key = /iwbep/if_ana_odata_types=>gcs_ana_odata_annotation_key-hierarchy_parent_node_for
        iv_value = 'id' ).

    " 3. SeqNo als Hierarchieebene
    lr_property = lr_entity->get_property( iv_property_name = 'hierlevel' ).
    lr_annotation = lr_property->/iwbep/if_mgw_odata_annotatabl~create_annotation(
                        iv_annotation_namespace = /iwbep/if_mgw_med_odata_types=>gc_sap_namespace ).
    lr_annotation->add(
        iv_key = /iwbep/if_ana_odata_types=>gcs_ana_odata_annotation_key-hierarchy_level_for
        iv_value = 'id' ).

    " 4. drill_state als Drill-Down-Zustand
    lr_property = lr_entity->get_property( iv_property_name = 'drilldownstate' ).
    lr_annotation = lr_property->/iwbep/if_mgw_odata_annotatabl~create_annotation(
                        iv_annotation_namespace = /iwbep/if_mgw_med_odata_types=>gc_sap_namespace ).
    lr_annotation->add(
        iv_key = /iwbep/if_ana_odata_types=>gcs_ana_odata_annotation_key-hierarchy_drill_state_for
        iv_value = 'id' ).

  ENDIF.
ENDMETHOD.

If I create then the Responsive Table in the BAS, it shows me my data correctly. When I change to type "TreeTable", it shows me "No data found".

What am I doing wrong?

Thanks and best regards
Thomas

@MR_srinivas 
@SumitKundu 
@jmalla 

Accepted Solutions (0)

Answers (0)