Generate itab with dynamic number of columns

I have a method that exports a internal table to excel, XML or HTML, which works fine in many cases.
Now I want to export some special data that I want to put into an itab first.
The problem is that both the number of columns and the number of rows are dynamic.
LOOP AT (header_table)
  (for each entry, I need one column)
ENDLOOP.
LOOP AT (row_table).
  (do some calculations and add a row to the itab)
ENDLOOP.
Is there a way to generate an internal table like this?

Hi daniel,
1. There is an INDEPENDENT FORM
  whose inputs are FIELD LIST
  and from those, it consructs dynamic table.
2. Here is the program.
the dynamic table name will be
<DYNTABLE>.
3. U can use this program (FORM in this program)
to generate any kind of internal table
by specifying some inputs (ie. field list)
4.
REPORT abc.
COMPULSORY
FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.
FIELD-SYMBOLS: <dynline> TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: <fld> TYPE ANY.
DATA : fldname(50) TYPE c.
PARAMETERS : infty(4) TYPE c OBLIGATORY.
DATA : iname LIKE dd02l-tabname.
START-OF-SELECTION.
GET INFO
CONCATENATE 'P' infty INTO iname.
DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
EXPORTING
tabname = iname
TABLES
ddfields = ddfields.
CONSTRUCT FIELD LIST
LOOP AT ddfields.
ls-fieldname = ddfields-fieldname.
APPEND ls TO lt.
ENDLOOP.
PERFORM
PERFORM mydyntable USING lt.
BREAK-POINT.
INDEPENDENT FORM
FORM mydyntable USING lt TYPE lvc_t_fcat .
Create Dyn Table From FC
FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
FIELD-SYMBOLS: <fs_1>.
FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.
DATA: lt_data TYPE REF TO data.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
Assign Dyn Table To Field Sumbol
ASSIGN <fs_data>->* TO <fs_1>.
ASSIGN <fs_1> TO <fs_2>.
ASSIGN <fs_1> TO <dyntable>.
ENDFORM. "MYDYNTABLE
regards,
amit m.

