Dynamic creation of table with variable field-names

HI
I am looking for a way in order to create a table during runtime. The problem is that the field names of the table are provided in another table.
TO illustrate the case at hand, an example:
The initial table contains the fields
UserID - attribut_name - attribute_value
Example Data
d00587 - first_name    - Jon
d00587 - last_name     - Smith
d00587 - age           - 48
d00127 - first_name    - Jack
d00127 - last_name     - Daniels
d00127 - position      - Manager
Now I need to create a table per User that looks as follows:
for user d00587
first_name  -  last_name  -  age
**Values
Jon         -  Smith      -  48
for user d00127
first_name  -  last_name  -  positioin
Jack        -  Daniels    -  Manager
I split the initial table by sorting it according to userID and then looping into an itab with an AT END OF userid, thus I receive the table per user:
Example iTab
UserID - attribut_name - attribute_value
Example Data
d00587 - first_name    - Jon
d00587 - last_name     - Smith
d00587 - age           - 48
However I have no clue on how to create a new internal table with field-names = attribute_name.
Does anybody have an idea or example code for this?
Thanks a lot for your help,
Kind regards,
Mingolo

Hello Minima
Here is some sample coding:
DATA:
  gt_fcat  type lvc_t_fcat,
  gdo_data TYPE REF TO data.
FIELD-SYMBOLS:
  <gt_itab> TYPE table.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
  EXPORTING
*     I_BUFFER_ACTIVE              =
    i_structure_name             = 'MARA'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
  CHANGING
    ct_fieldcat                  = gt_fcat
  EXCEPTIONS
    inconsistent_interface       = 1
    program_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.
CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
*      I_STYLE_TABLE             =
    it_fieldcatalog           = gt_fcat
  IMPORTING
    ep_table                  = gdo_data
*      E_STYLE_FNAME             =
  EXCEPTIONS
    generate_subpool_dir_full = 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.
ASSIGN gdo_data->* TO <gt_itab>.
In your case, you would call the function module with your tables (D00587, D00127). Remove all fields from the fieldcatalog that you do not need before calling the static method.
Regards
  Uwe

