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

Issue with Hierarchy CDS View

Rufs123
Discoverer
0 Kudos
1,173

Hi 

I have created a CDS view with Hierarchy Node, But I get the below error when trying to activate the CDS view. 

Error - Annotation 'Hierarchy.parentChild' must be an array type 

Rufs123_0-1740130682857.png

@EndUserText.label: 'Generic Hierarchy Node'

@ObjectModel.representativeKey: 'HierarchyNode'

@ObjectModel: { dataCategory: #HIERARCHY }

@vdm.viewType: #BASIC

@Hierarchy.parentChild:

{ recurse: { parent: 'ParentNode', child: 'HierarchyNode' },

siblingsOrder: { by: 'HierarchyNodeSequence', direction: 'ASC' },

directory: '_Hierarchy'

}

 

@AccessControl.authorizationCheck: #CHECK

@Metadata.ignorePropagatedAnnotations:true

 

@ObjectModel.modelingPattern: #ANALYTICAL_DIMENSION

@ObjectModel.supportedCapabilities: [ #CDS_MODELING_DATA_SOURCE, #CDS_MODELING_ASSOCIATION_TARGET, #ANALYTICAL_DIMENSION, #EXTRACTION_DATA_SOURCE]

 

@ObjectModel.usageType.serviceQuality: #A

@ObjectModel.usageType.sizeCategory: #XL

@ObjectModel.usageType.dataClass: #MASTER

 

@analytics.dataExtraction.enabled: true

 

define view entity ZCDSI_DSP_HIERNODE

as select from hrrp_node_n

 

 

association [0..*] to ZCDSI_DSP_HIERNODETEXT as _Text on $projection.Hierarchy = _Text.Hierarchy

and $projection.HierarchyNode = _Text.HierarchyNode

 

association [1..1] to ZCDSI_DSP_HIER as _Hierarchy on $projection.Hierarchy = _Hierarchy.Hierarchy

and $projection.ValidityEndDate = _Hierarchy.ValidityEndDate //Reviewed

 

{

 

@Consumption.filter: {mandatory : true, selectionType : #SINGLE, multipleSelections : false }

@ObjectModel.foreignKey.association: '_Hierarchy'

key cast(hrrp_node_n.hryid as fis_hryid_prctr preserving type ) as Hierarchy,

@ObjectModel.text.association: '_Text'

key hrrp_node_n.hrynode as HierarchyNode,

@Semantics.businessDate.to: true

@Consumption.filter: {mandatory : true, selectionType : #SINGLE, multipleSelections : false }

key cast(hrrp_node_n.hryvalto as fis_datbi preserving type ) as ValidityEndDate,

hrrp_node_n.parnode as ParentNode,

@vdm.lifecycle.status: #DEPRECATED

cast( '000000000000001' as hryversn ) as HierarchyVersion,

@Semantics.businessDate.from: true

cast(hrrp_node_n.hryvalfrom as fis_datab preserving type ) as ValidityStartDate,

@vdm.lifecycle.status: #DEPRECATED

@vdm.lifecycle.successor: 'HierarchyNodeSequence'

concat(hrrp_node_n.hryseqnbr, hrrp_node_n.hrynode) as SequenceNumber, // do not use any longer, use HierarchyNodeSequence

hrrp_node_n.hryseqnbr as HierarchyNodeSequence,

hrrp_node_n.hrylevel as HierarchyNodeLevel,

hrrp_node_n.nodetype as NodeType,

hrrp_node_n.nodevalue as HierarchyNodeVal,

 

_Text,

_Hierarchy

 

}

where

hrrp_node_n.nodetype <> 'D'

and hrrp_node_n.hrytyp = '0000';

 



Thanks

Accepted Solutions (0)

Answers (2)

Answers (2)

umasaral
Contributor
0 Kudos

The error message "Annotation 'Hierarchy.parentChild' must be an array type" suggests that the annotation @Hierarchy.parentChild is incorrectly formatted.
In CDS views, annotations that expect an array should be enclosed in square brackets [].

Issue in Your Code:Currently, your annotation is written as:

@Hierarchy.parentChild: {
recurse: { parent: 'ParentNode', child: 'HierarchyNode' },
siblingsOrder: { by: 'HierarchyNodeSequence', direction: 'ASC' },
directory: '_Hierarchy'
}
This is incorrect because @Hierarchy.parentChild expects an array of structures, not a single structure.

Corrected Code:

Modify the annotation to wrap the structure inside square brackets []:
@Hierarchy.parentChild: [
{
recurse: { parent: 'ParentNode', child: 'HierarchyNode' },
siblingsOrder: { by: 'HierarchyNodeSequence', direction: 'ASC' },
directory: '_Hierarchy'
}
]
Why This Works?
The @Hierarchy.parentChild annotation expects an array (i.e., multiple hierarchy definitions can be provided).
The corrected version ensures that the value is inside a list ([]), making it syntactically correct.

Next Steps:
Update the annotation as shown above.
Save and activate the CDS view.
If any further issues arise, check related annotations and ensure all hierarchy-related annotations align correctly.Let me know if you need further clarifications

umasaral
Contributor
0 Kudos

The error "Annotation 'Hierarchy.parentChild' must be an array type" occurs because the annotation @Hierarchy.parentChild expects an array format,
but it may have been declared incorrectly in your CDS view.

Correct Syntax for a Hierarchy CDS View
Make sure that your CDS view follows the correct syntax for defining a hierarchy. Below is the correct format:
----------abap
@AbapCatalog.sqlViewName: 'ZCDS_HIERARCHY'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS View with Hierarchy Node'
@Hierarchy.root: 'ROOT_NODE'
@Hierarchy.parentChild: [{ parent: 'PARENT_NODE', child: 'CHILD_NODE' }]
@Hierarchy.level: 'HIER_LEVEL'
@Hierarchy.ancestors: [{ ancestor: 'ANCESTOR_NODE', child: 'CHILD_NODE' }]
define view ZCDS_HIERARCHY as select from <your_table>
{
key node_id as CHILD_NODE,
parent_id as PARENT_NODE,
hierarchy_level as HIER_LEVEL,
ancestor_id as ANCESTOR_NODE,
node_name
}

Key Fixes:
1. @Hierarchy.parentChild must be an array
- Use `[{ parent: 'PARENT_NODE', child: 'CHILD_NODE' }]`
- Incorrect: `@Hierarchy.parentChild: { parent: 'PARENT_NODE', child: 'CHILD_NODE' }` (missing array brackets `[]`)

2. Ensure Parent-Child Fields Exist
- `PARENT_NODE` and `CHILD_NODE` should be actual fields in your table.

3. Optional Annotations:
- Use `@Hierarchy.root` for defining the root node.
- `@Hierarchy.ancestors` can be used if needed.

Next Steps:
- Try correcting your CDS view based on the syntax above.
- If the issue persists, share your full CDS view so I can check it for further errors.

Rufs123
Discoverer
0 Kudos
Added the FULL Code . .can you check