Hierarchy or Tree structure Query

Hi,
I have to display each level total amount from the below tables
We have two tables.
Table 1 having the all level columns and table 2 having amount for each level
Below are the table scripts and sample data
CREATE TABLE LEVEL_TABLE
LEVEL1 VARCHAR2(50),
LEVEL2 VARCHAR2(50),
LEVEL3 VARCHAR2(50),
LEVEL4 VARCHAR2(50),
LEVEL5 VARCHAR2(50)
CREATE TABLE LEVEL_TABLE_AMT
AMT NUMBER(15),
LEVEL_VALUE VARCHAR2(50)
INSERT INTO LEVEL_TABLE VALUES ('LEVEL_1', 'LEVEL_1.1', 'LEVEL_1.1.1', 'LEVEL_1.1.1.1', 'LEVEL_1.1.1.1.1');
INSERT INTO LEVEL_TABLE VALUES ('LEVEL_1', 'LEVEL_1.1', 'LEVEL_1.1.1', 'LEVEL_1.1.1.1', 'LEVEL_1.1.1.1.2');
INSERT INTO LEVEL_TABLE VALUES ('LEVEL_1', 'LEVEL_1.1', 'LEVEL_1.1.2', 'LEVEL_1.1.2.1', null);
INSERT INTO LEVEL_TABLE VALUES ('LEVEL_1', 'LEVEL_1.1', 'LEVEL_1.1.2', 'LEVEL_1.1.2.2', null);
INSERT INTO LEVEL_TABLE VALUES ('LEVEL_1', 'LEVEL_1.2', 'LEVEL_1.2.1', null, null);
INSERT INTO LEVEL_TABLE VALUES ('LEVEL_1', 'LEVEL_1.2', 'LEVEL_1.2.2', 'LEVEL_1.2.2.1', null);
INSERT INTO LEVEL_TABLE VALUES ('LEVEL_1', 'LEVEL_1.3', 'LEVEL_1.3.1', 'LEVEL_1.3.1.1', null);
INSERT INTO LEVEL_TABLE VALUES ('LEVEL_1', 'LEVEL_1.3', 'LEVEL_1.3.1', 'LEVEL_1.3.1.2', null);
INSERT INTO LEVEL_TABLE_AMT VALUES (100, 'LEVEL_1.1.1.1.1');
INSERT INTO LEVEL_TABLE_AMT VALUES (200, 'LEVEL_1.1.1.1.2');
INSERT INTO LEVEL_TABLE_AMT VALUES (100, 'LEVEL_1.1.2.1');
INSERT INTO LEVEL_TABLE_AMT VALUES (300, 'LEVEL_1.1.2.2');
INSERT INTO LEVEL_TABLE_AMT VALUES (100, 'LEVEL_1.2.1');
INSERT INTO LEVEL_TABLE_AMT VALUES (400, 'LEVEL_1.2.2.1');
INSERT INTO LEVEL_TABLE_AMT VALUES (100, 'LEVEL_1.3.1.1');
INSERT INTO LEVEL_TABLE_AMT VALUES (200, 'LEVEL_1.3.1.2');
COMMIT;
Output of the Quey should be as below
LEVEL_1(Amt)
-- LEVEL_1.1(Amt)
-- LEVEL_1.1.1(Amt)
-- LEVEL_1.1.1.1(Amt)
-- LEVEL_1.1.1.1.1(Amt)
-- LEVEL_1.1.1.1.2(Amt)
-- LEVEL_1.1.2(Amt)
-- LEVEL_1.1.2.1(Amt)
-- LEVEL_1.1.2.2(Amt)
-- LEVEL_1.2(Amt)
-- LEVEL_1.2.1(Amt)
-- LEVEL_1.2.2(Amt)
-- LEVEL_1.2.2.1(Amt)
-- LEVEL_1.3(Amt)
-- LEVEL_1.3.1(Amt)
-- LEVEL_1.3.1.1(Amt)
-- LEVEL_1.3.1.2(Amt)
Please check and help me to display the query.
Thanks,
Pradeep.