Similar Messages

  • Internal Table with variable field lengths

    Hi Guys,
    I have a requirement to populate an internal table whose structure is as follows.
    Internal Table will have 5 lines.
    Line1: 050 char
    Line2: 100 char
    Line3: 100 char
    Line4: 100 char
    Line5: 050 char.
    I have all the required data with me. I just need to populate the table.
    Reward points up for grabs
    Regards,
    Suhas

    Hi,
    Wher do you have the data?
    You can define a work area and internal table of two rows..
    wa-row1 = 'yourdata'
    wa-row2 = 'your data'
    append wa to itab.
    wa-row1 = 'yourdata'
    wa-row2 = 'your data'
    append wa to itab.
    wa-row1 = 'yourdata'
    wa-row2 = 'your data'
    append wa to itab.
    wa-row1 = 'yourdata'
    wa-row2 = 'your data'
    append wa to itab.
    wa-row1 = 'yourdata'
    wa-row2 = 'your data'
    append wa to itab.
    If you have your data in Db table then you need to write a select query..
    select <fields,,,> from DBtable into tableITAb.
    Be clear with your question we can help you...
    rewads if useful,
    regards,
    nazeer

  • Sorting internal table with variable no of fields

    Hi ,
    I want to sort the internal table with variable no of fields . Every time the  report is run the number of fields as well as the sequence by which the table has to be sorted changes . How to do this .
    regards

    Hi,
    Please try this.
    DATA: BEGIN OF ITAB OCCURS 0,
            F1(4),
          END OF ITAB.
    DATA: BEGIN OF ITAB2 OCCURS 0,
            F1(1),
            F2(1),
            F3(4),
          END OF ITAB2.
    ITAB-F1 = '01AC'.
    APPEND ITAB.
    ITAB-F1 = '02AB'.
    APPEND ITAB.
    ITAB-F1 = '01CD'.
    APPEND ITAB.
    ITAB-F1 = '02CA'.
    APPEND ITAB.
    LOOP AT ITAB.
      ITAB2-F1 = ITAB-F1+2(1).
      ITAB2-F2 = ITAB-F1+3(1).
      ITAB2-F3 = ITAB-F1.
      APPEND ITAB2.
    ENDLOOP.
    SORT ITAB2 BY F1 ASCENDING
                  F2 DESCENDING.
    LOOP AT ITAB2.
      WRITE: / ITAB2-F3.
    ENDLOOP.
    REWARD POINTS IF HELPFUL

  • How can I check if there is a table with the given name ?

    I'm using 8i and 9i.
    Could anybody teach me how to check if there is a table with a certain name in SQLPLUS without using SELECT
    statement ?
    I want to use the following logical procedure.
    if exists "table_to_be_deleted" then drop table "table_to_be_deleted"
    Or, is there any system table that I can check the names of tables like
    count = select "table_to_be_deleted" from "an_oracle_system_table"
    if ( count != 0 ) then drop table "table_to_be_deleted"
    Thanks,
    John

    Just create it, but be aware that DDLs can't be executed directly from Pl/Sql, so you'll have to use dynamic Sql, e.g. :
    SQL> create table test(a number);
    Table created.
    SQL> begin
      2  drop table test;
      3  exception
      4  when others then
      5  null;
      6  end;
    SQL> /
    drop table test;
    ERROR at line 2:
    ORA-06550: line 2, column 1:
    PLS-00103: Encountered the symbol "DROP" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe
    SQL> ed
    Wrote file afiedt.buf
      1  begin
      2  execute immediate 'drop table test';
      3  exception
      4  when others then
      5  null;
      6* end;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL>Now the table does not exist anymore, but further executions will not generate errors, due to the exception handler :
    SQL> desc test
    ERROR:
    ORA-04043: object test does not exist
    SQL> /
    PL/SQL procedure successfully completed.
    SQL>

  • Pivot table with variables columns

    I need a helo to pivot table with variable columns,
    I have a pivot table :
    SELECT a.*
    FROM (SELECT codigo_aluno,nome_aluno , id_curso,dia FROM c_frequencia where dia like '201308%') PIVOT (sum(null)   FOR dia IN ('20130805' ,'20130812','20130819','20130826')) a
    but I need to run the select with values for dia , getting from a other table :
    SELECT a.*
    FROM (SELECT codigo_aluno,nome_aluno , id_curso,dia FROM c_frequencia where dia like '201308%') PIVOT (sum(null)   FOR dia IN (
    select dia from v_dia_mes )) a
    thank you

    The correct answer should be "Use the Pivoted Report Region Plugin".
    But, as far as I know, nobody has created/posted that type of APEX plugin.
    You may have to use a Basic Report (not an IR) so that you can use "Function returning SELECT" for your Source.
    You would need two functions:
    One that dynamically generates the Column Names
    One that dynamically generates the SELECT statement
    These should be in a PL/SQL Package so that the later can call the former to ensure that the column data matches the column names.
    i.e. -- no 'SELECT *'
    MK

  • How to create table with variable

    hi,
    i m to create many table with same starting name but last name would be vary like
    i m to create table test121 and test122 and so on
    i want to set name test then any given number by variable so i can create many table.
    so how to add it in create table command.
    i tried create table test||:var (column names) but it didnt work.
    so plz suggest me how to do it ?
    thxs

    Actually this is good.
    It has nothing to do with database design. A database is not a garbage bin.
    You need to do several things
    a) make sure your design is normalized so you don't have identical tables.
    b) In future posts specify a platform and a version and the tool you are using to create the table
    c) if the tool is sql*plus learn about substitution variables aka DEFINEs.
    Sybrand Bakker
    Senior Oracle DBA

  • How to insert a table with variable rows in smart form

    Hi all,
    How to insert a table with variable rows in smart form?
    Any help would be appreciated.
    Regards,
    Mahesh.

    Hi,
    Right click the mouse->create->table
    If you want 5 columns, you need to declare 5 cells in one line type of the table
    Click on Table -> Details, then do the following
    Line Type 1 2 3 4 5
    L1 2mm 3mm etc
    Here specify the width of the columns as many as you want..
    then in the header/main area of the table, click create Table Line, Rowtype is L1, automatically 5 cells will come,In each cell create a text element, display the variable to be printed there.

  • Finding a table with a like %name% in a schema

    What is the query I should use to find a table with a like %name% in a schema?
    Thank you for any help

    select * from all_tables
    where owner = 'YOUR_SCHEMA' and lower(table_name) like '%name%'
    /Regards
    Dmytro

  • Is it possible to have 2 tables with the same name in an Orable database?

    Hello,
    I'm a complete Oracle newbie so please excuse my question if it's stupid.
    I was trying to create 2 tables with the same name using different tablespaces but it does not seem to work. Like this (second time just change the name of the tablespace):
    CREATE TABLE test_tbl (
      id INTEGER,
      status VARCHAR2(10),
      last_modified DATE DEFAULT SYSDATE
    TABLESPACE tblspc1Is it in general in Oracle possible to acquire this goal?
    Thanks a lot!
    P.S. I have already created the needed tablespaces
    CREATE TABLESPACE tblspc1 DATAFILE 'tblspc1.dbf' SIZE 10MEdited by: 808239 on 02-Mar-2011 02:18

    It is not possible to create two tables with same name in same schema.
    A user can own one schema with his own name and another with the schema name SYS.
    For this you have to grant sysdba privilage to the user and then have to connect using sys password or with the password specified in password file.
    But this still you have to access to the table in sys schema using sys.table_name.
    Hope Answered tthe Question.

  • Reference all tables with the same name

    If I have multiple worksheets that each have an identically structured table "Test", is it possible to create a formula in a cell of another worksheet that references the same range of cells in every table "Test"? So far I haven't found a way to reference cells in a table with an ambiguous name without having to prepend the worksheet name to the reference like so: 'Worksheet 1' :: Test :: B3:C4. What I want to be able to do is say Test :: B3:C4 and have the formula reference B3:C4 in all "Test" tables.
    Thanks!

    You've picked the correct descriptive term. Such a reference would indeed be "ambiguous".
    You might be able to reference a set of disconnected ranges of cells, but each range would have to be explicitly described.
    You might be able to collect the values in the cells into a single array in a single table, then reference that array in your formula.
    Regards,
    Barry
    PS: "Sheets" in Numbers have little in common with "Worksheets" in MS Excel. Using the Numbers vocabulary can help keep the distinction more clear, and avoid unwarranted expectations.
    B.

  • Understanding logminer results -- inserting row into table with CLOB field

    In using log miner I have noticed that inserts into rows that contain a CLOB (I assume this applies to other LOB type fields as well, have only tested with CLOB so far) field are actually recorded as two DML entries.
    --the first entry is the insert operation that inserts all values with an EMPTY_CLOB() for the CLOB field
    --the second entry is the update that sets the actual CLOB value (+this is true even if the value of the CLOB field is not being set explicitly+)
    This separation makes sense as there may be separate locations that the values are being stored etc.
    However, what I am tripping over is the fact the first entry, the Insert, has a RowId value of 'AAAAAAAAAAAAAAAAAA' which is invalid if I attempt to use it in a flashback query such as:
    SELECT * FROM PERSON AS OF SCN #####'  where RowId = 'AAAAAAAAAAAAAAAAAA'The second operation, the Update of the CLOB field, has the valid RowId.
    Now, again, this makes sense if the insert of the new row is not really considered "+done+" until the two steps are done. However, is there some way to group these operations together when analyzing the log contents to know that these two operations are a "+matched set+"?
    Not a total deal breaker, but would be nice to know what is happening under the hood here so I don't act on any false assumptions.
    Thanks for any input.
    To replicate:
    Create a table with CLOB field:
    CREATE TABLE DEVUSER.TESTTABLE
            ID NUMBER
           , FULLNAME VARCHAR2(50)
          , AGE NUMBER  
          , DESCRIPTION CLOB
           );Capture the before SCN:
    SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER FROM DUAL;Insert a new row in the test table:
    INSERT INTO TESTTABLE(ID,FULLNAME,AGE) VALUES(1,'Robert BUILDER',35);
         COMMIT;Capture the after SCN:
    SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER FROM DUAL;Start logminer session with the bracketing scn values and options etc:
    EXECUTE DBMS_LOGMNR.START_LOGMNR(STARTSCN=>2619174, ENDSCN=>2619191, -
               OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG + DBMS_LOGMNR.CONTINUOUS_MINE + -
               DBMS_LOGMNR.COMMITTED_DATA_ONLY + DBMS_LOGMNR.NO_ROWID_IN_STMT + DBMS_LOGMNR.NO_SQL_DELIMITER)Query the logs for the changes in that range:
    SELECT
           commit_scn, xid,operation,table_name,row_id
           ,sql_redo,sql_undo, rs_id,ssn
           FROM V$LOGMNR_CONTENTS
        ORDER BY xid asc,sequence# ascResults:
    2619178     0C00070028000000     START                  AAAAAAAAAAAAAAAAAA     set transaction read write
    2619178     0C00070028000000     INSERT     TESTTABLE     AAAAAAAAAAAAAAAAAA     insert into "DEVUSER"."TESTTABLE" ...
    2619178     0C00070028000000     UPDATE     TESTTABLE     AAAFEXAABAAALEJAAB     update "DEVUSER"."TESTTABLE" set "DESCRIPTION" = NULL ...
    2619178     0C00070028000000     COMMIT                  AAAAAAAAAAAAAAAAAA     commitEdited by: 958701 on Sep 12, 2012 9:05 AM
    Edited by: 958701 on Sep 12, 2012 9:07 AM

    Scott,
    Thanks for the reply.
    I am inserting into the table over a database link.
    I am using the new version of HTML Db (2.0)
    HTML Db is connected to an Oracle 10 database I think, however the table I am trying to insert data into (via the database link) is in an Oracle 8 database - this is why we created a link to it as we couldn't have the HTML Db interacting with the Oracle 8 database directly due to compatibility problems (or so I've been told)
    Simon

  • I want to create a mail merge for address labels into a table, but when I fill a table with merge fields, it ends up creating multiple entries for the same address, rather than one table full of each address.

    ...but when I fill a table with merge fields, it ends up creating multiple entries for the same address, rather than one table full of each address. Please help.
    Thanks!

    That is a quirk of Pagesthat  it applies only one record per page.
    There is a way around this:
    http://www.freeforum101.com/iworktipsntrick/viewtopic.php?t=245&highlight=labels &mforum=iworktipsntrick
    Peter

  • Subform with table with expanding fields - please help!

    I am a new user of LiveCycle Designer ES and need help with a form.  I've made so many changes within the form that I have now lost track and don't know where to start to fix the following two issues:
    The form itself is one Master Page that needs to repeat, based on the amount of data entered.  This is not happening.
    Within the form is a Table with expanding fields.  It is when the last field is full that I need a new page created.Also, as the table expands, it overwrites the Footer, which is a subform.  The footer is set to have a top margin (.25).
    Any assistance would be much appreciated.  Thank you!

    Looks like a cross post.  see other thread here...
    http://forums.adobe.com/thread/489453?tstart=0

  • How to update database table with key field?

    Hello Experts,
    I have a database table with following fields
    MATNR   - Key
    SSOUR  -  Key
    KUNNR   - Key
    MENG1 
    MENG2
    MENG3
    And this table contains records like...
    MSD50001     R      1000001     5.30    2.30    5.25
    MSD50002     R      1000002     5.30    2.30    5.25
    MSD50003     R      1000003     5.30    2.30    5.25
    MSD50005     R      1000004     5.30    2.30    5.25
    MSD50004     R      1000005     5.30    2.30    5.25
    I have an internal table with same fields of above database table.
    MSD50001     A      1000001     5.30    2.30    5.25
    MSD50002     A      1000002     5.30    2.30    5.25
    MSD50003     A      1000003     5.30    2.30    5.25
    MSD50005     A      1000004     5.30    2.30    5.25
    MSD50004     A      1000005     5.30    2.30    5.25
    MSD50006     A      1000006     5.30    2.30    5.25
    I want to update the DB table with following internal table records.
    If internal table records = db table records are same then Update....else insert from internal table to db table.
    But here, SSOUR is key field so i am not able to use
    MODIFY dbtab from itab.
    It results me , entries in internal table are inserted into db table.
    So i have double records.
    Is there any statement which updates the key field? and if no fields in db table then insert it?
    Regards
    RH

    hi,
    u cannot update akey field.u can update only non key fields by using key field as a selection criteria.For example if u go to sm30 if u enter any table for inserting values, the key field will always be greyed out it is not succumbed to chnges.but u can insert value into ,if ur inserting and in the insert staemnet if  u have key field which is already present in the table it will return sy-subrc = 4 otherwise it will insert the record and return 0.
    eg for update :
    UPDATE zdm_wtyprof  SET upload_status = 'S'
                             WHERE spart = wa_upd-spart.
    here spart is the key field and it will update the status field in the table as S.
    if updated succesfully it will return 0.
    SIMILARLY U CAN USE select.

  • Many to many join table with different column names

    Hi have a joint table with different column names as foreign keys in the joining
    tables...
    e.g. i have a many to many reltnshp btwn Table A and Table B ..and join table
    C
    both have a column called pk.
    and the join table C has columns call fk1 and fk2
    does cmd require the same column name in the join table as in the joining table?
    are there any workarounds?
    thanks

    HI,
    No, the foreign key column names in the join table do not have to match the primary
    key names in the joined tables.
    -thorick

Maybe you are looking for

  • Upgrading to 11.1.0.6

    We're planning upgrading our 10.2.0.4 databases to 11.1.0.6 and then move to latest version later. We've done few testing with our current queries and all the applications. I didn't get any issues so far except one with ACL list, noted this, and foun

  • IPhoto 08, Raw files wont save as Tiff

    I have set my preferences to save Raw files as tiff's after editing, however it will only save as jpeg, anyone have any ideas whats causing the problem

  • Lagged Database Copy - help.

    Hi exchange gurus! I am working on testing LAgged DB copy in Exchange 2013. What I've done: 1. Configured lagged passive copy by running set-mailboxdatabasecopy .... -replaylagtime 2 (similar to what we have on transport), I didn't use -truncate opti

  • How can I uninstall the cc programs I don't use without uninstalling the ones I need and the cs6 versions?

    How can I uninstall the cc programs I don't use without uninstalling the ones I need and the cs6 versions?

  • Long term discontinu​ous logging DAQ-assist​ant

    Hello, I need to log information of load cells (NI9219) and strain gauges (NI9237) with a compactDAQ 9178. This logging will be discontinous. Let's say 10 minutes logging and 50 minutes nothing (repeating). The logging has to be triggered by a digita