Similar Messages

  • BI  Layout/Template | Table with dynamic number of columns

    hi!
    i have a problem concerning the creation of a dynamic report with the BI publisher.
    in my BI template i need a table with a dynamic number of columns. i have searched the
    forums but havent really found a solution for this type of problem.
    first of all this is A dummy-structure of my dataset:
    <ROWSET>
         <ROW>
              <FIELD1>1</FIELD2>
              <FIELD2>2</FIELD2>
              <FIELD3>3</FIELD3>
              <FIELD4>4</FIELD4>
         </ROW>
         <ROW>
              <FIELD1>a</FIELD2>
              <FIELD2>b</FIELD2>
              <FIELD3>c</FIELD3>
              <FIELD4>d</FIELD4>
         </ROW>
    </ROWSET>
    in the report the fields represent the columns i need in the table.
    the problem is, that the number of the fields vary. in this example i have 4 fields/columns
    but another time i may have 6 or 10 etc..
    my dataset is always different because i am loading my dataset via a http request which is
    returning the needed data in XML.
    is there a nativ possibility within the publisher to generate the columns dynamically?
    i read about <?split-column-header:group element name?> etc. but this is only for cross-tables.
    can anybody give me a hint how to approach this problem?
    would be very glad for some advice.
    thanks a lot in advance!

    Specific answer is here
    http://winrichman.blogspot.com/2008/09/dynamic-column.html
    but these link let you know, how to do
    http://winrichman.blogspot.com/search/label/Dynamic%20column
    http://winrichman.blogspot.com/search/label/Cross-tab
    http://winrichman.blogspot.com/search/label/cross%20tab

  • Displaying tables with dynamic number of columns

    Hello,
    I'm pretty new to JSF. Currently I'm working on a project where I have to select a table from a list, and then make it browsable/editable. The problem I have is that the different tables also have a different number of columns.
    I have no problem displaying different tables if the number of coulumns stays the same (using h:datatable) but when it's dynamic, I don't know how I can have my JSP to adjust to support the varying number of columns.
    Has anyone got an example of dynamic datatable or maybe someone can point me in the right direction.
    Brimborian

    Hi daniel,
    1. There is an INDEPENDENT FORM
      whose inputs are FIELD LIST
      and from those, it consructs dynamic table.
    2. Here is the program.
    the dynamic table name will be
    <DYNTABLE>.
    3. U can use this program (FORM in this program)
    to generate any kind of internal table
    by specifying some inputs (ie. field list)
    4.
    REPORT abc.
    COMPULSORY
    FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.
    FIELD-SYMBOLS: <dynline> TYPE ANY.
    DATA: lt TYPE lvc_t_fcat.
    DATA: ls TYPE lvc_s_fcat.
    FIELD-SYMBOLS: <fld> TYPE ANY.
    DATA : fldname(50) TYPE c.
    PARAMETERS : infty(4) TYPE c OBLIGATORY.
    DATA : iname LIKE dd02l-tabname.
    START-OF-SELECTION.
    GET INFO
    CONCATENATE 'P' infty INTO iname.
    DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.
    CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
    EXPORTING
    tabname = iname
    TABLES
    ddfields = ddfields.
    CONSTRUCT FIELD LIST
    LOOP AT ddfields.
    ls-fieldname = ddfields-fieldname.
    APPEND ls TO lt.
    ENDLOOP.
    PERFORM
    PERFORM mydyntable USING lt.
    BREAK-POINT.
    INDEPENDENT FORM
    FORM mydyntable USING lt TYPE lvc_t_fcat .
    Create Dyn Table From FC
    FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
    FIELD-SYMBOLS: <fs_1>.
    FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.
    DATA: lt_data TYPE REF TO data.
    ASSIGN lt_data TO <fs_data>.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = lt
    IMPORTING
    ep_table = <fs_data>
    EXCEPTIONS
    generate_subpool_dir_full = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    ENDIF.
    Assign Dyn Table To Field Sumbol
    ASSIGN <fs_data>->* TO <fs_1>.
    ASSIGN <fs_1> TO <fs_2>.
    ASSIGN <fs_1> TO <dyntable>.
    ENDFORM. "MYDYNTABLE
    regards,
    amit m.

  • Generating table with large number of columns (256)

    Hi,
    I don't know if this is right place for posting this:
    for data mining purposes I need a table which column names needs to be size N, where N is 2, 3 or 4. Column name is build upon alphabet of nucleotids A,C,T,G and all variations with repetition. For N=2, columns are: AA, AC, AT, AG, CA, CC, CT, CG, TA, TC, TT, TG, GA, GC, GT, GG (4^2 = 16). For N=3, 4^3 = 64, and for N=4 4^4 = 256.
    Primary key in table is array of nucleotids, and values in previously mentioned columns for each nucleotid array are 1 or 0, based on that if such nucleotid of size N exists in that chain or not.
    My questions are:
    1) is there any tool (in Oracle Data Miner or whatever) which can generate such table from array of nucleotids (one array of nucleotids is ordinary string)?
    2) It's not a problem to generate this table myself but is it "normal" to have database table with 257 columns (when N = 4)?
    I hope that my problem is clear (because of my English).
    Thanks in advance.
    Regards.

    Without knowing the reason for doing so, I would guess, this kind of design is quite poor.
    How are you planning to specify your queries? (I do know dynamic SQL would be a possibility ...).
    Another point of view:
    What if someone decides to have column names built using 5 nucleotids? This would exceed the maximum number of columns of a table which currently (10g, 11g) is 1000?

  • How to generate report with dynamic variable number of columns?

    How to generate report with dynamic variable number of columns?
    I need to generate a report with varying column names (state names) as follows:
    SELECT AK, AL, AR,... FROM States ;
    I get these column names from the result of another query.
    In order to clarify my question, Please consider following table:
    CREATE TABLE TIME_PERIODS (
    PERIOD     VARCHAR2 (50) PRIMARY KEY
    CREATE TABLE STATE_INCOME (
         NAME     VARCHAR2 (2),
         PERIOD     VARCHAR2 (50)     REFERENCES TIME_PERIODS (PERIOD) ,
         INCOME     NUMBER (12, 2)
    I like to generate a report as follows:
    AK CA DE FL ...
    PERIOD1 1222.23 2423.20 232.33 345.21
    PERIOD2
    PERIOD3
    Total 433242.23 56744.34 8872.21 2324.23 ...
    The TIME_PERIODS.Period and State.Name could change dynamically.
    So I can't specify the state name in Select query like
    SELECT AK, AL, AR,... FROM
    What is the best way to generate this report?

    SQL> -- test tables and test data:
    SQL> CREATE TABLE states
      2    (state VARCHAR2 (2))
      3  /
    Table created.
    SQL> INSERT INTO states
      2  VALUES ('AK')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('AL')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('AR')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('CA')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('DE')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('FL')
      3  /
    1 row created.
    SQL> CREATE TABLE TIME_PERIODS
      2    (PERIOD VARCHAR2 (50) PRIMARY KEY)
      3  /
    Table created.
    SQL> INSERT INTO time_periods
      2  VALUES ('PERIOD1')
      3  /
    1 row created.
    SQL> INSERT INTO time_periods
      2  VALUES ('PERIOD2')
      3  /
    1 row created.
    SQL> INSERT INTO time_periods
      2  VALUES ('PERIOD3')
      3  /
    1 row created.
    SQL> INSERT INTO time_periods
      2  VALUES ('PERIOD4')
      3  /
    1 row created.
    SQL> CREATE TABLE STATE_INCOME
      2    (NAME   VARCHAR2 (2),
      3       PERIOD VARCHAR2 (50) REFERENCES TIME_PERIODS (PERIOD),
      4       INCOME NUMBER (12, 2))
      5  /
    Table created.
    SQL> INSERT INTO state_income
      2  VALUES ('AK', 'PERIOD1', 1222.23)
      3  /
    1 row created.
    SQL> INSERT INTO state_income
      2  VALUES ('CA', 'PERIOD1', 2423.20)
      3  /
    1 row created.
    SQL> INSERT INTO state_income
      2  VALUES ('DE', 'PERIOD1', 232.33)
      3  /
    1 row created.
    SQL> INSERT INTO state_income
      2  VALUES ('FL', 'PERIOD1', 345.21)
      3  /
    1 row created.
    SQL> -- the basic query:
    SQL> SELECT   SUBSTR (time_periods.period, 1, 10) period,
      2             SUM (DECODE (name, 'AK', income)) "AK",
      3             SUM (DECODE (name, 'CA', income)) "CA",
      4             SUM (DECODE (name, 'DE', income)) "DE",
      5             SUM (DECODE (name, 'FL', income)) "FL"
      6  FROM     state_income, time_periods
      7  WHERE    time_periods.period = state_income.period (+)
      8  AND      time_periods.period IN ('PERIOD1','PERIOD2','PERIOD3')
      9  GROUP BY ROLLUP (time_periods.period)
    10  /
    PERIOD             AK         CA         DE         FL                                             
    PERIOD1       1222.23     2423.2     232.33     345.21                                             
    PERIOD2                                                                                            
    PERIOD3                                                                                            
                  1222.23     2423.2     232.33     345.21                                             
    SQL> -- package that dynamically executes the query
    SQL> -- given variable numbers and values
    SQL> -- of states and periods:
    SQL> CREATE OR REPLACE PACKAGE package_name
      2  AS
      3    TYPE cursor_type IS REF CURSOR;
      4    PROCEDURE procedure_name
      5        (p_periods   IN     VARCHAR2,
      6         p_states    IN     VARCHAR2,
      7         cursor_name IN OUT cursor_type);
      8  END package_name;
      9  /
    Package created.
    SQL> CREATE OR REPLACE PACKAGE BODY package_name
      2  AS
      3    PROCEDURE procedure_name
      4        (p_periods   IN     VARCHAR2,
      5         p_states    IN     VARCHAR2,
      6         cursor_name IN OUT cursor_type)
      7    IS
      8        v_periods          VARCHAR2 (1000);
      9        v_sql               VARCHAR2 (4000);
    10        v_states          VARCHAR2 (1000) := p_states;
    11    BEGIN
    12        v_periods := REPLACE (p_periods, ',', ''',''');
    13        v_sql := 'SELECT SUBSTR(time_periods.period,1,10) period';
    14        WHILE LENGTH (v_states) > 1
    15        LOOP
    16          v_sql := v_sql
    17          || ',SUM(DECODE(name,'''
    18          || SUBSTR (v_states,1,2) || ''',income)) "' || SUBSTR (v_states,1,2)
    19          || '"';
    20          v_states := LTRIM (SUBSTR (v_states, 3), ',');
    21        END LOOP;
    22        v_sql := v_sql
    23        || 'FROM     state_income, time_periods
    24            WHERE    time_periods.period = state_income.period (+)
    25            AND      time_periods.period IN (''' || v_periods || ''')
    26            GROUP BY ROLLUP (time_periods.period)';
    27        OPEN cursor_name FOR v_sql;
    28    END procedure_name;
    29  END package_name;
    30  /
    Package body created.
    SQL> -- sample executions from SQL:
    SQL> VARIABLE g_ref REFCURSOR
    SQL> EXEC package_name.procedure_name ('PERIOD1,PERIOD2,PERIOD3','AK,CA,DE,FL', :g_ref)
    PL/SQL procedure successfully completed.
    SQL> PRINT g_ref
    PERIOD             AK         CA         DE         FL                                             
    PERIOD1       1222.23     2423.2     232.33     345.21                                             
    PERIOD2                                                                                            
    PERIOD3                                                                                            
                  1222.23     2423.2     232.33     345.21                                             
    SQL> EXEC package_name.procedure_name ('PERIOD1,PERIOD2','AK,AL,AR', :g_ref)
    PL/SQL procedure successfully completed.
    SQL> PRINT g_ref
    PERIOD             AK         AL         AR                                                        
    PERIOD1       1222.23                                                                              
    PERIOD2                                                                                            
                  1222.23                                                                              
    SQL> -- sample execution from PL/SQL block
    SQL> -- using parameters derived from processing
    SQL> -- cursors containing results of other queries:
    SQL> DECLARE
      2    CURSOR c_period
      3    IS
      4    SELECT period
      5    FROM   time_periods;
      6    v_periods   VARCHAR2 (1000);
      7    v_delimiter VARCHAR2 (1) := NULL;
      8    CURSOR c_states
      9    IS
    10    SELECT state
    11    FROM   states;
    12    v_states    VARCHAR2 (1000);
    13  BEGIN
    14    FOR r_period IN c_period
    15    LOOP
    16        v_periods := v_periods || v_delimiter || r_period.period;
    17        v_delimiter := ',';
    18    END LOOP;
    19    v_delimiter := NULL;
    20    FOR r_states IN c_states
    21    LOOP
    22        v_states := v_states || v_delimiter || r_states.state;
    23        v_delimiter := ',';
    24    END LOOP;
    25    package_name.procedure_name (v_periods, v_states, :g_ref);
    26  END;
    27  /
    PL/SQL procedure successfully completed.
    SQL> PRINT g_ref
    PERIOD             AK         AL         AR         CA         DE         FL                       
    PERIOD1       1222.23                           2423.2     232.33     345.21                       
    PERIOD2                                                                                            
    PERIOD3                                                                                            
    PERIOD4                                                                                            
                  1222.23                           2423.2     232.33     345.21                       

  • Dynamic Number of Column in a table

    Hi guys,
    I have a requirement that needs dynamic number of column in a tale.
    It is possible to do this in Adobe forms.
    Thanks,
    Chirantan

    Hello. It of course is possible in Adobe.
    You need to write a simple script using JavaScript or FormCalc to hide or show columns according to some special value. You will work with the presence attribute of the object. E.g. MYFIELD.presence = "visible" or "hidden" or "invisible". You will need to change your subforms content to flowed.
    Use these guides:
    http://www.adobe.com/devnet/livecycle/articles/lc_designer_scripting_basics/lc_designer_scripting_basics.pdf
    help.adobe.com/en_US/livecycle/es/FormCalc.pdf
    Hope this helps, good luck, Otto

  • Can we create JTable with multiple rows with varying number of columns ?

    Hi All,
    I came across a very typical problem related to JTable. My requirement is that cells should be added dynamically to the JTable. I create a JTable with initial size of 1,7 (row, columns) size. Once the 7 columns are filled with data, a new row should be created. But the requirement is, the new row i.e. second row should have only one cell in it initially. The number of cells should increase dynamically as the data is entered. The table is automatically taking the size of its previous row when new row is added. I tried by using setColumnCount() to change the number of columns to '1' for the second row but the same is getting applied to the first row also.
    So can you please help me out in this regard ? Is it possible to create a JTable of uneven size i.e. multiple rows with varying number of columns in each row ?
    Thanks in Advance.

    Well a JTable is always going to paint the same number of columns for each row. Anything is possible if you want to rewrite the JTable UI to do this, but I wouldn't recommend it. (I certainly don't know how to do it).
    A simpler solution might be to override the isCellEditable(...) method of JTable and prevent editing of column 2 until data in column 1 has been entered etc., etc. You may also want to provide a custom renderer that renderers the empty column differently, maybe with a grey color instead of a white color.

  • How to create a table with varied number of columns?

    I am trying to create a balance table. The colunms should include years between the start year and end year the user will input at run time. The rows will be the customers with outstanding balance in those years.
    If the user input years 2000 and 2002, the table should have columns 2000, 2001, 2002. But if the user input 2000 and 2001, the table will only have columns 2000 and 2001.
    Can I do it? How? Thanka a lot.

    Why did you create a new thread for this?
    How to create a table with varied number of columns?

  • How can i export the data to excel which has 2 tables with same number of columns & column names?

    Hi everyone, again landed up with a problem.
    After trying a lot to do it myself, finally decided to post here..
    I have created a form in form builder 6i, in which on clicking a button the data gets exported to excel sheet.
    It is working fine with a single table. The problem now is that i am unable to do the same with 2 tables.
    Because both the tables have same number of columns & column names.
    Below are 2 tables with column names:
    Table-1 (MONTHLY_PART_1)
    Table-2 (MONTHLY_PART_2)
    SL_NO
    SL_NO
    COMP
    COMP
    DUE_DATE
    DUE_DATE
    U-1
    U-1
    U-2
    U-2
    U-4
    U-4
    U-20
    U-20
    U-25
    U-25
    Since both the tables have same column names, I'm getting the following error :
    Error 402 at line 103, column 4
      alias required in SELECT list of cursor to avoid duplicate column names.
    So How can i export the data to excel which has 2 tables with same number of columns & column names?
    Should i paste the code? Should i post this query in 'SQL and PL/SQL' Forum?
    Help me with this please.
    Thank You.

    You'll have to *alias* your columns, not prefix it with the table names:
    $[CHE_TEST@asterix1_impl] r
      1  declare
      2    cursor cData is
      3      with data as (
      4        select 1 id, 'test1' val1, 'a' val2 from dual
      5        union all
      6        select 1 id, '1test' val1, 'b' val2 from dual
      7        union all
      8        select 2 id, 'test2' val1, 'a' val2 from dual
      9        union all
    10        select 2 id, '2test' val1, 'b' val2 from dual
    11      )
    12      select a.id, b.id, a.val1, b.val1, a.val2, b.val2
    13      from data a, data b
    14      where a.id = b.id
    15      and a.val2 = 'a'
    16      and b.val2 = 'b';
    17  begin
    18    for rData in cData loop
    19      null;
    20    end loop;
    21* end;
      for rData in cData loop
    ERROR at line 18:
    ORA-06550: line 18, column 3:
    PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names
    ORA-06550: line 18, column 3:
    PL/SQL: Statement ignored
    $[CHE_TEST@asterix1_impl] r
      1  declare
      2    cursor cData is
      3      with data as (
      4        select 1 id, 'test1' val1, 'a' val2 from dual
      5        union all
      6        select 1 id, '1test' val1, 'b' val2 from dual
      7        union all
      8        select 2 id, 'test2' val1, 'a' val2 from dual
      9        union all
    10        select 2 id, '2test' val1, 'b' val2 from dual
    11      )
    12      select a.id a_id, b.id b_id, a.val1 a_val1, b.val1 b_val1, a.val2 a_val2, b.val2 b_val2
    13      from data a, data b
    14      where a.id = b.id
    15      and a.val2 = 'a'
    16      and b.val2 = 'b';
    17  begin
    18    for rData in cData loop
    19      null;
    20    end loop;
    21* end;
    PL/SQL procedure successfully completed.
    cheers

  • Table with varying number of columns

    Hello experts,
    my issue:
    I need to print a table with varying number of columns. Depending on if all cells of a certain column are initial the
    whole column should disappear. Hiding is not enough.
    If this columns is in the middle of the table the following columns should move left to fill the gap.
    my approach: (maybe there is an easier one)
    There are 4 different possible situations. My approach was to create 4 different tables with different amount of
    columns. In the interface I fill the table that is really needed from the source table data and fill a flag that characteristics
    the situation, possible values (1,2,3,4).
    In the form I'd like to print the appropriate table depending on the situations.
    my problem:
    How to place all 4 possible tables lying upon each other in the form and print only the needed one depending on the flag value?
    my question:
    Is my approach ok? Or is there an easier one?
    If it is ok. How can I solve the problem regarding printing the right table.
    Thanks in advance!
    Heinz

    Hi Heinz,
    You can handle it with FormCalc Script at initialization.
    Suppose you have a table with name TABLE having a header HEADER and data row DATA:
    TABLE-->HEADER(Cell1...Cell2...Cell3...Cell4)
              --->DATA(Cell1...Cell2...Cell3...Cell4)
    Suppose you want to hide Cell3 for null values, then write below code at initialization of DATA:
    if(DATA[*].Cell3.rawValue eq null)
    then
    DATA[*].Cell3.presence = "hidden"
    HEADER.Cell3.presence = "hidden"
    else
    DATA[*].Cell3.presence = "visible"
    HEADER.Cell3.presence = "visible"
    endif
    Hope it would help.
    Regards,
    Vaibhav

  • DB view with flexible number of columns?

    In my Oracle 10 I have these tables
    Customer table:
    id      customer
    1       John
    2       Bob
    Item table
    id      item_name
    1       itemA
    2       itemB
    3       itemC
    4       itemD
    Purchase table:
    id      item_id date    customer_id
    1       3       070202  2
    2       6       070203  5
    ...I'd like to create a view like this:
            itemA   itemB   itemC   itemD   ...
    John    3       4       0       0       ...
    Bob     0       3       0       0       ...
    ...The view showed John purchased itemA 3 times, item B 4 times. Bob purchased itemB 3 times. This assume each customer only by one item at a time, which is a reasonable simplification of my situation.
    Such a view (with variable number of columns) is needed not in our web application but also provide an understandable data source for non IT professional to use report software. If my approach of solving this problem is completely wrong, I'd also like to know what's the common practice. Thank you very much in advance!
    Message was edited by:
    user609663

    I have tried to ask the question in a way that greatly simplify current problem to make it easy for others to understand without having to explain a lot of background information and 'the situation'; it seems I over-simplified the issue to make it even not worth solving or a wrong question being asked. So here I explain the complete problem and look for advice again (be prepared, pretty long description following:). I am a purchased customer of Oracle 10 DB and I reasonably expect being considered as Oracle user looking for help rather than students trying to play smart with assigned data normalization course exercises.
    We are working on a system that collects data from interview results. The questionnaires for the interviews are formatted with a coded question, followed by user's answer to the question, like the following:
         Question Code   Question content   Answer
         H001            ...                123
         H002            ...                45
         H003            ...                33
         H004            ...                66
         H005            ...                4,66
         ...             ...                ...The users answer question with a digit, for some special questions, e.g. H005, they are allowed to answer with a set of digits. There are thousands of interviews each year, the simplest solution to collect the interview answers is to use such a db table:
    simple_db_table:
    id   H001  H002  H003  H004  H005  H006  H007
    1    123   45    33    66    4     82    9
    ...This solution have two problems:
    1. It doesn't properly store answers to questions that requre a set of digits, like H005.
    2. The number of questions and their codes change from one survey to another, but the table have fixed number of columns and column names.
    And two benefit:
    1. With such simple table, people who use report software that directly access oracle db can creat their reports on easy-to-understand data presentation;
    2. calculation based on questionnaire data is simple, e.g. get the average of H007/H009 for questionnaires that have H002 > H003 * 600 would be:
    SELECT SUM(H007) / SUM(H009) FROM simple_db_table WHERE H002 > H003 * 600;Next solution we have normalized tables:
    questionnaire_entry_table:
    id                 NUMBER
    questionnaire_name CHARquestionnaire_definition_table:
    id                 NUMBER
    questionnaire_id   NUMBER
    question_code      CHAR
    question_content   VARHCARinterview_table:
    id                 NUMBER
    questionnaire_id   NUMBER
    date               DATEquestionnaire data table: itv_data
    id                 NUMBER
    interview_id       NUMBER
    question_code      CHAR
    answer             NUMBERWith the new structure, it just turn the problems of simple_db_table to its benefit and simple_db_table's benefit become the problem:
    1. Personnel who use report creation software feel too confused to make report based on such tables, because they do not understand the normalized modeling. In our case, effective training is difficult because there will be many geographically distributed people make reports based on this structure and they have lower IT knowledge than database administrators. These personnel can make reports based on simple_db_table.
    2. calculation based on questionnaire data is very difficult.
    To explain 2, let's take the same example, we still wish to get the average of H007/H009 for questionnaires that have H002 > H003 * 600, my method is:
    setp 1: create a view with by using:
           CREATE VIEW v (id, H002, H003) AS
           SELECT a.itv_id, a.H002, b.H003
             FROM itv_data a, itv_data b
           WHERE a.interviewee_id=b.interviewee_id
             AND a.question_code='H002' AND b.question_code='H003';step 2: create a stored procedure to get the calculation result:
           CREATE OR REPLACE PROCEDURE get_result (result OUT NUMBER) IS
             sh007 NUMBER := 0;
             sh009 NUMBER := 0;
           BEGIN
             SELECT SUM(H007) INTO sh007 FROM itv_data
               WHERE itv_id in (SELECT id FROM v WHERE H002 > H003 * 683);
             SELECT SUM(H009) INTO sh009 FROM itv_data
               WHERE itv_id in (SELECT id FROM v WHERE H002 > H003 * 683);
             idc := sh007/sh009;
           END get_idc;As you can see the calculation become much more complex and might involve overhead.
    There might be better way to calculate the result that I don't know yet. We have some 100 different formulas to calculate different results, so it's important to get them right and efficiently.
    The best solution seems to me is that to create such a view from itv_data and other tables so that to reflect the same structure of simple_db_table. So here comes the question I originally asked how is it possible to create a view with flexible number of columns. I made the very simple example in my original posted message wishing to get an idea of this is possible or the way to go.
    I may be taking a completely wrong approach to attack the problem, e.g. perhaps there is a simpler way to get_result from itv_table and for report creation users I should use a metadata layer on top of the normalized table structure (e.g. by using Metadata Query Language from Pentaho BI). But anyway I'd like to get some insightful ideas from the forum. Again thanks for help in advance.

  • How to pipeline a function with a dynamic number of columns?

    Hi everyone,
    I'm trying to figure out how to write a piplined function that generates a dynamic SQL statement from its inputs, executes the query, and returns the results of the query in the pipeline. The number and names of the columns in the dynamic query is unknown number until the function is invoked.
    I suspect that DBMS_SQL is involved, but can't quite figure out how to construct a row using it that I can use PIPE ROW on. I also can't figure out what data type the function should return (ANYDATASET?)
    pseudo-PLSQL follows:
    create function myfunction ( param1 varchar2)
    return anydataset pipelined
    as
    query_string := <... do stuff with param1 ...>
    < -- >
    open a cursor for query_string
    determine the number of columns
    read a row
    PIPE ROW it
    <--->
    Can what I'm trying to do be done?
    Thanks,
    Keith

    The following works on 10R2
    create or replace type NColPipe as object
      l_parm varchar2(10),   -- The parameter given to the table function
      rows_requested number, -- The parameter given to the table function
      ret_type anytype,      -- The return type of the table function
      rows_returned number,  -- The number of rows currently returned by the table function
      static function ODCITableDescribe( rtype out anytype, p_parm in varchar2, p_rows_req in number := 2 )
      return number,
      static function ODCITablePrepare( sctx out NColPipe, ti in sys.ODCITabFuncInfo, p_parm in varchar2, p_rows_req in number := 2 )
      return number,
      static function ODCITableStart( sctx in out NColPipe, p_parm in varchar2, p_rows_req in number := 2 )
      return number,
      member function ODCITableFetch( self in out NColPipe, nrows in number, outset out anydataset )
      return number,
      member function ODCITableClose( self in NColPipe )
      return number,
      static function show( p_parm in varchar2, p_rows_req in number := 2 )
      return anydataset pipelined using NColPipe
    create or replace type body NColPipe as
      static function ODCITableDescribe( rtype out anytype, p_parm in varchar2, p_rows_req in number := 2 )
      return number
      is
        atyp anytype;
      begin
        anytype.begincreate( dbms_types.typecode_object, atyp );
        if p_parm = 'one'
        then
          atyp.addattr( 'one'
                      , dbms_types.typecode_varchar2
                      , null
                      , null
                      , 10
                      , null
                      , null
        elsif p_parm = 'two'
        then
          atyp.addattr( 'one'
                      , dbms_types.typecode_varchar2
                      , null
                      , null
                      , 10
                      , null
                      , null
          atyp.addattr( 'two'
                      , dbms_types.typecode_varchar2
                      , null
                      , null
                      , 10
                      , null
                      , null
        else
          atyp.addattr( p_parm || '1'
                      , dbms_types.typecode_varchar2
                      , null
                      , null
                      , 10
                      , null
                      , null
          atyp.addattr( p_parm || '2'
                      , dbms_types.typecode_varchar2
                      , null
                      , null
                      , 10
                      , null
                      , null
          atyp.addattr( p_parm || '3'
                      , dbms_types.typecode_number
                      , 10
                      , 0
                      , null
                      , null
                      , null
        end if;
        atyp.endcreate;
        anytype.begincreate( dbms_types.typecode_table, rtype );
        rtype.SetInfo( null, null, null, null, null, atyp, dbms_types.typecode_object, 0 );
        rtype.endcreate();
        return odciconst.success;
      exception
        when others then
          return odciconst.error;
      end;  
      static function ODCITablePrepare( sctx out NColPipe, ti in sys.ODCITabFuncInfo, p_parm in varchar2, p_rows_req in number := 2 )
      return number
      is
        elem_typ sys.anytype;
        prec pls_integer;
        scale pls_integer;
        len pls_integer;
        csid pls_integer;
        csfrm pls_integer;
        tc pls_integer;
        aname varchar2(30);
      begin
        tc := ti.RetType.GetAttrElemInfo( 1, prec, scale, len, csid, csfrm, elem_typ, aname );
        sctx := NColPipe( p_parm, p_rows_req, elem_typ, 0 );
        return odciconst.success;
      end;
      static function ODCITableStart( sctx in out NColPipe, p_parm in varchar2, p_rows_req in number := 2 )
      return number
      is
      begin
        return odciconst.success;
      end;
      member function ODCITableFetch( self in out NColPipe, nrows in number, outset out anydataset )
      return number
      is
      begin
        anydataset.begincreate( dbms_types.typecode_object, self.ret_type, outset );
        for i in self.rows_returned + 1 .. self.rows_requested
        loop
          outset.addinstance;
          outset.piecewise();
          if self.l_parm = 'one'
          then
            outset.setvarchar2( to_char( i ) );
          elsif self.l_parm = 'two'
          then
            outset.setvarchar2( to_char( i ) );
            outset.setvarchar2( 'row: ' || to_char( i ) );
          else
            outset.setvarchar2( 'row: ' || to_char( i ) );
            outset.setvarchar2( 'row: ' || to_char( i ) );
            outset.setnumber( i );
          end if;
          self.rows_returned := self.rows_returned + 1;
        end loop;
        outset.endcreate;
        return odciconst.success;
      end;
      member function ODCITableClose( self in NColPipe )
      return number
      is
      begin
        return odciconst.success;
      end;
    end;
    /And to use it
    SQL> select * from table( NColPipe.show( 'test', 3 ) );
    test1      test2           test3
    row: 1     row: 1              1
    row: 2     row: 2              2
    row: 3     row: 3              3
    SQL>  select * from table( NColPipe.show( 'two', 5 ) );
    one        two
    1          row: 1
    2          row: 2
    3          row: 3
    4          row: 4
    5          row: 5
    SQL> select * from table( NColPipe.show( 'one' ) );
    one
    1
    2
    SQL> Anton

  • PLSQL-generated SQL report with variable number of columns

    I created an app to track college football bowl picks:
    http://apex.oracle.com/pls/otn/f?p=21723
    The main report region includes columns for the various games as well as a column for each participant. In order not to hard code the number of participants, I used PLSQL to generate the SQL so that new columns could be added on the fly.
    However, whenever I add a new user I get this result -
    report error:
    ORA-01403: no data found
    If I copy and paste the PLSQL into a new report region and then delete the old one, however, all is well.
    Is there something I can do to overcome this?
    Thanks.
    Bill

    Roberto
    <br><br>
    Here are the tables:
    <br><br>
    BOWL_GAMES<br>
    ID     NUMBER<br>
    NAME     VARCHAR2(30)<br>
    FAV     VARCHAR2(20)<br>
    DOG     VARCHAR2(20)<br>
    BDATE     DATE<br>
    LINE     NUMBER(3,1)<br>
    FAV_SCORE     NUMBER(4,0)<br>
    DOG_SCORE     NUMBER(4,0)<br>
    <br>
    BOWL_USERS<br>
    ID     NUMBER<br>
    USERNAME     VARCHAR2(20)<br>
    PW     VARCHAR2(20)<br>
    NAME     VARCHAR2(20)<br>
    EMAIL     VARCHAR2(50)<br>
    <br>
    BOWL_PICKS<br>
    ID     NUMBER(5,0)<br>
    USERID     NUMBER(10,0)<br>
    GAMEID     NUMBER(10,0)<br>
    PICK     NUMBER(1,0)<br>
    <br>
    <br>
    Below is my PLSQL. Feel free to try out the app. Thanks.
    <br><br>
    Bill<br><br>
    declare<br>
    p_sql varchar2(32767);<br>
    cursor c1 is select * from bowl_users order by id;<br>
    begin<br>
    p_sql := q'! select to_char(b.bdate, 'Mon FMdd') "Date", b.name, '< a href="javascript$pickEm(''' || b.fav || ''')">' || b.fav || '</ a> -' || b.line || ' < a href="javascript$pickEm(''' || b.dog || ''')">' || b.dog || '</ a>' "Line" !';<br>
    for a1 in c1 loop<br>
    p_sql := p_sql || q'! , bowl_strike(b.id, !' || a1.id || q'! , 0) || (select decode(p.pick, 0, substr(b.dog,1,4), 1, substr(b.fav,1,4), 'No pick') from bowl_picks p where p.userid = !' || a1.id || q'! and p.gameid = b.id) || bowl_strike(b.id, !' || a1.id || q'! , 1) "!' || upper(a1.name) || q'!" !';<br>
    end loop;<br>
    p_sql := p_sql || q'! , bowl_score(b.id) "SCORE" from bowl_games b order by b.bdate !';<br>
    return replace(p_sql,'$',':');<br>
    end;
    <br><br>
    Message was edited by:
    [email protected]

  • How to create a Type Object with Dynamic select query columns in a Function

    Hi Every One,
    I'm trying to figure out how to write a piplined function that executes a dynamic select query and construct a Type Object in order to assigned it to the pipe row.
    I have tried by
    SELECT a.DB_QUERY INTO actual_query FROM mytable a WHERE a.country_code = 'US';
    c :=DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE(c,actual_query,DBMS_SQL.NATIVE);
    l_status := DBMS_SQL.EXECUTE(c);
    DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
    FOR j in 1..col_cnt LOOP
    DBMS_SQL.DEFINE_COLUMN(c,j,v_val,2000);
    END LOOP;
    FOR j in 1..col_cnt LOOP
    DBMS_SQL.COLUMN_VALUE(c,j,v_val);
    END LOOP;
    But got stuck, how to iterate the values and assign to a Type Object from the cursor. Can any one guide me how to do the process.
    Thanks,
    mallikj2

    Hi Justin,
    First of thanks for your reply, and coming to my requirement, I need to report the list of items which are there in the dynamic select statement what am getting from the DB. The select statement number of columns may vary in my example for different countries the select item columns count is different. For US its '15', for UK it may be 10 ...like so, and some of the column value might be a combination or calculation part of other table columns (The select query contains more than one table in the from clause).
    In order to execute the dynamic select statement and return the result i choose to write a function which will parse the cursor for dynamic query and then iterate the values and construct a Type Object and append it to the pipe row.
    Am relatively very new for these sort of things, welcome in case of any suggestions to make it simple (Instead of the function what i thought to work with) also a sample narrating the new procedure will be appreciated.
    Thanks in Advance,
    mallikj2.

  • Report with indefinite number of columns

    Hello,
    I'm using VB.NET and Crystal Reports 2008 for my Windows application.
    I've a new report to implement. It's a budgetting report in a table form, which shows the amount of money allocated to a certain projects over a range of years. In each row I show the different projects, in each column I show the budget of each project per year. Users can select the number of years to print (as a parameter), that means, the number of columns is dynamic.
    My question is, how am I going to design this report? Will cross-tab help? My report will be in landscape format. The page width is enough for 8 columns, i.e. 8 years can be printed per table. If users choose to print more than 8 years, the "extra" columns should be printed on a new table underneath the one with the first 8 years, or on a new page if there's not enough space underneath.
    Your help and suggestions would be much appreciated. Thank you very much.
    Agnes

    use conditional supressions on the fields in the colums so based upon parameter selection it will display what is shown
    insert a section below the other and then use the conditional supression based upon the selection of 8+
    cross tabs have limitations and are hard to read.

Maybe you are looking for

  • Can not update iPod Nano, brand new and error says there is not enough room

    I just purchased my son a 1 gig nano. After registering and setting up options for updates. I got a message saying that it could not update because there wasn't enough room. I was trying to download less than 100 songs and all of them have been downl

  • Object with a mind of its own

    hi.... i have two objects currently sharing a layer, and i have used various behaviours and filters on them already, separately as individual objects AND together as a layer. no problem UNTIL i tried to change the rotation of one of the objects in th

  • Deployment Failed

    HI OTN I encounter this error message when i try to run my application: *** Using port 7101 *** C:\Users\shirleen\AppData\Roaming\JDeveloper\system11.1.1.1.33.54.07\DefaultDomain\bin\startWebLogic.cmd [waiting for the server to complete its initializ

  • Synchronous interface ...

    Hi, I've a scenario using a BPM where a receive an synchronous message and after that i've to split it into other two msgs. One of those two messages is the input message of my synchronous interface and it works as the response of the initial request

  • [SOLVED] Syslinux. Installing bootloader.

    Hello, I have an Acer Aspire M3-581TG, which comes with 20Gb mSSD and 500Gb HDD. For some reason mSSD can't be bootable, so if I try to install any operating system with automatic installation on this drive, it creates MBR boot sector on my HDD. I wo