cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the level number of the Hierarchy table

Former Member
0 Kudos

Dear All,

Could you please give me some support about the following issue:

1. How to get the level number of the Hierarchy table if you know the record belong to Leaf 2 or Leaf 1.

Root (Level 0)

|______Leaf 1 (Level 1)

|_______Leaf 2 (Level 2)

Thanks and Regards,

Edited by: Zhiqiang Liu on Nov 4, 2008 8:11 AM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Pavel Kolotey,

Could you please check my codes:

		RetrieveHierAncestorsCommand  cmd = new RetrieveHierAncestorsCommand(context);
		cmd.setChildNode(channels[1].getId());
		cmd.execute();
		RecordResultSet set = cmd.getAncestors();
		System.out.println("set.getCount():"+set.getCount());

// System.out results

channels[0].getId():R8

Error message:

java.lang.NullPointerException: The result definition is not an optional parameter.

at com.sap.mdm.data.commands.AbstractRetrieveLimitedRecordsCommand.execute(AbstractRetrieveLimitedRecordsCommand.java:128)

at com.sap.mdm.data.commands.RetrieveHierAncestorsCommand.execute(RetrieveHierAncestorsCommand.java:114)

at com.sap.xedm.apple.AppleHierarchy.SearchElement(AppleHierarchy.java:284)

at com.sap.xedm.apple.AppleHierarchy.main(AppleHierarchy.java:322)

Exception in thread "main"

Former Member
0 Kudos

Really, you also need to set result definition for ancestors records.

Try this way:


RetrieveHierAncestorsCommand  cmd = new RetrieveHierAncestorsCommand(context);
cmd.setChildNode(channels[1].getId());

// Creating and setting empty result definition
final ResultDefinition rsd = new ResultDefinition(tableId); // TableId of the hierarchy table
cmd.setResultDefinition(rsd);

cmd.execute();
RecordResultSet set = cmd.getAncestors();
System.out.println("set.getCount():"+set.getCount());

Answers (5)

Answers (5)

Former Member
0 Kudos

It works well.

Thank you for your kind support.

Thanks and Regards

Zhiqiang

Former Member
0 Kudos

Hello Pavel Kolotey,

I checked the API and found that only 4 methods of the Class RetrieveHierAncestorsCommand.

1. public RecordId getChildNode()

2. public void setChildNode(RecordId childNodeId)

3. public RecordResultSet getAncestors()

4. public void execute() throws CommandException

Could you please give me more solutions?

Edited by: Zhiqiang Liu on Nov 5, 2008 8:00 AM

Former Member
0 Kudos

Hello, Zhiqiang Liu.

Let's consider an example.

You have a RecordId of a hierarchy record in variable recordId, and you need to know level of this record in the hierarchy.


final RetrieveHierAncestorsCommand cmd = new RetrieveHierAncestorsCommand(...); // use suitable constructor
cmd.setChildNode(recordId);
cmd.execute(); // CommandException can occur here
final int level = cmd.getAncestors().getCount(); // the level you need to know

Former Member
0 Kudos

Hello, Zhiqiang Liu.

I think you can execute RetrieveHierAncestorsCommand on RecordId of your hierarchy record. The count of items in it's result set will be equal to record level.

Former Member
0 Kudos

The version is MDM 5.5.63.60 SP06 Patch03 Hotfix02 - 32Bit.

Thanks

Former Member
0 Kudos

Hi

Hierarchy

1) You can have lookup for main Table for Hierarchy.

2) You can maintain it ECC.

There are many ways to handle if you tell which version of SAP MDM you want to maintain

And what are other system according to that you can maintain Hierarchy .

Thanks

Satnam