Calculation of average in the child-parent relationship

Hello

Oracle database version: 11.2.0.1.0

Currently I'm having a problem of query to calculate the average value. Using the usual average query does not get the result I'm looking for. Because I'm not good with English, I will try to explain for example instead.

Data table
COD_A     COD_B     SALES     QTY     PRICE
0000302     00003               6.09
0000302     00003               11.7
0000304     00003               14.08
0000306     00003               8.87
0000306     00003     3105     510     4.63
0000306     00003               4.65
0000308     00003     18091     1456     12.43
If I try to calculate the average price of COD_A, I have the correct answer, as expected.
SELECT COD_A, SUM(SALES), SUM(QTY), AVG(PRICE) FROM VDATATABLE GROUP BY COD_A ORDER BY 1;
Average price per COD_A
COD_A     SUM(SALES)     SUM(QTY)     AVG(PRICE)
0000302                                8.895
0000304                           14.08
0000306     3105         510                6.05
0000308     18091        1456              12.43
--------------

If I try to calculate the average price of COD_B, I don't have my expected result.
SELECT COD_B, SUM(SALES), SUM(QTY), AVG(PRICE) FROM VDATATABLE GROUP BY COD_B ORDER BY 1;
Average price per COD_B (1)
COD_B     SUM(SALES)     SUM(QTY)     AVG(PRICE)
00003     21196             1966              8.92142857142857
The result I'm looking for is
WITH W1 AS
(SELECT COD_B, SUM(SALES) SALES, SUM(QTY) QTY, AVG(PRICE) PRICE FROM VDATATABLE GROUP BY COD_A,COD_B)
SELECT COD_B, SUM(SALES), SUM(QTY), AVG(PRICE) FROM W1 GROUP BY COD_B;
Average price of COD_B (2)
COD_B     SUM(SALES)     SUM(QTY)     AVG(PRICE)
00003     21196              1966         10.36375
---------

So, the way I want to calculate the average price is the average of the lower child attribute and continue the average to its parent attribute. Currently I can get the result by using the clause, but the hierarchy available not only stops at COD_B, there is more (e.g. COD_C, COD_D, so on), so the foregoing WITH the query "seems" to be inflexible. If I want to ask the COD_C aggregation, I might have to put another COMPONENT in the query.

So I was wondering is there any other better method to get the result I want? Something more dynamic as a recursive function or integrated maybe?

Thank you

Published by: user10620897 on October 19, 2011 04:15

Hello

Whenever you have questions, please post CREATE TABLE and INSERT statements for your sample data.
Always tell what version of Oracle you are using. Don't say something vague, like "11g" in a label where it is easy to miss. Tell exactly what version you have in the body of the message. For example "I'm using Oracle 11.1.0.7.0.

If you have N levels in the hierarchy, then using subqueries N-1, as you already do, might be the best way.

If you use Oracle 11.2, you may be able to obtain these results by using a WITH recursive clause.

Here's another approach to obtain the results desired with a hierarchy of level 2:

WITH     got_cnt          AS
(
     SELECT     cod_a, cod_b, sales, qty, price
     ,     COUNT (*) OVER (PARTITION BY cod_a, cod_b)     AS cnt
     FROM     data
)
SELECT       cod_b
,       SUM (sales)               AS sum_sales
,       SUM (qty)                  AS sum_qty
,       SUM (price / cnt)
       / COUNT (DISTINCT cod_a)     AS avg_price
FROM       got_cnt
GROUP BY  cod_b
;

I think you can do this job for any number of levels without adding another subquery for all levels. You may need to add expressions to COUNT more for all levels, and the query only works for a fixed number of levels.

Tags: Database

