Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

People, Have never done hierarc

Status
Not open for further replies.

IMAUser

Technical User
May 28, 2003
121
CH
People,

Have never done hierarchial trees, but now I have a requirement. And for the life of it I cant figure out how to get it done. Perhaps my understanding is not very good abt trees. Anywa the problem is:
I have a set of customers in a CUSTOMER table and a set of orders ina ORDER table. I need to show the cust_id as the parent and the Order_id as the children in a Tree. Any suggestions how can I acheive this.

TIA
 
Are you looking at using forms to do this? There are tree items built into forms 6 and above, and you can populate them quite easily from data in a record group.
 
Yes I m looking to do this using Form s6i.
But have absolutely no clue how to get it working, have looked thru the manuals, and yes they do talk abt populating the tree using record groups etc. But I dont understand if I have to write one query or more queries to acheive this.
 
You could populate a record group using a nested SQL loop

[tt]lcount := 0;
--
FOR c1 IN (SELECT * FROM customer)
LOOP
Set_Group_Number_Cell(<column>,lcount,1); -- state
Set_Group_Number_Cell(<column>,lcount,1); -- level
Set_Group_Char_Cell(<column>,lcount,c1.cust_id); -- label
Set_Group_Char_Cell(<column>,lcount,NULL); -- icon
Set_Group_Char_Cell(<column>,lcount,c1.cust_id); -- value
--
lcount := lcount + 1;
--
FOR c2 IN (SELECT * FROM ORDER
WHERE cust_id = c1.cust_id)
LOOP
Set_Group_Number_Cell(<column>,lcount,1);
Set_Group_Number_Cell(<column>,lcount,2);
Set_Group_Char_Cell(<column>,lcount,c2.order_id);
Set_Group_Char_Cell(<column>,lcount,NULL);
Set_Group_Char_Cell(<column>,lcount,c2.order_id);
--
lcount := lcount + 1;
END LOOP;
END LOOP;[/tt]

Then you would build your tree from the resultant record group. Obviously you will need to play about with the above SQL code a bit.

You could do it with a single SQL loop, ordered by order_id within cust_id, but you would have to watch for changes in the cust_id. This would be a break report of sorts.
 
Thanks for your efforts lewisp, much appreciated. I can build the record group in the object navigator itself. So I dont need to do the looping etc. But once I have the record group ( and the data in the record group) how does forms know what to do with that data. I did create a record group and have written a trigger to populate the tree ( Used the example in Help ) , but nothing happens. It just stays as it is. So I m wondering there is some fundamental error in the way I m trying to populate the tree. Can you tell me, what shld be the trigger to do this.

Thanks ...
 
I assume you have the records in the record group in *exactly* the right order, otherwise the tree will not work. The reason I used a loop is because I cant see a way of generating the data in the right order.

Your record group must consist of 5 columns, 2 number and 3 char (see my example above), also in the right order.

If you want to display a tree like this:

[tt]+-Cust1
| |
| +-Order1
| +-Order2
|
+-Cust2
| |
| |-Order3
.
.
etc[/tt]

Your data will need to be structured like this:

[tt]1,1,'Cust1',NULL,'Cust1'
1,2,'Order1',NULL,'Order1'
1,2,'Order2',NULL,'Order2'
1,1,'Cust2',NULL,'Cust2'
1,2,'Order3',NULL,'Order3'[/tt]
 
Also I should ask, are you using

[tt]FTREE.POPULATE_TREE('block.tree');[/tt]

in your form startup code?
 
Thanks lewisp. I didnt realise I had to create the record group with the hierarchy built in.
I was thinking more in terms of a master detail form where you an specify the join condition. And I was wondering what was the way to join two record groups. My whole understanding of the population of trees was fundamentally incorrect.
But yes this definitely helps. And yes I m using FTREE.populate_tree.

Will let you know how it goes, I m off the issue for the moment. Thanks again.
 
Dear lewisp,

Could you plz define what would be the query to define the record group for?
and how to embed the coding with tree object to get result?
and how to mension column name in &quot;set_group_number_cell&quot;?

thanx in advance.

adeel.
 
For the record group:

[tt]DECLARE
l_rg RECORDGROUP;
l_stat GROUPCOLUMN;
l_lev GROUPCOLUMN;
l_lab GROUPCOLUMN;
l_icon GROUPCOLUMN;
l_val GROUPCOLUMN;
BEGIN
l_rg := Create_Group('TREE1');
l_stat := Add_Group_Column(l_rg,'STATE',NUMBER_COLUMN);
l_lev := Add_Group_Column(l_rg,'LEVEL',NUMBER_COLUMN);
l_lab := Add_Group_Column(l_rg,'LABEL',CHAR_COLUMN,100);
l_icon := Add_Group_Column(l_rg,'ICON',CHAR_COLUMN,10);
l_val := Add_Group_Column(l_rg,'VALUE',CHAR_COLUMN,100);
.
.
etc.[/tt]

To set the column:

[tt]Set_Group_Number_Cell(l_stat,<index>,1);[/tt]

or

[tt]Set_Group_Number_Cell('TREE1.STATUS',<index>,1);[/tt]


...and to use this recordgroup for the tree:

[tt]Ftree.Set_Tree_Property('<block.tree>',FTREE.RECORD_GROUP,l_rg);[/tt]
 
Dear lewisp,

I have got the results successfully, viewing in tree.

But when i click on any node to expand or collapse, it works with displaying an error.
[Microsoft Visual C++ Runtime Liabrary]
Assertion failed!
...
....


why it is showing this error message?

thanx in advance

adeel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top