Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create hierarchy CDS view?

former_member306214
Discoverer
0 Kudos

Hi experts,

I'm trying to create A very simple hierarchy without hierarchy directory

My source code is as follows. I try to activate these source at the same time, but these got errors.

Do you have any idea for these errors?

Error:

Basis object ZGL_HIER does not exist or is not active

SAP object VIEW GLHIERV cannot be assigned to package XXXX

@AbapCatalog.sqlViewName: 'GLHIERV'
@AbapCatalog.compiler.compareFilter: true
@EndUserText.label: 'ZGL_HIER'
@ObjectModel:{dataCategory: #HIERARCHY}
@Hierarchy.parentChild.name: 'HIER1'
@Hierarchy.parentChild.label: 'GL HIER1'
@Hierarchy.parentChild: 
{ recurse: {parent: 'ParentNode', child: 'ChildNode'},
siblingsOrder: { by:'ParentNode', direction: #DESC},
orphanedNode.handling: #ROOT_NODES
}
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view ZGL_HIER as select from zzglhier1
association[0..*] to ZGL_COUNTRY as _ZGL_COUNTRY on $projection.ChildNode=_ZGL_COUNTRY.country
{
    key zparentnode as ParentNode,
    @ObjectModel.foreignKey.association: '_ZGL_COUNTRY'
    key zchildnode as ChildNode,
    _ZGL_COUNTRY
}

@AbapCatalog.sqlViewName: 'ZGL_COUNTRYV'
@AbapCatalog.compiler.compareFilter: true
@EndUserText.label: 'ZGL_COUNTRY'
@Analytics.dataCategory: #DIMENSION
@ObjectModel.representativeKey: 'Country'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view ZGL_COUNTRY as select from zzglcountry
association[0..*] to ZGL_HIER as _GLCOUNTRY_Hier1 on $projection.countory = _GLCOUNTRY_Hier1.ChildNode
{
    @ObjectModel.Hierarchy.association: '_GLCOUNTRY_Hier1'
    @EndUserText.label: 'Country'
    key zzglcountry.zglcountry as country,
    _GLCOUNTRY_Hier1
}

Regards,

Arisa

1 REPLY 1

stefan_unnebrink
Employee
Employee

Dear Arisa,

the definition is almost correct.There is just a little typo in document ZGL_COUNTRY: association[0..*]to ZGL_HIER as _GLCOUNTRY_Hier1 on $projection.countory = _GLCOUNTRY_Hier1.ChildNode

I suggest that you at first uncomment the hierarchy assocation from ZGL_COUNTRY, then activate this, after that activate the hierarchy view and at last add the hierarchy assocation again and activate ZGL_COUNTRY again. With this you get better control of the errors.

Despite this the hierarchy definition is okay. Notice that in your case also all nodes of the hierarchy have to be countries (here it means these have to be part of ZGL_COUNTRY).

Only the siblingsOrder is not 100% accurate. It describes how to sort the nodes, but it doesn't describe how to sort the leaves. Maybe the default sorting is okay for you.

Regards,

Stefan