Similar Questions

  • expdp/impdp: constraints in the child-Parent relationship

    Hello

    I have a table parent1 and child1, child2 and chld3 tables have foreign key created on this parent1.

    Now, I want to do a delete on parent1. But as the number of records is very high on parent1, we go with expdp / impdp with option querry.

    I took the expdp parent1 level query. Now I dropped parent1 with option of cascade constraints and all foreign keys created by child1, 2 and 3 that parent1 references are automatically deleted.

    Now, if I have the impdp to the query of fire level dump file, are these foreign key constraints will be created automatically on child1, 2 and 3 or I need to manually recreate it?

    Kind regards

    ANU

    Hello
    The CF will not be in the dumpfile - see the code example below where I generate a sqlfile following pretty much the process that you would have done. This is because FK belongs to the DDL for the child table not the parent.

    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning option
    
    OPS$ORACLE@EMZA3>create table a (col1 number);
    
    Table created.
    
    OPS$ORACLE@EMZA3>alter table a add primary key (col1);
    
    Table altered.
    
    OPS$ORACLE@EMZA3>create table b (col1 number);
    
    Table created.
    
    OPS$ORACLE@EMZA3>alter table b add constraint x foreign key (col1) references a(col1);
    
    Table altered.
    
    OPS$ORACLE@EMZA3>
    
    EMZA3:[/oracle/11.2.0.1.2.DB/bin]# expdp / include=TABLE:\"=\'A\'\"
    
    Export: Release 11.2.0.3.0 - Production on Fri May 17 15:45:50 2013
    
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning option
    Starting "OPS$ORACLE"."SYS_EXPORT_SCHEMA_04":  /******** include=TABLE:"='A'"
    Estimate in progress using BLOCKS method...
    Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 0 KB
    Processing object type SCHEMA_EXPORT/TABLE/TABLE
    Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    . . exported "OPS$ORACLE"."A"                                0 KB       0 rows
    Master table "OPS$ORACLE"."SYS_EXPORT_SCHEMA_04" successfully loaded/unloaded
    ******************************************************************************
    Dump file set for OPS$ORACLE.SYS_EXPORT_SCHEMA_04 is:
      /oracle/11.2.0.3.0.DB/rdbms/log/expdat.dmp
    Job "OPS$ORACLE"."SYS_EXPORT_SCHEMA_04" successfully completed at 15:45:58
    
    Import: Release 11.2.0.3.0 - Production on Fri May 17 15:46:16 2013
    
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning option
    Master table "OPS$ORACLE"."SYS_SQL_FILE_FULL_01" successfully loaded/unloaded
    Starting "OPS$ORACLE"."SYS_SQL_FILE_FULL_01":  /******** sqlfile=a.sql
    Processing object type SCHEMA_EXPORT/TABLE/TABLE
    Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    Job "OPS$ORACLE"."SYS_SQL_FILE_FULL_01" successfully completed at 15:46:17
    
    -- CONNECT OPS$ORACLE
    ALTER SESSION SET EVENTS '10150 TRACE NAME CONTEXT FOREVER, LEVEL 1';
    ALTER SESSION SET EVENTS '10904 TRACE NAME CONTEXT FOREVER, LEVEL 1';
    ALTER SESSION SET EVENTS '25475 TRACE NAME CONTEXT FOREVER, LEVEL 1';
    ALTER SESSION SET EVENTS '10407 TRACE NAME CONTEXT FOREVER, LEVEL 1';
    ALTER SESSION SET EVENTS '10851 TRACE NAME CONTEXT FOREVER, LEVEL 1';
    ALTER SESSION SET EVENTS '22830 TRACE NAME CONTEXT FOREVER, LEVEL 192 ';
    -- new object type path: SCHEMA_EXPORT/TABLE/TABLE
    CREATE TABLE "OPS$ORACLE"."A"
       (    "COL1" NUMBER
       ) SEGMENT CREATION IMMEDIATE
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
     NOCOMPRESS LOGGING
      STORAGE(INITIAL 16384 NEXT 16384 MINEXTENTS 1 MAXEXTENTS 505
      PCTINCREASE 50 FREELISTS 1 FREELIST GROUPS 1
      BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "SYSTEM" ;
    -- new object type path: SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    ALTER TABLE "OPS$ORACLE"."A" ADD PRIMARY KEY ("COL1")
      USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
      STORAGE(INITIAL 16384 NEXT 16384 MINEXTENTS 1 MAXEXTENTS 505
      PCTINCREASE 50 FREELISTS 1 FREELIST GROUPS 1
      BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "SYSTEM"  ENABLE;
    -- new object type path: SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    DECLARE I_N VARCHAR2(60);
      I_O VARCHAR2(60);
      NV VARCHAR2(1);
      c DBMS_METADATA.T_VAR_COLL;
      df varchar2(21) := 'YYYY-MM-DD:HH24:MI:SS';
     stmt varchar2(300) := ' INSERT INTO "SYS"."IMPDP_STATS" (type,version,flags,c1,c2,c3,c5,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,d1,cl1) VALUES (''I'',6,:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,NULL,:14,:15,NULL,:16,:17)';
    BEGIN
      DELETE FROM "SYS"."IMPDP_STATS";
      c(1) := 'COL1';
    
      DBMS_METADATA.GET_STAT_INDNAME('OPS$ORACLE','A',c,1,i_o,i_n);
      EXECUTE IMMEDIATE stmt USING 0,I_N,NV,NV,I_O,0,0,0,0,0,0,0,0,NV,NV,TO_DATE('2013-05-17 15:43:24',df),NV;
    
      DBMS_STATS.IMPORT_INDEX_STATS('"' || i_o || '"','"' || i_n || '"',NULL,'"IMPDP_STATS"',NULL,'"SYS"');
      DELETE FROM "SYS"."IMPDP_STATS";
    END;
    /
    

    Kind regards
    Harry

    http://dbaharrison.blogspot.com/

  • How to create a child-parent relationship in ADF

    Hello

    I have 2 tables-> a parent table and another child table.

    Now, I need to create a workflow ADF as on the selection of a row in the parent table, it should display the rows from the related child table the parent table.

    I also want to add/change/remove the data from the two tables.

    Could you please guide me to some tutorial so that I can make the features mentioned above as I'm new to ADF.

    Thank you

    Check this box
    http://www.javacodegeeks.com/2012/10/master-detail-CRUD-operations-with.html
    CRUD operation

    ~ Abhijit

  • the query result child parent

    Hi all

    I write the query to the output of the Parent and the child's relationship and would need assistance. Would like to ask someone to help out me.

    I have a table like

    create the table par_chd

    (

    parent_id number (10),

    child_id number (10)

    );

    Who has data like

    SQL > select * from par_chd;

    PARENT_ID, CHILD_ID

    ----------- -----------

    1001 1011

    1001-1021

    1001 1031

    1001-1041

    1021 10210

    1031 10310

    6 selected lines

    I would like to have output as

    PARENT_ID CHILD_LEVEL_1 CHILD_LEVEL_2

    ----------          -------------              -------------

    1001 1011

    1001-1021-10210

    1001-1021

    1001 1031 10310

    1001 1031

    1001-1041

    1001

    7 selected lines

    Thanks in advance

    Saaz

    Hi Saaz,

    Minor adjustment to the script of Moazzam (who made 99% of employment):

    SELECT

    connect_by_root (parent_id),

    CASE

    WHEN LEVEL = 1 THEN child_id

    WHEN LEVEL = 2 THEN PREVIOUSLY child_id

    OTHER prerequisite parent_id

    END CHILD_LEVEL_1

    CASE

    WHEN LEVEL = 2 THEN child_id

    ANOTHER PREREQUISITE Child_id

    END CHILD_LEVEL_2

    CASE

    WHEN LEVEL = 3 THEN child_id

    END CHILD_LEVEL_3

    OF par_chd

    START WITH parent_id = 1001

    CONNECT BY parent_id = child_id PRIOR

    UNION ALL

    SELECT 1001, NULL, NULL, NULL FROM DUAL;

  • Remove the child window Parent using WIN API

    Hi all

    For a parent-child relationship between two screws using the User32.dll I use the SetParent function and pass the handle of the parent VI and VI child to this function. Now, after this relationship has been established, I want to remove the child from the parent window and use it as an independent VI using WIN API. Can someone help me on this?

    Thanks in advance!

    Fragger Fox!

    Hi Fragger Fox,

    I think that it should be possible, if you assign a new parent to the child. Maybe this works if you assign the desktop as a new parent.

    It will be useful.

    Mike

  • Get the Parent for each record in the child

    Dear Experts,

    I have a table that contains the parent and child information. I need to make a request to get the parents of each book of the child table. I tried to write the query but does not get the expected results. Please help me.

    Table: relationship

    Parent of the child

    102 101

    103 102

    104 103

    106 105

    107 106

    109 108

    110 109

    Output:

    Expected child

    102 101

    103 102; 101

    104 103, 102, 101

    106 105

    107 106; 105

    109 108

    110 109

    Thank you very much

    Hello

    MU * 443499 * TR wrote:

    Dear Experts,

    I have a table that contains the parent and child information. I need to make a request to get the parents of each book of the child table. I tried to write the query but does not get the expected results. Please help me.

    Table: relationship

    Parent of the child

    102 101

    103 102

    104 103

    106 105

    107 106

    109 108

    110 109

    Output:

    Expected child

    102 101

    103 102; 101

    104 103, 102, 101

    106 105

    107 106; 105

    109 108

    110 109

    Thank you very much

    Why do you want to

    Expected child

    -----  ---------------

    110 109

    Instead of

    Expected child

    -----  ---------------

    110 109; 108

    ?

    You may want something like this:

    CONNECT_BY_ROOT SELECT AS children

    SYS_CONNECT_BY_PATH (parent, ';')  AS expected_output

    FROM table_x

    WHERE CONNECT_BY_ISLEAF = 1

    CONNECT BY child = parent PRIOR

    ;

    If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.

  • Switch the setting to a page of the window parent child and store session values in the parent window

    Hello

    I have two pages of the apex. I open a page of the child using javascript in the parent page.

    Parent window has the following articles.  P1_Text1, P1_text2, P1_text3. The setting is 'Change only when the session state is null', static assignment.

    In the child window: I have two buttons 'Confirm' and 'close '.

    When I press "confirm", it sets the value of a page element parent in a process of PL/SQL.

    BEGIN

    / * some calculations

    followed by an assignment statement * /.

    : P1_Text1: = final_value;

    END;

    "Close" button in the child window. as a result of javascript that are associated with:

    JavaScript:

    Window.opener.Location.href = window.opener.location.href;

    Window.Close ();


    When I press the close button, the parent window gets updated and P1_Text1 is responsible for the requirements.  Everything is going well so far.


    But the problem is with other elements of the parent page. They become null.


    How to store the values of the elements of the page of the parent window?



    Kind regards

    Archana








    archana2 wrote:

    But the problem is with other elements of the parent page. They become null.

    How to store the values of the elements of the page of the parent window?

    Problem: You're not 'save' the other page elements.

    Solution: Before you open the child window, you need to "introduce" the values desired registered on the server.

    This is best done with a dynamic Action that uses a PL/SQL code block.  The key is to include all the items you want to store the property in the "Page" referred to submit

    PL/SQL code is a code simple no - ops

    begin
      null;
    end;
    

    For you, it seems that the 'child window open"should be action 2 of this dynamic Action.

    MK

  • Responsive HTML5 with mergedprojects, creates a hyperlink to a file in the project html parent to a child html file and it does not work! The child has with the parent TOC, but need to tie. Help, please!

    Hi group!

    I have a brilliant parent project that serves as a springboard for other projects. Users click a component of software they want and are redirected to a page with a list of all the documentation available for this component. Click on the name of a document and access - a lot of PDF files. BUT I also wish they were able to tie the online help for the component. After having read up on the link through / between projects, I knew that I needed to create a parent project (for the page intro and links brilliant) and projects for children (for software components).

    THEN

    I created a parent sensitive HTML5 project and the projects of two children. I compiled the parent to create mergedprojects files, and then open the projects children and collected to the appropriate mergedprojects folder. I then created a hyperlink to the file list html documentation in the project parent towards the child file software component html (output folder and start page [which is the same as the default theme]) and the link does not work! The child and its table of contents appears in the parent TOC so topics are here, but I can't link to them. If necessary, I can send screenshots.

    Where I am dorking this place?

    Thanks in advance for your time and help!

    Scottie 'needs help' gear

    What is your relationship like? And how did you create the link?

    A typical reactive merged help is structured as follows:

    index.htm (Master home page)

    mergedProjects

    childName

    index.htm (starting page for child)

    A child from the index.htm page link would look like this:... /... index.htm

    Kind regards

    Willam

  • When Parent, the child is not getting saved.

    Hello
    I have 2 entities

    Public parent()
    {
    int A;
    int B;
    Child of the child;

    @ManyToOne (waterfall = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn (name = "child_id", nullable = false)
    public child getChild() {}
    Return this.child;
    }
    }

    public Child()
    {
    int child_Id;
    int Y;
    The value < Parent > parents;

    @OneToMany (fetch = FetchType.LAZY, mappedBy = "child")
    public Set < Parent > getParents() {}
    Return this.parents;
    }

    }

    Then
    Parent P = new Parent();
    Class c Child = new Child();
    ....
    I put values for classes of the mother and the child
    p.setChild (c);

    So, when I save the parent class

    entityManager.persist (parent);

    Ideally, it should save the child. But she got the following error. My mapping entity were not manually written. They were generated by eclipse. So I guess that as long as the database mapping is correct by the entity mapping will be also correct.

    +
    Caused by: openjpa - 1.1.1 - SNAPSHOT-error no fatal store r422266:807362 > org.apache.openjpa.util.StoreException: ORA-02291: integrity (PARENT_R03) violated constraint - found parent key
    {prepstmnt 4234 INSERT INTO PARENT (A, B, CHILD_ID) VALUES (?,?,?,?,?,?,?)} {[(null), (null) null, null, (BigDecimal) 58608]} [code = 2291, State = 23000]
    FailedObject: com.ejb.entity.Parent@337261
    at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4207)
    at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4171)
    at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:102)
    at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:72)
    at kodo.jdbc.kernel.BatchingPreparedStatementManager.flushInternal(BatchingPreparedStatementManager.java:214)
    at kodo.jdbc.kernel.BatchingPreparedStatementManager.flushInternal(BatchingPreparedStatementManager.java:112)
    at kodo.jdbc.kernel.BatchingPreparedStatementManager.flush(BatchingPreparedStatementManager.java:72)
    at kodo.jdbc.kernel.AutoOrderUpdateManager.flush(AutoOrderUpdateManager.java:84)
    at kodo.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:68)
    at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:89)
    at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72)
    at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:549)
    at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
    at org.apache.openjpa.datacache.DataCacheStoreManager.flush(DataCacheStoreManager.java:554)
    at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
    ... more than 49
    +
    As you can see the CHILD_ID was generated. But I think that the order in which it gets commited is different. Please let me know if I need to change the configuration of my entity to make it work.

    Jebus, a column of ID of BigDecimal. You must have the intention to store the whole universe in there. I never managed to go on a primary key to precision 10 sequence generated to myself...

    Same difference: sound in rear. You have a card with a RfuiRfDef child and a child of RfuiRfDef belonging to many cards. Huh?

    In this scenario, I see only one true way to persistence it.

    -persist RfuiRfDef child object to a managed JPA entity
    -assign the child entity MANAGED RfuiRfDef to RfuiRfLgcMap object
    -persist RfuiRfLgcMap object to a managed JPA entity
    -to be complete, paste the RfuiRfLgcMap parent entity at the address now managed in the game of rfuiRfLgcMaps of the child object

    That translates into SQL statements; You cannot persist the Map object when there is firstly a RfuiRfDef record so you can store a foreign key relationship itself.

    I see a waterfall ALL slapped on everything (this is not recommended, don't use generated code as is the case, you must understand what it all does and adjust according to what is safe and necessary) - maybe it will work if you persist in fact the object of RfuiRfDef as follows:

    -create the child object RfuiRfDef
    -create the RfuiRfLgcMap object (with the game in the RfuiRfDef object)
    -stick RfuiRfLgcMap object in the game of RfuiRfDef.rfuiRfLgcMaps
    -persisted child object RfuiRfDef

  • The professional events and child master relationship

    Hi all

    Consider there are two entities in a master-child relationship, is there a way to trigger the event of business such that the payload contains several details of a row for each master.
    I guess that declaratively, we must publish log sales on master and child entities separately.
    Is there another possible way?

    Thank you
    Lalit.

    Lalit,

    Your use case makes sense to me. My personal opinion is that the docs for business events in British Colombia ADF are a little light; However, there is a paragraph that gives a hint of a glimmer of a grain of hope that can run your scenario:

    To support scenarios of composition (for example, an order to buy with invoice lines), a child
    entity can raise events defined on the entity relationship and events defined on the child
    entity can include attributes of the parent entity. When a child entity raises an event
    on a parent entity, only one event is triggered for a top-level entity given by
    transaction, no matter how many times the child entity triggers the it.

    You have a relationship defined between your master/child entities composition?

    I had not the time personally to play with log sales again, unfortunately :(

    John

  • How to run the trigger child block before the block parent?

    Y at - it anyway to run the child block trigger before master block?
    In fact, I have a parent block having 3 blocks to the child on a form. I would now, when the user runs Delete_Record integrated with a push button, then first of all it must run before you remove the trigger 2nd child block, and then click the 1st installment of the child and the parent block.
    If this sequence is not respected, form gives me error that exists to book the child and violated foreign key of the table of block parent. I already set the property of relationship to the waterfall.
    So is there a solution?

    I could have spent a little more time thinking about your question. {: 8} is the issue. Because the relationship is not cascade past the first child, an event "Dele you" don't occur in blocks of Parent and 1 child. Therefore, on child blocks 2-5 Pre - led summer triggers do not fire because there is no case of "elete" D in the blocks for the triggers to respond too. I think the best option is to use the trigger before Dele you on the parent or blocks of 1 child.
    >
    PS... I can dele given you children tables without any error of block-1 pre D elete in descending order. But I don't think it better option. >
    Hope this helps,
    Craig B-)

    If someone useful or appropriate, please mark accordingly.

    Published by: Silvere on October 14, 2010 09:01

  • LVOOP - 1 table of Parents in several bays of the child?

    I have 3 types of channels in my system. DI, I and AO.

    I want to create a Parent class that has 3 children for each of my types of channels.  It's because I want to store (on disk using flatten chain) all my channels together as an array of strings.  It's ok because I can use the 'to the more generic class"and a record in a table of my parents (CHANNEL class).

    The problem is when I read this array of objects.  I can read my array of objects parent but then I want to transform my array of objects of string into an array of objects, an array of objects HAVE and an array of objects of the DI AO.

    Any ideas?  Thank you.

    Lewis_G wrote:

    Hi nathand thanks for the ideas.  I've implemented it as you sugested.  Is there a way to make it more scalable?

    You might abuse the primitive preserve Run-Time class, as shown below. This divided the table parent tables separated for each class of the child, but the type of each element of these tables is always the parent type, even if they are transporting children. Not sure if that's what you want, or not.

    Lewis_G wrote:

    The child the more classes i, messier, fine.  Even if the code is the same for both, I can't have a Subvi generic because the child class is different for the two.  Don't you think it's a good idea to have a new class of table for each child.  For example, I could make a class with a method that has a channel enter parent and trys to add it to the guard?

    This could be very good, if it meets your needs.

    Intaris wrote:

    nathand wrote:

    Otherwise, add a method to the class called parent Type Get and override it in each class of the child, and then call on each element of the array to determine its type.

    And make sure that the type is a string, otherwise problems ensure later in life...

    I thought to mention that when I offered everything first, but then I thought that there could be situations in which an enum would work very well if you don't mind violating good OOP practices. Yes, the parent should know his children and you need to know about all children at design time, but if you can accept these terms then an enum is simple. I'm undecided about whether I would never apply this solution if I were to try to solve this problem in my own code.

  • Private data LVOOP Parent returned when the child instance created from constant

    I created a parent class and child class.  For each of these classes, I created a member who is a builder, whose purpose is to initialize constants for each class and return the instance of the class VI.  I also have an accessor Member VI for each class that returns private data of the class (in this case, a single string for each class).

    Private class data Parent 'String' is set to "text Parent" as default.

    Private data of the class of the child 'Child String' are set to 'Child text' as a default.

    The Parent class constructor works very well.  For testing purposes, I'll be back the text of unbundling of directly the manufacturer VI, as a return of the VI accessor. The Parent constructor starts from a class constant.

    However, in the case the constructor of class as a child, if I start from a class constant, unbundling directly private data (using a feature of unbundling by name and choosing "Child String" as the element), I get the private parent data!

    If I use the Member of the class of the child VI to retrieve the text, I get the private data of the child.

    If I change the constructor from a class of control instead of a constant class, I get the private data of the child.

    This occurs only until the child class has existed as a control flag. that is, if I ungroup private data, after the class is returned by any Member VI, I get the private good child data.  Then, of course, something changes once the class 'data' has been a control at a given time.

    I'm using Labview 8.6.1, Windows XP

    I have attached a small project that demonstrates the problem that I encounter, without actually doing initialization, just read.

    Is this expected behavior?  Why does it matter if I start with a constant of class instead of a control of the class?  When you slide the block diagram in the project window, you will always have a constant.

    Although I was able to reproduce your problem in LabVIEW 8.6.1, it seems to work fine in 2009.  I could not find a CAR ID, but at this point I can only assume that the behavior was not intended but it is set in 2009.

    Let me know if you need me to find more details.

  • Private class data accessible parent in the child's class?

    Hello!

    I thought this would be obvious, but my search thing fails to me.  I hope that someone would be kind enough to answer my question LVOOP of beginner.

    I have a a parent class.  This parent class contains a set of private class data.  I have Setup all the data accessor methods.  I create a child class that has functions that need to access the data stored in its parent category.  His legacy is defined, but when I try to separate data from class all that I can't do are what is configured in the cluster of data of the child class.

    I watched a video and it seemed that the DataSet magically appeared and is accessible via the methods of children.  What Miss me?

    Thanks for the input!

    -nic

    To access the data of the parent in the child's class class, you must use the accessor of reading methods you created for the parent class get the parent class data (you must use the same accessor methods in the methods of the child because all the data of the class is private in LabVIEW). I hope this helps.

    -RW

  • How can I get the child to pass under the appropriate parent based on the name?

    I'm reading an .ini file and based on the name of the group, I want that child to go under this name. If I read in another file, and he wears the same group name, that I want the child to be able to go under this name. Right now I can't even the child to pass under a different group name when it is supposed to. He continues to go by the same name of Parent. Here is my code.

    parent of int = 0;

    Ini_GetStringIntoBuffer (iniText, 'Details', 'Group', cbuf, BUFSIZE);

    InsertTreeItem (s_gMainWindow.managerTab, MANAGERTAB_TREE, VAL_SIBLING, 0,)
    VAL_NEXT, cbuf, NULL, 0, relative).

    Ini_GetStringIntoBuffer (iniText, 'Details', 'Name', cbuf, BUFSIZE);
         
    InsertTreeItem (s_gMainWindow.managerTab, MANAGERTAB_TREE, VAL_CHILD, 0,)
    VAL_LAST, cbuf, NULL, 0, relative ++);

    Ini_GetStringIntoBuffer (iniText, 'Details', 'Version', cbuf, BUFSIZE);
         
    SetTreeCellAttribute (s_gMainWindow.managerTab, MANAGERTAB_TREE, relate, 1, ATTR_LABEL_TEXT, cbuf); I can't do this correspond with the child column.

    Try this:

    parent of int = 0;

    int parent, index;

    Ini_GetStringIntoBuffer (iniText, 'Details', 'Group', cbuf, BUFSIZE);

    parent = InsertTreeItem (s_gMainWindow.managerTab, MANAGERTAB_TREE, VAL_SIBLING, 0,)
    VAL_NEXT, cbuf, NULL, 0, relative).

    Ini_GetStringIntoBuffer (iniText, 'Details', 'Name', cbuf, BUFSIZE);
    index = InsertTreeItem (s_gMainWindow.managerTab, MANAGERTAB_TREE, VAL_CHILD, parent,
    VAL_LAST, cbuf, NULL, 0, relative ++);

    Ini_GetStringIntoBuffer (iniText, 'Details', 'Version', cbuf, BUFSIZE);
    SetTreeCellAttribute (s_gMainWindow.managerTab, MANAGERTAB_TREE, index, 1, ATTR_LABEL_TEXT, cbuf);

    the idea is to keep the index of the item that you insert in order to reuse it when you want to edit the item.

Maybe you are looking for