Seems level_table is not needed
with
level_table_amt as
(select 100 amt, 'LEVEL_1.1.1.1.1' level_value from dual union all
select 200, 'LEVEL_1.1.1.1.2' from dual union all
select 100, 'LEVEL_1.1.2.1' from dual union all
select 300, 'LEVEL_1.1.2.2' from dual union all
select 100, 'LEVEL_1.2.1' from dual union all
select 400, 'LEVEL_1.2.2.1' from dual union all
select 100, 'LEVEL_1.3.1.1' from dual union all
select 200, 'LEVEL_1.3.1.2' from dual
ancestors(l,amt,list) as
  (select 1,amt,substr(level_value,7) from level_table_amt
   union all
   select l + 1,amt,substr(list,1,instr(list,'.',-1,1) - 1)
     from ancestors
    where instr(list,'.') > 0
select 'LEVEL_' || list,sum(amt) amt
  from ancestors
group by list
order by listRegards
Etbin
Edited by: Etbin on 8.3.2012 14:26
A quick and dirty hierarhical approach
with
level_table_amt as
(select 100 amt, 'LEVEL_1.1.1.1.1' level_value from dual union all
select 200, 'LEVEL_1.1.1.1.2' from dual union all
select 100, 'LEVEL_1.1.2.1' from dual union all
select 300, 'LEVEL_1.1.2.2' from dual union all
select 100, 'LEVEL_1.2.1' from dual union all
select 400, 'LEVEL_1.2.2.1' from dual union all
select 100, 'LEVEL_1.3.1.1' from dual union all
select 200, 'LEVEL_1.3.1.2' from dual
select level_value,amount
  from (select 'LEVEL_' || ltrim(ancestor,'.') level_value,sum(amt) amount
          from (select distinct
                       amt,
                       level_value,
                       substr(level_value,1,instr(level_value,'.',-1,level) - 1) ancestor
                  from (select amt,'.' || substr(level_value,7) level_value
                          from level_table_amt
                connect by level < length(level_value) - length(replace(level_value,'.',''))
         group by ancestor
        union all
        select level_value,amt
          from level_table_amt
order by level_value

Similar Messages

  • Complex Tree Structure Query

    Hi,
    I have a table which contains the hierarchial data upto 4 levels. I needed to have the information of all the four levels in a row, so I created 3 tree structured views and one another view using the tree structured views as below
    --To get the great grand parent id for the children*
    CREATE OR REPLACE VIEW VR_PO_TREE AS
    SELECT LEVEL pathlength,
    connect_by_root partner_organization_id root_po,
    partner_organization_id,
    partner_common_name,
    partner_organization_type
    FROM partner_organization po
    START WITH po.org_entity_above_id IS NULL
    CONNECT BY PRIOR po.partner_organization_id = po.org_entity_above_id
    ORDER BY po.partner_organization_id;
    -- level 2 (grant parent) id
    CREATE OR REPLACE VIEW VR_PO_AREA_TR AS
    SELECT LEVEL pathlength,
    connect_by_root partner_organization_id root_po,
    partner_organization_id,
    partner_common_name,
    partner_organization_type
    FROM partner_organization vcpo
    START WITH vco.partner_organization_type = 'AREA'
    CONNECT BY PRIOR vcpo.partner_organization_id = vcpo.org_entity_above_id
    ORDER BY vcpo.partner_organization_id;
    --level 3 (parent) id*
    CREATE OR REPLACE VIEW VR_PO_REGION_TREE AS
    SELECT LEVEL pathlength,
    connect_by_root partner_organization_id root_po,
    vcpo.partner_organization_id,
    vcpo.partner_common_name,
    vcpo.partner_type
    FROM partner_organization vcpo
    START WITH vcpo.partner_organization_type = 'REGION'
    CONNECT BY PRIOR vcpo.partner_organization_id = vcpo.org_entity_above_id
    ORDER BY vcpo.partner_organization_id;
    ---and finally created a view to have all the levels in a single row
    CREATE OR REPLACE VIEW VR_PO_ALL_TREE AS
    SELECT pot.pathlength,
    po.partner_organization_id,
    po.partner_common_name,
    pot.root_po int_partner_org_id,
    pot.intl_po_name int_partner_common_name,
    vpat.root_po area_partner_org_id,
    vpat.area_po_name area_partner_common_name,
    vprt.root_po region_partner_org_id,
    vprt.region_po_name region_partner_common_name
    FROM partner_organization po
    JOIN vr_po_tree pot
    ON pot.partner_organization_id = po.partner_organization_id
    LEFT outer JOIN vr_po_area_tr vpat
    ON vpat.partner_organization_id = po.partner_organization_id
    LEFT OUTER JOIN vr_po_region_tree vprt
    ON vprt.partner_organization_id = po.partner_organization_id;
    All the views are working fine, very fast, giving the expected output.
    if we make a join to the view vr_po_all_tree in a query that also works fine. However, if we make an outer join to a query that has the join to vr_po_all_tree, Oracle throws an internal error - Ora-00600 internal error codes, arguments [qrctce1], [0],[0],.....
    Is the view vr_po_all_tree is cause for this problem?, in such a case can any one help me to rewrite the view with a simple query to give the same results?
    Thanks in advance.
    Nattu
    Edited by: Nattu on Nov 26, 2009 8:25 PM
    Edited by: Nattu on Nov 27, 2009 11:48 AM
    Edited by: Nattu on Nov 27, 2009 11:55 AM

    Hi,
    if we make a join to the view vr_po_all_tree in a query that also works fine. However, if we make an outer join to a query that has the join to vr_po_all_tree, Oracle throws an internal error - Ora-00600 internal error codes, arguments [qrctce1], [0],[0],.....
    Is the view vr_po_all_tree is cause for this problem?As Sven said, ORA-00600 is the sign of some low-level problem, and you should seek a solution from Oracle support. Your views are not the cause of this problem; most likely, the views trigger something that would not be a problem except for a installatin problem or maybe a bug.
    We can try to find a work-around for you, but don't ignore the problem.
    in such a case can any one help me to rewrite the view with a simple query to give the same results?It seems very likely that you could do something that didn't involve so many CONNECT BYs and outer joins.
    Post some sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
    Simplify as much as possible. For example, in the first view you say:
    CREATE OR REPLACE VIEW VR_PO_TREE AS
    SELECT LEVEL pathlength,
    connect_by_root partner_organization_id root_po,
    connect_by_root partner_common_name intl_po_name,
    connect_by_root is_wbti is_wbti,
    connect_by_root is_sil_int is_sil_int,
    connect_by_root organization_entity_code int_org_entity_code,
    org_entity_above_id, partner_organization_id,
    partner_organization_type,
    sys_connect_by_path(partner_organization_id, '\') po_path_id,
    sys_connect_by_path(partner_common_name, '\') po_path_name
    FROM ...That is, you're selecting 1 pseudo-column (LEVEL), 4 CONNECT_BY_ROOTs, 3 plain columns, and 2 SYS_CONNECT_BY_PATHs.
    Can you post a problem with just one of each: 1 pseudo-column, 1 CONNECT_BY_ROOT, 1 plain column, and 1 SYS_CONNECT_BY_PATH?  Adding the others later should be easy.
    Any information you can give about the data would be helpful.
    In particular,
    (a) Can org_entity_above be NULL on the same row where partner_organization_type is 'AREA' or 'REGION'?
    (b) How many ancestors with partner_organization_type = 'AREA' Can a node have? 1? No more than 1?  1 or more? 0 or more?
    (c) Same for 'REGION'.  How many ancestors with partner_organization_type = 'REGION' Can a node have? 1? No more than 1?  1 or more? 0 or more?
    (d) Can a node with partner_organization_type = 'REGION' be the ancestor of a row with partner_organization_type = 'AREA'?
    (e) Other way around: can a node with partner_organization_type = 'AREA' be the ancestor of a row with partner_organization_type = 'REGION'?
    Some of these questions may seem silly to you, because you know the table and the data so well.  I don't, so you'll have to explain things.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Urgent Help:Tree structured query

    Hi,
    My requirement is as follows..
    I have two tables let's say A and B
    Table A has two fileds ID and PARENT_ID
    ID is a primary key and Parent_id is a foreign key to the same tables "ID" field(i.e, parent_id references a.id)
    Table B has 2 fields : status and id
    where ID is a foreign key to table A.id(B.id references A.ID)
    The data in those two tables looks like this
    A
    ID PARENT_ID
    1 2
    2 3
    3 4
    4
    5 6
    6 7
    7
    Table B has ..
    Status id
    Approved 1
    Approved 2
    Now I would like to select all the Approved Ids and all parent_IDs
    So i should get the following result
    id
    1
    2
    3
    4
    Can somebody help me write this query.. this is Kinda urgent Please.
    Thank you

    sql>select * from a;
           ID PARENT_ID
            1         2
            2         3
            3         4
            4
            5         6
            6         7
            7
    7 rows selected.
    sql>select * from b;
    STATUS                                ID
    Approved                               1
    Approved                               2
    2 rows selected.
    sql>select distinct id
      2    from a
      3   start with id in (select id
      4                       from b
      5                      where status = 'Approved')
      6   connect by prior parent_id = id;
           ID
            1
            2
            3
            4
    4 rows selected.

  • How to use ONE query to find out tree structure?

    ID------------upperID----------Name------------------------isFolder
    1------------ 0---------- Folder
    1------------------------------------1
    2------------ 1------------ Folder 1- Sub
    Folder--------------------1
    3------------ 2------------
    Folder1-Item1-A--------------------------0
    4------------ 1------------ Folder 1- Sub
    Item-----------------------0
    Hi all, if I have a table like above to demonstrate the
    folders and item relationship. This structure allows the user to
    create unlimited folders and items.
    Now I would like to use one query to find out the tree
    structure of this table, how could I do the query.
    Any help on this will be highly appreciated!
    Thanks,
    ez

    Also, see this thread:
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=1&catid=7&threadid=12 55788&enterthread=y

  • Listing File Hierarchy in console using a Tree structure

    first off i'm a college student. i'm not that good at java... we got this CA in class and try as i might i just can't get my head around it
    i was wondering if someone who know a bit more about java then i do would point me in the right direction, were i'm going wrong in my code
    i have to list out sub-files and sub-directorys of a folder (i.e. C:/test) to console using tree structure
    like this
    startingdir
    dir1 //subfolder of startingdir
    dir11 //subfolder of dir1
    dir111 //subfolder of dir11
    dir12 //subfolder of dir1
    file1A // document on dir1
    dir2 //subfolder of startingdir
    Tree.java
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.ListIterator;
    import java.util.NoSuchElementException;
    import java.util.Deque;
    public class Tree<E> {
        // Each Tree object is an unordered tree whose
        // elements are arbitrary objects of type E.
        // This tree is represented by a reference to its root node (root), which
        // is null if the tree is empty. Each tree node contains a link to its
        // parent and a LinkedList of child nodes
        private Node root;
        //////////// Constructor ////////////
        public Tree () {
        // Construct a tree, initially empty.
            root = null;
        //////////// Accessors ////////////
        public boolean isEmpty () {
        // Return true is and only if this tree is empty.
             return (root == null);
        public Node root () {
        // Return the root node of this tree, or null if this tree is empty.
            return root;
        public Node parent (Node node) {
        // Return the parent of node in this tree, or null if node is the root node.
            return node.parent;
        public void makeRoot (E elem) {
        // Make this tree consist of just a root node containing element elem.
            root = new Node(elem);
        public Node addChild (Node node, E elem) {
        // Add a new node containing element elem as a child of node in this
        // tree. The new node has no children of its own. Return the node
        // just added.
            Node newChild = new Node(elem);
            newChild.parent = node;
            node.children.addLast(newChild);
            return newChild;
        public E element (Node node) {
             return node.getElement();
        //////////// Iterators ////////////
        public Iterator childrenIterator (Node node) {
            return node.children.iterator();
        public Iterator nodesPreOrder () {
        // Return an iterator that visits all nodes of this tree, with a pre-order
        // traversal.
            return new Tree.PreOrderIterator();
        //////////// Inner classes ////////////
        public class Node {
            // Each Tree.Node object is a  node of an
            // unordered tree, and contains a single element.
            // This tree node consists of an element (element),
            // a link to its parent
            // and a LinkedList of its children
            private E element;
            private Node parent;
            private LinkedList<Node> children;
            private Node (E elem) {
                // Construct a tree node, containing element elem, that has no
                // children and no parent.
                this.element = elem;
                this.parent = null;
                children = new LinkedList<Node>();
            public E getElement () {
            // Return the element contained in this node.
                return this.element;
            public String toString () {
            // Convert this tree node and all its children to a string.
                String children = "";
                // write code here to add all children
                return element.toString() + children;
            public void setElement (E elem) {
            // Change the element contained in this node to be elem.
                this.element = elem;
        public class PreOrderIterator implements Iterator {
            private Deque<Node> track; //Java recommends using Deque rather
            // than Stack. This is used to store sequence of nomempty subtrees still
            //to be visited
            private PreOrderIterator () {
                track = new LinkedList();
                if (root != null)
                    track.addFirst(root);
            public boolean hasNext () {
                return (! track.isEmpty());
            public E next () {
                Node place = track.removeFirst();
                //stack the children in reverse order
                if (!place.children.isEmpty()) {
                    int size = place.children.size(); //number of children
                    ListIterator<Node> lIter =
                            place.children.listIterator(size); //start iterator at last child
                    while (lIter.hasPrevious()) {
                        Node element = lIter.previous();
                        track.addFirst(element);
                return place.element;
            public void remove () {
                throw new UnsupportedOperationException();
        FileHierarchy.java
    import java.io.File;
    import java.util.Iterator;
    public class FileHierarchy {
        // Each FileHierarchy object describes a hierarchical collection of
        // documents and folders, in which a folder may contain any number of
        // documents and other folders. Within a given folder, all documents and
        // folders have different names.
        // This file hierarchy is represented by a tree, fileTree, whose elements
        // are Descriptor objects.
        private Tree fileTree;
        //////////// Constructor ////////////
        public FileHierarchy (String startingDir, int level) {
            // Construct a file hierarchy with level levels, starting at
            // startingDir
            // Can initially ignore level and construct as many levels as exist
            fileTree = new Tree();
            Descriptor descr = new Descriptor(startingDir, true);
            fileTree.makeRoot(descr);
            int currentLevel = 0;
            int maxLevel = level;
            addSubDirs(fileTree.root(), currentLevel, maxLevel);
        //////////// File hierarchy operations ////////////
        private void addSubDirs(Tree.Node currentNode, int currentLevel,
                int maxLevel) {
        // get name of directory in currentNode
        // then find its subdirectories (can add files later)
        // for each subdirectory:
        //    add it to children of currentNode - call addChild method of Tree
        //    call this method recursively on each child node representing a subdir
        // can initially ignore currentLevel and maxLevel   
            Descriptor descr = (Descriptor) currentNode.getElement();
            File f = new File(descr.name);
            File[] list = f.listFiles();
            for (int i = 0; i < list.length; ++i) {
                if (list.isDirectory()) {
    File[] listx = null;
    fileTree.addChild(currentNode, i);
    if (list[i].list().length != 0) {
    listx = list[1].listFiles();
    addSubDirs(currentNode,i,1);
    } else if (list[i].isFile()) {
    fileTree.addChild(currentNode, i);
    // The following code is sample code to illustrate how File class is
    // used to get a list of subdirectories from a starting directory
    // list now contains subdirs and files
    // contained in dir descr.name
    ////////// Inner class for document/folder descriptors. //////////
    private static class Descriptor {
    // Each Descriptor object describes a document or folder.
    private String name;
    private boolean isFolder;
    private Descriptor (String name, boolean isFolder) {
    this.name = name;
    this.isFolder = isFolder;
    FileHierarchyTest.javapublic class FileHierarchyTest {
    private static Tree fileTree;
    public static void main(String[] args) {
    FileHierarchy test = new FileHierarchy ("//test", 1);
    System.out.println(test.toString());

    Denis,
    Do you have [red hair|http://www.dennisthemenace.com/]? ;-)
    My advise with the tree structure is pretty short and sweet... make each node remember
    1. it's parent
    2. it's children
    That's how the file system (inode) actually works.
    <quote>
    The exact reasoning for designating these as "i" nodes is unsure. When asked, Unix pioneer Dennis Ritchie replied:[citation needed]
    In truth, I don't know either. It was just a term that we started to use. "Index" is my best guess, because of the
    slightly unusual file system structure that stored the access information of files as a flat array on the disk, with all
    the hierarchical directory information living aside from this. Thus the i-number is an index in this array, the
    i-node is the selected element of the array. (The "i-" notation was used in the 1st edition manual; its hyphen
    became gradually dropped).</quote>

  • Query for spesific children in a tree structure

    Hi,
    My data is organized in a tree structure.
    I need a sql statement that returns a parent that
    have a set of children corresponding to some demands.
    I provide a very simplified description of my data, but it covers my problem.
    Can anyone please help me write a select statement that gives me all featureids
    that have a GID attribute with children GNR=123 AND BNR=456?
    Regards
    gv
    create table attributetype( id number, name varchar2(8), parentid number );
    insert into attributetype( id, name ) values ( 1, 'GIDLIST' );
    insert into attributetype( id, name, parentid ) values ( 2, 'GID', 1 );
    insert into attributetype( id, name, parentid ) values( 3, 'GNR', 2 );
    insert into attributetype( id, name, parentid ) values ( 4, 'BNR', 2 );
    create table attribute( featureid number, id number, parentid number, atttypeid number, intvalue number );
    --attributes for feature1
    insert into attribute( featureid, id, parentid, atttypeid ) values( 1, 1, 0, 1 );
    insert into attribute( featureid, id, parentid, atttypeid ) values( 1, 2, 1, 2 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 1, 3, 2, 3, 123 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 1, 4, 2, 4, 456 );
    insert into attribute( featureid, id, parentid, atttypeid ) values( 1, 5, 1, 2 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 1, 6, 5, 3, 12 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 1, 7, 5, 4, 456 );
    --attributes for feature 2
    insert into attribute( featureid, id, parentid, atttypeid ) values( 2, 8, 0, 1 );
    insert into attribute( featureid, id, parentid, atttypeid ) values( 2, 9, 8, 2 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 2, 10, 9, 3, 678 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 2, 11, 9, 4, 456 );
    insert into attribute( featureid, id, parentid, atttypeid ) values( 2, 12, 8, 2 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 2, 13, 12, 3, 876 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 2, 14, 12, 4, 456 );
    commit;
    column name format a15
    select a.featureid featureid, lpad(' ', (level - 1) * 2) || b.name name, a.id attid, a.parentid parentid, a.intvalue
    from attribute a, attributetype b
    where a.atttypeid=b.id
    connect by prior a.id=a.parentid
    start with a.parentid=0;
    FEATUREID NAME ATTID PARENTID INTVALUE
    1 GIDLIST 1 0
    1 GID 2 1
    1 GNR 3 2 123
    1 BNR 4 2 456
    1 GID 5 1
    1 GNR 6 5 12
    1 BNR 7 5 456
    2 GIDLIST 8 0
    2 GID 12 8
    2 GNR 13 12 876
    2 BNR 14 12 456
    2 GID 9 8
    2 GNR 10 9 678
    2 BNR 11 9 456

    Hi,
    Thanks for providing the CREATE TABLE and INSERT statements; that helps a lot.
    You want featureids that meet three criteria:
    (1) there is a GID attribute
    (2) the GID attribute has a GNR child with intvalue=123
    (3) the GID attribute has a BNR child with intvalue=456
    Since you're looking for immediate children, not distant descendants, it's easiest to do this with a non-hierarrchical query that finds one of these criteria, and does EXISTS sub-queries to test for the other two.
    For example:
    WITH aat AS
    ( -- Begin aat: join of attribute and attributetype
         SELECT     a.featureid
         ,     a.id
         ,     a.parentid
         ,     a.intvalue
         ,     t.name
         FROM     attribute     a
         JOIN     attributetype     t     ON     a.atttypeid     = t.id
    ) -- End aat: join of attribute and attributetype
    SELECT DISTINCT     featureid
    FROM     aat     m     -- m for main
    WHERE     name     = 'GID'
    AND     EXISTS     (     -- Begin EXISTS sub-query for GNR=123
              SELECT     NULL
              FROM     aat
              WHERE     parentid     = m.id
              AND     name          = 'GNR'
              AND     intvalue     = 123
              )     -- End EXISTS sub-query for GNR=123
    AND     EXISTS     (     -- Begin EXISTS sub-query for BNR=456
              SELECT     NULL
              FROM     aat
              WHERE     parentid     = m.id
              AND     name          = 'BNR'
              AND     intvalue     = 456
              )     -- End EXISTS sub-query for BNR=456
    ;Alternatively, you could do a three-way self join, and skip the EXISTS sub-queries.
    If you were looking for GNR and BNR descendants, any number of levels below the same GID node, it's easy to modify the query above. Just re-write the EXISTS sub-queries to CONNECT BY queries that "START WITH parentid = m.id".
    It looks like this application will have a lot of use for a view like aat, above. If you don't already have a permanent view like that, you should create one.

  • How to create a form on a tree structured table

    Hi,
    I have a table that is designed to do a tree structure  like:
    Table Name: test
    Fields:
    ID
    ParentID
    Description
    I created a browser (IR) (page 1) that calls a form (page 2)
    The form has the editing fields and at the bottom layer I have a reports region where I display the children records using a query like:
    select * from test where ParentID = :P2_ID
    I need at the region level to add a button to call a form to edit the child record (which is the same table) and when done, to return to the form again but to the parent record.
    How can I do that successfully? Is there any example:?
    Thank you

    Maybe this can help:
    http://apex.oracle.com/pls/otn/f?p=31517:157
    using instead of trigger on a view.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • How can I create a Tree  Structure in java ??

    Hi,
    I want to create a tree structure(objects hierarchy) using java language. Is there any API method for this ?
    Can any one please give me a hint or suggestion how I can do this ??
    Thanks for the help in advance.

    Do you mean graphically?
    You can use a TreeSet or TreeMap if you just want to use tree structures.
    Kaj

  • How to populate Tree structure from BAPI while tree grows or shrinks

    Hi All
    Currently I am populating the tree structure from BAPI based on the HLevel (Hierarchy  Level) parameter, but when ever insertion and deletion happens in the tree at any level in the UI and at the same time i am updating these tree node values with HLevel value(example : 1 is first level , 2 is second level, 3 is third level etc)  updating successfully& correctly  into the BAPI, no issues.
    Once it is updated into the BAPI, next time when i refreshed the UI then i am not populating the tree structure correctly from BAPI with updated new nodes based on the HLevel. when tree struture grows or shrinks in the BAPI after updating into BAPI from UI then i am not populating the tree sturcture correctly based on the HLevel value from the BAPI.
    Please let me know any sample code how to populate tree structure correctly when tree structure grows or shrinks based on the HLevel value ( Hierarchy Level , for example : 1 is level , 2 is 2nd level , 3 is third level nodes etc)
    anybody helps in this regard with sample code on the populating tree tructure then it would be great help to me.
    Thanks in advance
    Regards
    Kalki Reddy
    Edited by: KalkiReddy on Nov 29, 2009 3:48 PM

    Bapi output node:
    Value     | Text     | HLevel
    01     | A     | 1               
    0101     | AA       | 2
    010101     | AAA     | 3
    01010B     | AAB     | 3
    0102     | AB     | 2
    02     | B     | 1
    0201     | BA        | 2
    This code is used to build the tree in wdDoInit method
         IE_T_CatalogueNode catalogueNode = wdContext.nodeE_T_Catalogue();
         int size = catalogueNode.size();
         ICatalogoElement level1elem = null;
         for (int i = 0; i < size; i ++)
              IE_T_CatalogueElement catalogueElem = catalogueNode.getE_T_CatalogueElementAt(i);
              if (catalogueElem.getLevel().equals("1"))
                   // 1 Livello
                   level1elem = wdContext.createCatalogoElement();
                   level1elem.setKATALOGART_CODE(catalogueElem.getKatalogart());
                   level1elem.setCODEGRUPPE_CODE(catalogueElem.getCodegruppe());
                   level1elem.setCODE(catalogueElem.getCode());
                   level1elem.setCODE_DESCR(catalogueElem.getKatalogart_Descr());
                   level1elem.setDESCR(catalogueElem.getKatalogart_Descr());
                   wdContext.nodeCatalogo().addElement(level1elem);
                   for (int j = i + 1; j < size; j ++)
                        IE_T_CatalogueElement catalogueElem2level =
                                                 catalogueNode.getE_T_CatalogueElementAt( j );
                        String level2 = catalogueElem2level.getLevel();
                        if (level2.equals("2"))
                             ICatalogoElement level2elem = level1elem.nodeChild().createCatalogoElement();
                             level2elem.setKATALOGART_CODE(catalogueElem2level.getKatalogart());
                             level2elem.setCODEGRUPPE_CODE(catalogueElem2level.getCodegruppe());
                             level2elem.setCODE(catalogueElem2level.getCode());
                             level2elem.setCODE_DESCR(catalogueElem2level.getCodegruppe_Descr());
                             level2elem.setDESCR(catalogueElem2level.getCodegruppe_Descr());
                             level1elem.nodeChild().addElement(level2elem);
                             for (int k = j + 1; k < size; k ++)
                                  IE_T_CatalogueElement catalogueElem3level =
                                                           catalogueNode.getE_T_CatalogueElementAt( k );
                                  String level3 = catalogueElem3level.getLevel();
                                  if (level3.equals("3"))
                                       ICatalogoElement level3elem = level2elem.nodeChild().createCatalogoElement();
                                       level3elem.setKATALOGART_CODE(catalogueElem3level.getKatalogart());
                                       level3elem.setCODEGRUPPE_CODE(catalogueElem3level.getCodegruppe());
                                       level3elem.setCODE(catalogueElem3level.getCode());
                                       level3elem.setCODE_DESCR(catalogueElem3level.getCode_Descr());
                                       level3elem.setDESCR(catalogueElem3level.getCode_Descr());
                                       level2elem.nodeChild().addElement(level3elem);
    Damiano

  • Hierarchial ALV  Tree Report.

    Hi!
    iam designing a module pool to get all the info of the idoc like status record control record etc.the 3 rd screen would be a hierarchial tree structure.All the data would be retrieved from Z tables.
    My requirement is on the left side of the pane the tree would contain 6 tables as nodes and these would be constant for all the idoc numbers.On the right side of the screen i would have to populate the complete data from these tables.
    When user clicks on the first table only that table data needs to appear.This would be only a display report.
    Plz tell me if this logic would work
    I will create the tree structure on the left side of the pane with all the 6 tables as default.I would also define a subscren on the right side and would call a table control for the respective tables along with the data populated in them.
    Now can i link the double click event of the tree ie the table name to populate the table control in the subscreen.
    Please provide suggestions.
    thanks
    kedar

    HI Kedar,
    What u r trying to do is going to work.
    Evn I tried to do the same, but since I ahve less knowledge in ALV class I couldnt do it.
    U can refer to DWDM, it is for demo programs...it has ALV tree method

  • Hiding hierarchy level in Report (Query Designer)

    Hallo Experts,
    I am working on a hierarchy structure. I use the activate Hierarchy Display in the Query Designer. I try to expand my query till level "2".
    But I actually want only the 2 level report and the 1st level should be hidden. Can anyone guide me how this can be done.
    Thanks in advance
    Santosh

    Hello Santosh,
    You can have Level 2 as an InfoObject that will be attached to 0MATERIAL as a navigational attribute. Then you can use this in your report and and create a condition on it.
    Thanks.
    With regards,
    Anand Kumar

  • WDA:  Tree structure in web dynpro for ABAP

    Hi,
    I am trying to build a tree structure with information something like the following:
    Country
    State
    City
    I used the UI Element "Tree" and I was successful in building it. The only problem is that it supports only one column in each row like name.
    I need multiple columns in each row like Name and population.
    1) Is there any solution for this using UI element "Tree" only?
    2)I checked that there is Table tree UI element, but I could not figure out how I could use it for hierarchial structure like that of my requirement? Can I use it? Is there any example application with hierarchial structure?
    3)For tree UI element, any node that is not directly below context node has to be non-singleton. It will lead to adverse performance. Is there any solution for this?
    Thanks in advance.
    Regards,
    Srini.

    Hi Srinivasa,
    In the context, please create a node DATA with the following fields:
    KEY type string
    PARENT type string
    LOCATION type string
    POPULATION type string (or "I" if you happen to have numbers only without a unit like "k" for "thousand").
    Then please create a table with a TreeByKeyTableColumn namde LOCATION and an additional TableColumn called POPULATION. Now please add a TextView cell editor to both and bind the text value of each of them to the attributes LOCATION and POPULATION of the context node DATA. Last step is to bind the attribtues rowKey and parentRowKey(?) to the KEY and the PARENT attributes. This concludes the design time part.
    Next step is to fill the node DATA with actual data. Just use a supply function and do it like this:
    First entry:
    KEY = 'WORLD'.
    PARENT = ''.
    LOCATION = 'World'.
    POPULATION = '4 billion'.
    Second entry:
    KEY = 'DE'.
    PARENT = 'WORLD'.
    LOCATION = 'Germany'.
    POPULATION = '80 million'.
    You should now see a table with a tree at the left column that looks like:
    <pre>
      World        4 billion
       ->Germany   80 million
    </pre>
    Kind regards,
    Thomas
    Message was edited by: Thomas Szuecs

  • How to create a tree structure using list items(tlist)

    HI every one,
    As we know how to create a tree structure using Hierarchy item type.
    We have a requirement to create The same tree like structure using List Item(Tlist)
    I would be so appreciated If you send with an example
    Thanks
    RangaReddy

    Hi all
    Any one help me please
    Actually our client requirement is creation of tree structure using list item,similar to what we used in oracle Application(FNDSCSGN) form.We did the tree structure using hierarchy tree using Htree and Ftree.It working excelently.For client requirement, we want to use list item.How PJC(Pluggable Java Components) is useful for using list item(Tlist).I can't understand how it is useful.
    Do you have any example please help me.
    Thanks
    RangaReddy

  • F4 search help as tree structure in a module for one field

    hi experts,
    i have created a z module by copying standard module SAPMV23N of vbg1/2/3 transaction and i have added one tab in vbg1/2/3. the 5th tab is working. i am calling a subscreen using 5 tabstrip. there are one field MAKTL i want to use a F4 search as tree structure for that MAKTL field.
    in code for displaying tree structure i am using function module RS_TREE***
    please help me

    Hi,
    Please study this search help, there is a search help exit in which the hierarchy part it written,
    Search Help: PRCTH
    Search help exit:   K_F4IF_SHLP_STANDARD_HIERARCHY
    Hope this helps you,
    Regards,
    Abhijit G. Borkar

  • How to create tree structure in abap

    hi,
       I am mohan. Please send the how to create the tree structure. how to insert the child nodes in  root node. actually our requirement is we have list transaction codes. We are planning to put all transaction codes in tree level.
    please tell me how to do the program in tree structure.

    Hi Mohan,
    Check the following program on ALV tree.
    REPORT zalvtree.
    CLASS cl_gui_column_tree DEFINITION LOAD.
    CLASS cl_gui_cfw DEFINITION LOAD.
    DATA: go_grid TYPE REF TO cl_gui_alv_grid.
    DATA: ro_grid TYPE REF TO cl_gui_alv_grid.
    DATA tree1  TYPE REF TO cl_gui_alv_tree.
    DATA mr_toolbar TYPE REF TO cl_gui_toolbar.
    DATA : gt_checked TYPE lvc_t_chit,
           gs_checked LIKE LINE OF gt_checked,
           l_part_key TYPE lvc_nkey,
           gt_node TYPE lvc_s_chit-nodekey.
    INCLUDE <icon>.
    INCLUDE zamit_alv_tree_toolbar_event.
    INCLUDE zbcalv_tree_event_receiver.
    *DATA: toolbar_event_receiver TYPE REF TO lcl_toolbar_event_receiver.
    DATA: gt_sflight      TYPE sflight OCCURS 0,      "Output-Table
          gt_fieldcatalog TYPE lvc_t_fcat, "Fieldcatalog
          ok_code LIKE sy-ucomm.           "OK-Code
    START-OF-SELECTION.
    END-OF-SELECTION.
      CALL SCREEN 100.
    *&      Module  PBO  OUTPUT
          process before output
    MODULE pbo OUTPUT.
      SET PF-STATUS 'MAIN100'.
      IF tree1 IS INITIAL.
        PERFORM init_tree.
    else.
                  CALL METHOD me->refresh_table_display
                    EXCEPTIONS
                      PROGRAM_ERROR = 1
                      others        = 2
                  IF sy-subrc <> 0.
                   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
                  ENDIF.
      ENDIF.
      CALL METHOD cl_gui_cfw=>flush.
    ENDMODULE.                             " PBO  OUTPUT
    *&      Module  PAI  INPUT
          process after input
    MODULE pai INPUT.
      CASE ok_code.
        WHEN 'EXIT' OR 'BACK' OR 'CANC'.
          PERFORM exit_program.
    *mrk
        WHEN 'MOVE'.
          PERFORM check_selection.
        WHEN 'MBAK'.
          PERFORM another_selection.
        WHEN 'ALL'.
          PERFORM select_all.
        WHEN 'CLEAR'.
          PERFORM clear_all.
        WHEN 'DELETE'.
          PERFORM delete_all.
        WHEN 'EXPAND'.
          PERFORM expand_all.
        WHEN 'COLLAPSE'.
          PERFORM collapse_all.
        WHEN OTHERS.
          CALL METHOD cl_gui_cfw=>dispatch.
      ENDCASE.
      CLEAR ok_code.
      CALL METHOD cl_gui_cfw=>flush.
    ENDMODULE.                             " PAI  INPUT
    *&      Form  build_fieldcatalog
          build fieldcatalog for structure sflight
    FORM build_fieldcatalog.
    get fieldcatalog
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name = 'SFLIGHT'
        CHANGING
          ct_fieldcat      = gt_fieldcatalog.
    change fieldcatalog
      DATA: ls_fieldcatalog TYPE lvc_s_fcat.
      LOOP AT gt_fieldcatalog INTO ls_fieldcatalog.
        CASE ls_fieldcatalog-fieldname.
          WHEN 'CARRID' OR 'CONNID' OR 'FLDATE'.
            ls_fieldcatalog-no_out = 'X'.
            ls_fieldcatalog-key    = ''.
          WHEN 'PRICE' OR 'SEATSOCC' OR 'SEATSMAX' OR 'PAYMENTSUM'.
            ls_fieldcatalog-do_sum = 'X'.
        ENDCASE.
        MODIFY gt_fieldcatalog FROM ls_fieldcatalog.
      ENDLOOP.
    ENDFORM.                               " build_fieldcatalog
    *&      Form  build_hierarchy_header
          build hierarchy-header-information
         -->P_L_HIERARCHY_HEADER  strucxture for hierarchy-header
    FORM build_hierarchy_header CHANGING
                                   p_hierarchy_header TYPE treev_hhdr.
      p_hierarchy_header-heading = 'Hierarchy Header'.          "#EC NOTEXT
      p_hierarchy_header-tooltip =
                             'This is the Hierarchy Header !'.  "#EC NOTEXT
      p_hierarchy_header-width = 30.
      p_hierarchy_header-width_pix = ''.
    ENDFORM.                               " build_hierarchy_header
    *&      Form  exit_program
          free object and leave program
    FORM exit_program.
      CALL METHOD tree1->free.
      LEAVE PROGRAM.
    ENDFORM.                               " exit_program
    *&      Form  check_selection
          text
    -->  p1        text
    <--  p2        text
    FORM check_selection .
    create container for alv-tree
      DATA: l_tree_container_name(30) TYPE c,
            l_custom_container2 TYPE REF TO cl_gui_custom_container.
      l_tree_container_name = 'TREE2'.
      IF sy-batch IS INITIAL.
        CREATE OBJECT l_custom_container2
          EXPORTING
                container_name = l_tree_container_name
          EXCEPTIONS
                cntl_error                  = 1
                cntl_system_error           = 2
                create_error                = 3
                lifetime_error              = 4
                lifetime_dynpro_dynpro_link = 5.
        IF sy-subrc <> 0.
          MESSAGE x208(00) WITH 'ERROR'.                        "#EC NOTEXT
        ENDIF.
      ENDIF.
      CREATE OBJECT go_grid
        EXPORTING
       I_SHELLSTYLE      = 0
       I_LIFETIME        =
          i_parent          = l_custom_container2
       I_APPL_EVENTS     = space
       I_PARENTDBG       =
       I_APPLOGPARENT    =
       I_GRAPHICSPARENT  =
       I_NAME            =
    EXCEPTIONS
       ERROR_CNTL_CREATE = 1
       ERROR_CNTL_INIT   = 2
       ERROR_CNTL_LINK   = 3
       ERROR_DP_CREATE   = 4
       others            = 5
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      PERFORM load_data_into_grid.
    *data: lt_nodes type LVC_T_NKEY,
         ls_nodes like line of lt_nodes,
         ls_checked like line of gt_checked.
    *loop at gt_checked into ls_checked.
    ls_nodes = ls_checked-nodekey.
    append ls_nodes to lt_nodes.
    *endloop.
    *CALL METHOD tree1->unselect_nodes
    EXPORTING
       it_node_key                  = lt_nodes
    EXCEPTIONS
       CNTL_SYSTEM_ERROR            = 1
       DP_ERROR                     = 2
       MULTIPLE_NODE_SELECTION_ONLY = 3
       ERROR_IN_NODE_KEY_TABLE      = 4
       FAILED                       = 5
       others                       = 6
    *IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *ENDIF.
    ENDFORM.                    " check_selection
    *&      Form  another_selection
          text
    -->  p1        text
    <--  p2        text
    FORM another_selection .
    create container for alv-tree
      DATA: l_tree_container_name(30) TYPE c,
            l_custom_container2 TYPE REF TO cl_gui_custom_container.
      l_tree_container_name = 'TREE2'.
      IF sy-batch IS INITIAL.
        CREATE OBJECT l_custom_container2
          EXPORTING
                container_name = l_tree_container_name
          EXCEPTIONS
                cntl_error                  = 1
                cntl_system_error           = 2
                create_error                = 3
                lifetime_error              = 4
                lifetime_dynpro_dynpro_link = 5.
        IF sy-subrc <> 0.
          MESSAGE x208(00) WITH 'ERROR'.                        "#EC NOTEXT
        ENDIF.
      ENDIF.
      CREATE OBJECT ro_grid
        EXPORTING
       I_SHELLSTYLE      = 0
       I_LIFETIME        =
          i_parent          = l_custom_container2
       I_APPL_EVENTS     = space
       I_PARENTDBG       =
       I_APPLOGPARENT    =
       I_GRAPHICSPARENT  =
       I_NAME            =
    EXCEPTIONS
       ERROR_CNTL_CREATE = 1
       ERROR_CNTL_INIT   = 2
       ERROR_CNTL_LINK   = 3
       ERROR_DP_CREATE   = 4
       others            = 5
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      PERFORM load_data_into_grid1.
      DATA: lt_unsel TYPE lvc_t_nkey,
            ls_unsel LIKE LINE OF lt_unsel.
      LOOP AT gt_checked INTO gs_checked.
        ls_unsel = gs_checked-nodekey.
        APPEND ls_unsel TO lt_unsel.
      ENDLOOP.
      CALL METHOD tree1->unselect_nodes
        EXPORTING
          it_node_key                  = lt_unsel
        EXCEPTIONS
          cntl_system_error            = 1
          dp_error                     = 2
          multiple_node_selection_only = 3
          error_in_node_key_table      = 4
          failed                       = 5
          OTHERS                       = 6.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    *CALL METHOD tree1->unselect_all
    EXCEPTIONS
       CNTL_SYSTEM_ERROR = 1
       FAILED            = 2
       others            = 3
    *IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *ENDIF.
      DATA: text TYPE lvc_value,
       item TYPE lvc_t_layi,
       node TYPE lvc_s_layn,
       inode TYPE lvc_nkey.
      FIELD-SYMBOLS: <wa> TYPE ANY.
      DATA: l_dref_wa LIKE LINE OF gt_sflight.
      ASSIGN l_dref_wa TO <wa>.
      READ TABLE gt_checked INTO gs_checked WITH KEY nodekey = 3.
      inode = gs_checked-nodekey.
      CALL METHOD tree1->get_outtab_line
        EXPORTING
          i_node_key     = inode
        IMPORTING
          e_outtab_line  = <wa>
          e_node_text    = text
          et_item_layout = item
          es_node_layout = node
        EXCEPTIONS
          node_not_found = 1
          OTHERS         = 2.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      DATA: lt_layout TYPE lvc_t_laci,
            layout LIKE LINE OF lt_layout.
      layout-chosen = 'X'.
      layout-fieldname = tree1->c_hierarchy_column_name.
    ls_item_layout-chosen = 'X'.           "To give default checkbox value checked
      layout-class   = cl_gui_column_tree=>item_class_checkbox.
      layout-editable = 'X'.
    LAYOUT-U_CHOSEN = 'X'.
      APPEND layout TO lt_layout.
      CALL METHOD tree1->change_node
        EXPORTING
          i_node_key     = inode
          i_outtab_line  = <wa>
       IS_NODE_LAYOUT =
          it_item_layout =  lt_layout
       I_NODE_TEXT    =
       I_U_NODE_TEXT  =
        EXCEPTIONS
          node_not_found = 1
          OTHERS         = 2
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    *CALL METHOD tree1->change_item
    EXPORTING
       i_node_key     = inode
       i_fieldname    = gs_checked-FIELDNAME
       i_data         = <wa>
       I_U_DATA       = ''
       IS_ITEM_LAYOUT = layout
    EXCEPTIONS
       NODE_NOT_FOUND = 1
       others         = 2
    *IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *ENDIF.
    *loop at lt_unsel into ls_unsel.
    *CALL METHOD tree1->update_checked_items
    EXPORTING
       i_node_key    = ls_unsel
       i_fieldname   = ''
       i_checked     = ''
    EXCEPTIONS
       PROGRAM_ERROR = 1
       others        = 2
    *IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *ENDIF.
    *endif.
    ENDFORM.                    " another_selection
    *&      Form  select_all
          text
    -->  p1        text
    <--  p2        text
    FORM select_all .
      CONSTANTS: c_x(1) TYPE c VALUE 'X'.
    *********Check box modifications.
      CALL METHOD tree1->delete_all_nodes
        EXCEPTIONS
          failed            = 1
          cntl_system_error = 2
          OTHERS            = 3.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    clear l_part_key.
    create hierarchy
      PERFORM create_hierarchy USING c_x.
      CALL METHOD tree1->expand_node
        EXPORTING
          i_node_key          = gt_node
       I_LEVEL_COUNT       = 1
          i_expand_subtree    = 'X'
        EXCEPTIONS
          failed              = 1
          illegal_level_count = 2
          cntl_system_error   = 3
          node_not_found      = 4
          cannot_expand_leaf  = 5
          OTHERS              = 6
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    add own functioncodes to the toolbar
    perform change_toolbar.
    register events
    perform register_events.
    adjust column_width
    call method tree1->COLUMN_OPTIMIZE.
    ENDFORM.                    " select_all
    *&      Form  clear_all
          text
    -->  p1        text
    <--  p2        text
    FORM clear_all .
      CONSTANTS: c_x(1) TYPE c VALUE space.
    *********Check box modifications.
      CALL METHOD tree1->delete_all_nodes
        EXCEPTIONS
          failed            = 1
          cntl_system_error = 2
          OTHERS            = 3.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    create hierarchy
      PERFORM create_hierarchy USING c_x.
      CALL METHOD tree1->expand_node
        EXPORTING
          i_node_key          = gt_node
       I_LEVEL_COUNT       = 1
          i_expand_subtree    = 'X'
        EXCEPTIONS
          failed              = 1
          illegal_level_count = 2
          cntl_system_error   = 3
          node_not_found      = 4
          cannot_expand_leaf  = 5
          OTHERS              = 6
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " clear_all
    *&      Form  delete_all
          text
    -->  p1        text
    <--  p2        text
    FORM delete_all .
    *********Check box modifications.
      CALL METHOD tree1->delete_all_nodes
        EXCEPTIONS
          failed            = 1
          cntl_system_error = 2
          OTHERS            = 3.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " delete_all
    *&      Form  expand_all
          text
    -->  p1        text
    <--  p2        text
    FORM expand_all .
      CALL METHOD tree1->expand_node
        EXPORTING
          i_node_key          = gt_node
       I_LEVEL_COUNT       = 1
          i_expand_subtree    = 'X'
        EXCEPTIONS
          failed              = 1
          illegal_level_count = 2
          cntl_system_error   = 3
          node_not_found      = 4
          cannot_expand_leaf  = 5
          OTHERS              = 6
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " expand_all
    *&      Form  collapse_all
          text
    -->  p1        text
    <--  p2        text
    FORM collapse_all .
      CALL METHOD tree1->collapse_all_nodes
        EXCEPTIONS
          failed            = 1
          cntl_system_error = 2
          OTHERS            = 3.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " collapse_all
    *&      Form  load_data_into_grid
          text
    -->  p1        text
    <--  p2        text
    FORM load_data_into_grid .
      DATA:
      For parameter IS_VARIANT
          l_layout TYPE disvariant,
      gs_layout TYPE lvc_s_layo.
      DATA gi_sflight TYPE TABLE OF zsflight.
    Load data into the grid and display them
      l_layout-report = sy-repid.
      gs_layout-grid_title = 'Amits Test Program'.
      gs_layout-sel_mode = 'A'.
      SELECT *
       FROM zsflight
       INTO TABLE gi_sflight.
      CALL METHOD go_grid->set_table_for_first_display
        EXPORTING
          i_structure_name = 'SFLIGHT'
          is_layout        = gs_layout
          is_variant       = l_layout
          i_save           = 'A'
        CHANGING
          it_outtab        = gi_sflight.
    ENDFORM.                    " load_data_into_grid
    *&      Form  load_data_into_grid
          text
    -->  p1        text
    <--  p2        text
    FORM load_data_into_grid1.
      DATA:
      For parameter IS_VARIANT
          l_layout TYPE disvariant,
      gs_layout TYPE lvc_s_layo.
      DATA gi_sflight TYPE TABLE OF zapempl.
    Load data into the grid and display them
      l_layout-report = sy-repid.
      gs_layout-grid_title = 'Rams Test Program'.
      gs_layout-sel_mode = 'A'.
      SELECT *
       FROM zapempl
       INTO TABLE gi_sflight.
      CALL METHOD ro_grid->set_table_for_first_display
        EXPORTING
          i_structure_name = 'ZAPEMPL'
          is_layout        = gs_layout
          is_variant       = l_layout
          i_save           = 'A'
        CHANGING
          it_outtab        = gi_sflight.
    ENDFORM.                    " load_data_into_grid1
    *&      Form  build_header
          build table for html_header
    -->  p1        text
    <--  p2        text
    FORM build_comment USING
          pt_list_commentary TYPE slis_t_listheader
          p_logo             TYPE sdydo_value.
      DATA: ls_line TYPE slis_listheader.
    LIST HEADING LINE: TYPE H
      CLEAR ls_line.
      ls_line-typ  = 'H'.
    LS_LINE-KEY:  NOT USED FOR THIS TYPE
      ls_line-info = 'ALV-tree-demo: flight-overview'.          "#EC NOTEXT
      APPEND ls_line TO pt_list_commentary.
    STATUS LINE: TYPE S
      CLEAR ls_line.
      ls_line-typ  = 'S'.
      ls_line-key  = 'valid until'.                             "#EC NOTEXT
      ls_line-info = 'January 29 1999'.                         "#EC NOTEXT
      APPEND ls_line TO pt_list_commentary.
      ls_line-key  = 'time'.
      ls_line-info = '2.00 pm'.                                 "#EC NOTEXT
      APPEND ls_line TO pt_list_commentary.
    ACTION LINE: TYPE A
      CLEAR ls_line.
      ls_line-typ  = 'A'.
    LS_LINE-KEY:  NOT USED FOR THIS TYPE
      ls_line-info = 'actual data'.                             "#EC NOTEXT
      APPEND ls_line TO pt_list_commentary.
      p_logo = 'ENJOYSAP_LOGO'.
    ENDFORM.                    "build_comment
    *&      Form  create_hierarchy
          text
    -->  p1        text
    <--  p2        text
    FORM create_hierarchy USING p_x.
      DATA: ls_sflight TYPE sflight,
            lt_sflight TYPE sflight OCCURS 0.
    get data
      SELECT * FROM sflight INTO TABLE lt_sflight
                            UP TO 200 ROWS .
      SORT lt_sflight BY carrid connid fldate.
    add data to tree
      DATA: l_carrid_key TYPE lvc_nkey,
            l_connid_key TYPE lvc_nkey,
            l_last_key TYPE lvc_nkey.
           l_part_key TYPE lvc_nkey
      PERFORM add_carrid_line USING    ls_sflight
                              CHANGING l_part_key.
      gt_node = l_part_key.
      LOOP AT lt_sflight INTO ls_sflight.
        ON CHANGE OF ls_sflight-carrid.
          PERFORM add_carrid_line USING    ls_sflight
                                           l_part_key
                                  CHANGING l_carrid_key.
          PERFORM add_connid_line USING    ls_sflight
                                           l_carrid_key
                                  CHANGING l_connid_key.
          PERFORM add_complete_line USING  ls_sflight
                                         l_connid_key
                                         p_x
                                CHANGING l_last_key.
          CONTINUE.
        ENDON.
        ON CHANGE OF ls_sflight-connid.
          PERFORM add_connid_line USING    ls_sflight
                                           l_carrid_key
                                  CHANGING l_connid_key.
          PERFORM add_complete_line USING  ls_sflight
                                         l_connid_key
                                         p_x
                                CHANGING l_last_key.
          CONTINUE.
        ENDON.
        PERFORM add_complete_line USING  ls_sflight
                                         l_connid_key
                                         p_x
                                CHANGING l_last_key.
      ENDLOOP.
    calculate totals
      CALL METHOD tree1->update_calculations.
    this method must be called to send the data to the frontend
      CALL METHOD tree1->frontend_update.
    ENDFORM.                               " create_hierarchy
    *&      Form  add_carrid_line
          add hierarchy-level 1 to tree
         -->P_LS_SFLIGHT  sflight
         -->P_RELEATKEY   relatkey
        <-->p_node_key    new node-key
    FORM add_carrid_line USING     ps_sflight TYPE sflight
                                   p_relat_key TYPE lvc_nkey
                         CHANGING  p_node_key TYPE lvc_nkey.
      DATA: l_node_text TYPE lvc_value,
            ls_sflight TYPE sflight.
    set item-layout
      DATA: lt_item_layout TYPE lvc_t_layi,
            ls_item_layout TYPE lvc_s_layi.
      ls_item_layout-t_image = '@3P@'.
      ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
      ls_item_layout-style   =
                            cl_gui_column_tree=>style_intensifd_critical.
      APPEND ls_item_layout TO lt_item_layout.
    add node
      l_node_text =  ps_sflight-carrid.
      CALL METHOD tree1->add_node
        EXPORTING
          i_relat_node_key = p_relat_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          i_node_text      = l_node_text
          is_outtab_line   = ls_sflight
          it_item_layout   = lt_item_layout
        IMPORTING
          e_new_node_key   = p_node_key.
    ENDFORM.                               " add_carrid_line
    *&      Form  add_connid_line
          add hierarchy-level 2 to tree
         -->P_LS_SFLIGHT  sflight
         -->P_RELEATKEY   relatkey
        <-->p_node_key    new node-key
    FORM add_connid_line USING     ps_sflight TYPE sflight
                                   p_relat_key TYPE lvc_nkey
                         CHANGING  p_node_key TYPE lvc_nkey.
      DATA: l_node_text TYPE lvc_value,
            ls_sflight TYPE sflight.
    set item-layout
      DATA: lt_item_layout TYPE lvc_t_layi,
            ls_item_layout TYPE lvc_s_layi.
      ls_item_layout-t_image = '@3Y@'.
      ls_item_layout-style   =
                            cl_gui_column_tree=>style_intensified.
      ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
      APPEND ls_item_layout TO lt_item_layout.
    add node
      l_node_text =  ps_sflight-connid.
      CALL METHOD tree1->add_node
        EXPORTING
          i_relat_node_key = p_relat_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          i_node_text      = l_node_text
          is_outtab_line   = ls_sflight
          it_item_layout   = lt_item_layout
        IMPORTING
          e_new_node_key   = p_node_key.
    ENDFORM.                               " add_connid_line
    *&      Form  add_cmplete_line
          add hierarchy-level 3 to tree
         -->P_LS_SFLIGHT  sflight
         -->P_RELEATKEY   relatkey
        <-->p_node_key    new node-key
    FORM add_complete_line USING   ps_sflight TYPE sflight
                                   p_relat_key TYPE lvc_nkey
                                   p_x
                         CHANGING  p_node_key TYPE lvc_nkey.
      DATA: l_node_text TYPE lvc_value.
    set item-layout
      DATA: lt_item_layout TYPE lvc_t_layi,
            ls_item_layout TYPE lvc_s_layi.
      ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
      ls_item_layout-chosen = p_x.           "To give default checkbox value checked
      ls_item_layout-class   = cl_gui_column_tree=>item_class_checkbox.
      ls_item_layout-editable = 'X'.
      APPEND ls_item_layout TO lt_item_layout.
      l_node_text =  ps_sflight-fldate.
      CALL METHOD tree1->add_node
        EXPORTING
          i_relat_node_key = p_relat_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          is_outtab_line   = ps_sflight
          i_node_text      = l_node_text
          it_item_layout   = lt_item_layout
        IMPORTING
          e_new_node_key   = p_node_key.
    ENDFORM.                               " add_complete_line
    *&      Form  register_events
          text
    -->  p1        text
    <--  p2        text
    FORM register_events.
    define the events which will be passed to the backend
      DATA: lt_events TYPE cntl_simple_events,
            l_event TYPE cntl_simple_event.
    define the events which will be passed to the backend
      l_event-eventid = cl_gui_column_tree=>eventid_expand_no_children.
      APPEND l_event TO lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_checkbox_change.
      APPEND l_event TO lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_header_context_men_req.
      APPEND l_event TO lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
      APPEND l_event TO lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_item_context_menu_req.
      APPEND l_event TO lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_header_click.
      APPEND l_event TO lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_item_keypress.
      APPEND l_event TO lt_events.
      CALL METHOD tree1->set_registered_events
        EXPORTING
          events                    = lt_events
        EXCEPTIONS
          cntl_error                = 1
          cntl_system_error         = 2
          illegal_event_combination = 3.
      IF sy-subrc <> 0.
        MESSAGE x208(00) WITH 'ERROR'.                          "#EC NOTEXT
      ENDIF.
    set Handler
      DATA: l_event_receiver TYPE REF TO lcl_tree_event_receiver.
      CREATE OBJECT l_event_receiver.
      SET HANDLER l_event_receiver->handle_node_ctmenu_request
                                                            FOR tree1.
      SET HANDLER l_event_receiver->handle_node_ctmenu_selected
                                                            FOR tree1.
      SET HANDLER l_event_receiver->handle_item_ctmenu_request
                                                            FOR tree1.
      SET HANDLER l_event_receiver->handle_item_ctmenu_selected
                                                            FOR tree1.
      SET HANDLER l_event_receiver->handle_checkbox_change FOR tree1.
    ENDFORM.                               " register_events
    *&      Form  change_toolbar
          text
    -->  p1        text
    <--  p2        text
    FORM change_toolbar.
    DATA: toolbar_event_receiver TYPE REF TO lcl_toolbar_event_receiver.
    get toolbar control
      CALL METHOD tree1->get_toolbar_object
        IMPORTING
          er_toolbar = mr_toolbar.
      CHECK NOT mr_toolbar IS INITIAL.
    add seperator to toolbar
      CALL METHOD mr_toolbar->add_button
        EXPORTING
          fcode     = ''
          icon      = ''
          butn_type = cntb_btype_sep
          text      = ''
          quickinfo = 'This is a Seperator'.                    "#EC NOTEXT
    add Standard Button to toolbar (for Delete Subtree)
      CALL METHOD mr_toolbar->add_button
        EXPORTING
          fcode     = 'DELETE'
          icon      = '@18@'
          butn_type = cntb_btype_button
          text      = ''
          quickinfo = 'Delete subtree'.                         "#EC NOTEXT
    add Dropdown Button to toolbar (for Insert Line)
      CALL METHOD mr_toolbar->add_button
        EXPORTING
          fcode     = 'INSERT_LC'
          icon      = '@17@'
          butn_type = cntb_btype_dropdown
          text      = ''
          quickinfo = 'Insert Line'.                            "#EC NOTEXT
    set event-handler for toolbar-control
      CREATE OBJECT toolbar_event_receiver.
      SET HANDLER toolbar_event_receiver->on_function_selected
                                                          FOR mr_toolbar.
      SET HANDLER toolbar_event_receiver->on_toolbar_dropdown
                                                          FOR mr_toolbar.
    ENDFORM.                               " change_toolbar
    *&      Form  init_tree
          text
    -->  p1        text
    <--  p2        text
    FORM init_tree.
    create fieldcatalog for structure sflight
      PERFORM build_fieldcatalog.
    create container for alv-tree
      DATA: l_tree_container_name(30) TYPE c,
            l_custom_container TYPE REF TO cl_gui_custom_container.
      l_tree_container_name = 'TREE1'.
      IF sy-batch IS INITIAL.
        CREATE OBJECT l_custom_container
          EXPORTING
                container_name = l_tree_container_name
          EXCEPTIONS
                cntl_error                  = 1
                cntl_system_error           = 2
                create_error                = 3
                lifetime_error              = 4
                lifetime_dynpro_dynpro_link = 5.
        IF sy-subrc <> 0.
          MESSAGE x208(00) WITH 'ERROR'.                        "#EC NOTEXT
        ENDIF.
      ENDIF.
    create tree control
      CREATE OBJECT tree1
        EXPORTING
            parent              = l_custom_container
            node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple "node_sel_mode_single
            item_selection      = 'X'
            no_html_header      = ''
            no_toolbar          = ''
        EXCEPTIONS
            cntl_error                   = 1
            cntl_system_error            = 2
            create_error                 = 3
            lifetime_error               = 4
            illegal_node_selection_mode  = 5
            failed                       = 6
            illegal_column_name          = 7.
      IF sy-subrc <> 0.
        MESSAGE x208(00) WITH 'ERROR'.                          "#EC NOTEXT
      ENDIF.
    create Hierarchy-header
      DATA l_hierarchy_header TYPE treev_hhdr.
      PERFORM build_hierarchy_header CHANGING l_hierarchy_header.
    create info-table for html-header
      DATA: lt_list_commentary TYPE slis_t_listheader,
            l_logo             TYPE sdydo_value.
      PERFORM build_comment USING
                     lt_list_commentary
                     l_logo.
    repid for saving variants
      DATA: ls_variant TYPE disvariant.
      ls_variant-report = sy-repid.
    create emty tree-control
      CALL METHOD tree1->set_table_for_first_display
        EXPORTING
          is_hierarchy_header = l_hierarchy_header
          it_list_commentary  = lt_list_commentary
          i_logo              = l_logo
          i_background_id     = 'ALV_BACKGROUND'
          i_save              = 'A'
          is_variant          = ls_variant
        CHANGING
          it_outtab           = gt_sflight "table must be emty !!
          it_fieldcatalog     = gt_fieldcatalog.
      CONSTANTS: c_s(1) TYPE c VALUE space.
    create hierarchy
      PERFORM create_hierarchy USING c_s.
    add own functioncodes to the toolbar
      PERFORM change_toolbar.
    register events
      PERFORM register_events.
    adjust column_width
    call method tree1->COLUMN_OPTIMIZE.
    ENDFORM.                    " init_tree
    Award points if found useful.
    Regards
    Indrajit

Maybe you are looking for

  • Dynamic query report problem

    I have followed the tutorial in on dynamic query and created a region where the type is SQL Query (PL/SQL function body returning SQL Query) The source is declare q varchar2(4000); teatid NUMBER := :P305_TARGET_ID; begin wwv_flow.debug('teatid = ' ||

  • HP printer is in paused status and will not print. HP6520

    How to remove the hp6520 printer out of paused status?

  • Problem with CCMS PI7.1 alert configuration for RWB Alert count

    Hi, We have configured CCMS alert for PI7.1 RWB failure count. Alert is getting triggered only one time and after that no alerts. I can see the change in data but alert is not getting triggered. If I complete the alert then immediately in next run a

  • Stand Alone Skin Editor

    Here is the scenario. I am strictly a front-end developer using HTML, CSS, Javascript etc. I have been brought onboard to work on a project that uses the Oracle Fusion Middleware ADF Framework. I am a total noob with this stuff!! We are currently wor

  • What are those sounds warning on the iPad?

    The ipad makes sounds as if it would have received something or had connected to something but does not say what is, can be a virus or a hacker?