ERROR creating table with dynamic SQL :-(

Hi friends,
I have a problem when I try to create a table using dynamic SQL.
(Env.: Forms 6i, WinXP, Oracle 9i)
I only want to create a table, insert data and drop the table.
I have a user with the correct privileges (At least ....I think so), because I can to make the three actions in SQL*PLUS (CREATE TABLE, INSERT .. and DROP TABLE).
I want to do the same in Forms using dynamic SQL...
I've made a package with 3 procedures:
1st to create the table, 2nd to insert data , 3rd to drop the table.
Only the 1st fails with the error ORA-01031 (insufficient privileges).
Here it is:
PROCEDURE PRO_DM_CreaTabla(pe_nombre_tabla VARCHAR2) IS
id_cursor INTEGER;
ls_sentencia VARCHAR2(500);
v_dummy integer;
BEGIN
id_cursor := DBMS_SQL.OPEN_CURSOR;
ls_sentencia := 'CREATE TABLE '||pe_nombre_tabla||' ( campo1 VARCHAR2(100), campo2 VARCHAR2(100), campo3 VARCHAR2(100),campo4 VARCHAR2(100))';
DBMS_SQL.PARSE(id_cursor, ls_sentencia, dbms_sql.NATIVE);
v_dummy := dbms_sql.execute(id_cursor);
DBMS_SQL.CLOSE_CURSOR(id_cursor);
END;
The DROP_table procedure is exactly the same as this (with the difference of the 'CREATE' sentence, where I have a DROP sentence)... then.. why the DROP procedure works?... and.. why this CREATE procedure doesn't work?
Any ideas?
Thanks a lot.
Jose.

From a different thread, Jose wrote:
V_INSERT:='INSERT INTO TMP_TABLE(field1,field3,field3,field4) VALUES (1,2,3,4)';
Forms_DDL(V_INSERT);
commit;First, try your statement in SQL Plus:
INSERT INTO TMP_TABLE(field1,field3,field3,field4) VALUES (1,2,3,4);
Then if that works, try doing this right after the Forms_DDL(V_INSERT);
If not form_success then
  Message('   Insert has failed');
  Raise form_trigger_failure;
Else
  Forms_DDL('COMMIT');
End if;

Similar Messages

  • Error creating table on MS SQL Server with OC4J standalone

    Hi there,
    I'm trying to deploy an EJB application to OC4J standalone using a MS SQL Server 2000 database, MS SQL Server JDBC Drivers and OC4J 9.0.3 standalone but i keep getting this error:
    Auto-creating table: create table Functieprofiel_competentieNiveau_CompetentieNiveau_functieprofiel_LBOS_Ear_LBOS_Ejb (Functieprofiel_FUNCTIE_ID bigint identity not null, COMP_ID bigint identity null, NIVEAU_ID sql_variant(255) null)
    Error creating table: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Could not create IDENTITY attribute on nullable column 'COMP_ID', table 'Functieprofiel_competentieNiveau_CompetentieNiveau_functieprofiel_LBOS_Ear_LBOS_Ejb'.
    Deployment succeeds after this but the application does not run properly. Can anyone help me with this? I have no idea what to do.
    Rob Heikoop

    Rb -
    if you want to stop the auto-creation of tables, try going to the j2ee/home/config directory of your OC4J installation. Open the application.xml file and modify the attribute autocreate-tables to be set to false.
    That should stop the default table creation as a global property, unless you specifically override it at the specific deployed application level.
    You can then manually create the tables on the sql-server database instance. If you keep the column names the same as the field names in the bean, then you shouldn't need to do any manual mapping. To be sure of the column names to use, take a look in the orion-ejb-jar.xml which gets generated in the j2ee/home/application-deployments/<app-name>/<ejb-module-name> to see what table/column names the generator defaulted to
    -steve-
    -steve-

  • Create table with PL/SQL

    <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">Hi,</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">I would like to create a table with PL/SQL statement. I wrote that :</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">IF</font><font SIZE="2"> T_Exists </font><font SIZE="2" COLOR="#0000f0">=</font><font SIZE="2"> </font><font SIZE="2" COLOR="#ff0000">'N'</font><font SIZE="2"> </font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">THEN</font></p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font SIZE="2" COLOR="#008000" face="Courier New">-- Create the table</p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">  CREATE</font><font SIZE="2"> </font><font SIZE="2" COLOR="#0000f0">TABLE</font></font><font face="Courier New" size="2"> T_Name</font></p>
    <p style="margin-top: 0; margin-bottom: 0"><font SIZE="2" COLOR="#0000f0" face="Courier New">  (</p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">    EXPLICITKEY </font></font><font face="Courier New"><font SIZE="2" COLOR="#ff0000"> VARCHAR2</font><font SIZE="2" COLOR="#0000f0">(</font><font SIZE="2" COLOR="#800000">25</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">),</font></p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">    BALANCE </font></font><font face="Courier New"><font SIZE="2" COLOR="#ff0000">     NUMBER</font><font SIZE="2" COLOR="#0000f0">(</font><font SIZE="2" COLOR="#800000">15</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2" COLOR="#800000">2</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">),</font></p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">    PERIOD01 </font></font><font face="Courier New"><font SIZE="2" COLOR="#ff0000">    NUMBER</font><font SIZE="2" COLOR="#0000f0">(</font><font SIZE="2" COLOR="#800000">15</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2" COLOR="#800000">2</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">),</font></p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">    PERIOD02 </font></font><font face="Courier New"><font SIZE="2" COLOR="#ff0000">    NUMBER</font><font SIZE="2" COLOR="#0000f0">(</font><font SIZE="2" COLOR="#800000">15</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2" COLOR="#800000">2</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">),</font></p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">    PERIOD03 </font></font><font face="Courier New"><font SIZE="2" COLOR="#ff0000">    NUMBER</font><font SIZE="2" COLOR="#0000f0">(</font><font SIZE="2" COLOR="#800000">15</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2" COLOR="#800000">2</font></font><font face="Courier New" SIZE="2" COLOR="#0000f0">),</font></p>
    <font SIZE="2" face="Courier New"><p style="margin-top: 0; margin-bottom: 0">  </font><font SIZE="2" COLOR="#0000f0" face="Courier New">);</p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font SIZE="2" COLOR="#0000f0" face="Courier New">ELSE</p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font SIZE="2" COLOR="#008000" face="Courier New">-- Truncate the table</p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">  DELETE</font><font SIZE="2"> </font><font SIZE="2" COLOR="#0000f0">FROM</font><font SIZE="2"> T_Name</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">;</font></p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">END</font><font SIZE="2"> </font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">IF;</font></p>
    </font>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">But there is an error :</font></p>
    <p style="margin-left: 10; margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">PLS-00103: Encountered the symbol &quot;CREATE&quot; when expecting one of the following:</font></p>
    <p style="margin-left: 10; margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">begin case declare exit for goto if loop mod null pragma</font></p>
    <p style="margin-left: 10; margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">raise return select update while with &lt;an identifier&gt;</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">Do you know why ?</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">Thank you for you help.</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><i><b><font face="Tahoma" size="2">Patrick</font></b></i></p>

    Thank you very much. And you're right because there is an error with the table <b>T_Name</b> because it doesn't exit. But <b>T_Name</b> is a variable with the name of the table to manage.
    How can I send a variable name of table in the part :
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">  DELETE</font><font SIZE="2"> </font><font SIZE="2" COLOR="#0000f0">FROM</font><font SIZE="2"> T_Name</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">;</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">Thank you.</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><i><b><font face="Tahoma" size="2">Patrick</font></b></i></p>

  • How to create table with dynamic rows

    Hi Ppl,
    I have an array lets say with length of n. I want to creata table with 2 columns and no of rows = array length.
    lets say array length is 3 ( array[0] = 1, array[1] = 2, array[2] = 3) so the table should have 2 columns and 3 rows.
    After creation of table I want to display each array value in each row.
    Can somebody help me in this asap.
    Thanks \
    Ashish

    Hi, Thanks for reply... actually this is one part of rtf. I have put values from xml to an array and now I want to create a table with no of rows = length of array. so here xml will not be useful. could you pls think of it without xml.
    result is like
    lets says below is the array
    array[0] = a
    array[1] = b
    array[2] = c
    array length = 3
    so there should be a table of 2 coulmns and 3 rows. Second column of first row will show 'a', Second column of second row wil show 'b' and Second column of third row will show 'c'.
    Hope this is useful.
    Thakns
    Ashish

  • Create table with dynamic table name.

    I'm trying to create a table
    like
    select x.*,  convert(nvarchar(20), getdate(), 101) AS LoadDate
    into table1_20140512
    from (
           select c1,c2,c3 from table2_20140512
           WHERE(LoadDate = (select MAX(LoadDate) FROM table2_20140512   )
           union all
        select c1,c2,c3 from table3_20140512
          WHERE(LoadDate = (select MAX(LoadDate) FROM table3_20140512  )
    ) X
    I want to make table name dynamic, like 'table1'+toady's date
    I declared three variables, but they didn't work as I expected  
    These are my variables
    DECLARE @table1 nvarchar(500)
    DECLARE @table2 nvarchar(500)
    DECLARE @table3 nvarchar(500)
    SET @table1='H1_' +(CONVERT(VARCHAR(8),GETDATE(),112))
    SET @table2='H2_' +(CONVERT(VARCHAR(8),GETDATE(),112))
    SET @table2='H3_' +(CONVERT(VARCHAR(8),GETDATE(),112))

    Try the following:
    DECLARE @SQL nvarchar(2000);
    DECLARE @table1 nvarchar(500) ='H1_' +(CONVERT(VARCHAR(8),GETDATE(),112));
    DECLARE @table2 nvarchar(500) ='H2_' +(CONVERT(VARCHAR(8),GETDATE(),112));
    DECLARE @table3 nvarchar(500) ='H3_' +(CONVERT(VARCHAR(8),GETDATE(),112));
    PRINT @table1+' '+@table2+' '+@table3;
    --H1_20140512 H2_20140512 H3_20140512
    SET @SQL = 'select x.*, convert(nvarchar(20), getdate(), 101) AS LoadDate
    into '+QUOTENAME(@table1)+'
    from (
    select c1,c2,c3 from table2_20140512
    WHERE(LoadDate = (select MAX(LoadDate) FROM '+QUOTENAME(@table2)+' ))
    union all
    select c1,c2,c3 from table3_20140512
    WHERE(LoadDate = (select MAX(LoadDate) FROM '+QUOTENAME(@table3)+' ))
    ) X '
    PRINT @SQL; -- debugging
    /* select x.*, convert(nvarchar(20), getdate(), 101) AS LoadDate
    into [H1_20140512]
    from (
    select c1,c2,c3 from table2_20140512
    WHERE(LoadDate = (select MAX(LoadDate) FROM [H2_20140512] ))
    union all
    select c1,c2,c3 from table3_20140512
    WHERE(LoadDate = (select MAX(LoadDate) FROM [H3_20140512] ))
    ) X
    EXEC sp_executeSQL @SQL;
    Dynamic SQL examples:
    http://www.sqlusa.com/bestpractices/dynamicsql/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • How to create table with dynamic amount of columns which are nested columns

    M trying to fetch data and show in a javaFX table.
    My table displays the details of different items from ItemVO , where :
    public class ItemVO()
    String itemName;
    List<ItemTypeVO> type;
    and My ItemTypeVO has the following attributes :
    public class ItemTypeVO()
    String typeName;
    Integer quantity;
    Integer price;
    Now, i want to display the details of an item in a table in which the itemname and quantity will be displayed, the quantity column will have nested columns showing different types(typeName) as found from List<ItemTypeVO> inside ItemVO.
    This question is similar to this link but my not able to find how to link a list with itemVO for nested columns. :(
    Please help !!
    M still unable to find a solution..
    Edited by: abhinay_a on Jan 14, 2013 10:50 AM

    Hi Abhilash,
    Thanks for the quick reply.
    Actually the problem is with the image, as I am not able to rotate 270 degree. Crystal report cannot support the rotation of image.
    i have another problem, I have to create a report in which
    Lables are fixed on the left side of report and 3 columns per portrait page. Those columns are
    dynamically created and shown in the report.
    The format is like the above. Can you please help me in doing this report, as I tried it doing
    with CrossTab. I am really stuck to this report.

  • Trying to create table with dynamic rows

    First off, I'm a noob. This is a homework assignment I'm working on. I'm trying to create an Amortization Table based on a user's selection of different term/interest rate combinations. I need a table that has four columns: Payment Month 1-12, Monthly Payment Amount, Interest Paid, and Remaining Principle. But I need the rows to change based on the user's selection of a radio button. I have three radio buttons: 7 years at 5.35% interest, 15 years at 5.5% interest, and 30 years at 5.75% interest. I'll need anywhere from 180 rows to 360 rows; one row for each monthly payment.
    I'm not sure about my approach to this, but I created a JTable named 'amortTable' and I'm using the DefaultTableModel. I'm using a for loop to step through the calculations until the principle balance is zero. I'm apparently not doing something right, as the data is not populating in the table. Here's the code in question. I didn't post my full code, but let me know if it's needed and I will.
    import java.io.*;
    import javax.swing.*;
    import javax.swing.table.*;
    javax.swing.JTable amortTable = new javax.swing.JTable();
    javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
    private void init Components()
    ... //extra code omitted
    amortTable.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][]
    {null, null, null, null}
    new String []
    "Payment No.", "Payment Amount", "Interest Paid", "Remaining Principle"
    jScrollPane1.setViewportView(amortTable);
    .... //extra code omitted
    }//end initComponents
    private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt)
    ... //extra code omitted
    while (loanAmount>0)
    for (int i = 0; i < 12; i++)
    interestPaid = loanAmount * monthlyRate;
    principlePaid = monthlyPymt - interestPaid;
    loanAmount = loanAmount - principlePaid;
    pymtNo = pymt;
    amortTable.addRow(new Object[]{pymtNo, monthlyPymt, interestPaid, loanAmount});
    }//end for loop
    }//end while loop
    }//end calculateButtonActionPerformed
    My goal was to use the for loop to continue to add rows containing the specified variables to amortTable until the principle balance reached zero.I get a compiler error that says "cannot find symbol / symbol: method addRow(java.lang.Object[]) / location: class javax.swing.JTable). I'm pretty sure it has to do with the fact that the table is located in a different method than the for loop, but I don't know how to check for that. I also don't believe that the problem is with the method itself, but rather a syntax error elsewhere. Any ideas? Or if I'm going about this the wrong way, can someone point me in the right direction?

    Hello and welcome. Some observances.
    1) You seem to be trying to call addRow on amortTable, a JTable object, and these beasts shouldn't have that method. Rather you would call this method on the DefaultTableModel object held by this JTable.
    2) Please read the FAQ to see how to use code tags to make your code readable when posting it here.
    3) I find when I have difficulty like this, it is always better to try to solve the problem in a very simple program first and then use that info in the larger program. So in that light, why not create a very simple program that tries to add simple rows to a JTable on button press. Solve your problem here and you've solved it for the big program. Fail to solve it and you can always post the whole simple program here which will be a lot easier for us to read and understand than your big program.
    Much luck!

  • Writing to a temp table in a stored procedure with dynamic sql

    Hi
    I am writing into a temp table with dynamic sql:
    select coloum_name into #temp_table from
    +
    @DestinationDBName+'.information_schema.tables
    and then I am trying to use #temp_table in the procedure:
    select coloum_name into #anotherTable from #temp_table
    but I am getting an error that #temp_table is not recognized.
    Can a temp table not be used in dynamic sql ?
    How can I overcome this problem ?

    Temp Table Can used easily in Dynamic Query in SQL Server and here is small Exmaple you can check it and do like it 
    CREATE PROC test
    AS
    BEGIN
    CREATE TABLE #T1 
    (ID  int , NAME Nvarchar(50))
    CREATE TABLE #T2 
    (ID  int , NAME Nvarchar(50))
    DECLARE @SQL NVARCHAR(MAX)='Insert into #T1 
    SELECT database_id , Name FROM Sys.Databases
    Insert into #T2 Select ID , Name from  #T1 '
    EXEC SP_ExecuteSQL @SQL
    SELECT * FROM #T2
    DROP TABLE #T1
    DROP TABLE #T2
    END
    Exec Test
    If you found My reply is helpful for you please vote me 
    thanks
    Mustafa EL-Masry
    Principle Database Administrator & DB Analyst
    SQL Server MCTS-MCITP
    M| +966 54 399 0968
    MostafaElmasry.Wordpress.Com

  • Create table in PL/SQL proc not working

    Hello,
    Here is a procedure I have tried to create & run in SQL Developer:
    create or replace procedure transpose as
    begin
    create table lines as (select level line from dual connect by level <= 5),
    create table cols as (select level col from dual connect by level <= 5),
    select max(decode(col, 1,
    decode(line, 1, line_id,
    2, description,
    3, statetax,
    4, freight,
    5, weightedAvg))) col1,
    max(decode(col, 2,
    decode(line, 1, line_id,
    2, description,
    3, statetax,
    4, freight,
    5, weightedAvg))) col2,
    max(decode(col, 3,
    decode(line, 1, line_id,
    2, description,
    3, statetax,
    4, freight,
    5, weightedAvg))) col3,
    max(decode(col, 4,
    decode(line, 1, line_id,
    2, description,
    3, statetax,
    4, freight,
    5, weightedAvg))) col4,
    max(decode(col, 5,
    decode(line, 1, line_id,
    2, description,
    3, statetax,
    4, freight,
    5, weightedAvg))) col5
    from lines, cols,
    (select rownum rn, tfe_line_info.* from tfe_line_info)
    where rn = col
    group by line
    order by line;
    end transpose;
    I however get the error:
    Error(3,7): PLS-00103: Encountered the symbol "CREATE" 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
    I cannot understand what is wrong with my Create statement at line 3?

    It looks like you have no PL/SQL experience. I suggest reading PL/SQL manual. Yes, single row select requires INTO clause. Multi-rows select requires cursor. But this is least of your problems. Your SPp will not complile even if you fix select. Why? SP creates tables dynamically at run time, so tables do not exist at SP compile time. Therefore select from these yet non-existent tables will not compile. By creating tables via dynamic SQL you forced yourself into querying them via dynamic SQL. Now you are trying to transpose (pivot) table. What Oracle version do you have? Oracle 11g provides PIVOT/UNPIVOT operators. Check them out before writing code.
    SY.

  • Error while creating table with clusters

    Hi
    I tried the following
    CREATE CLUSTER emp_dept (deptno NUMBER(3))Cluster is created
    Then i tried to create the table having the above cluster but giving the errors:
    create table emp10 (ename char(5),deptno number(2) )cluster emp_dept(deptno);The error is:
    ORA-01753 column definition incompatible with clustered column definitionCould you please help me in this

    Your cluster is based on a NUMBER(3) data type while the emp10 table has a deptno column with a data type of NUMBER(2).

  • Create dynamic internal table with dynamic structure

    I have an internal table itab1 that have 12 amount fields from period1 thru period12.  I need to create a dynamic table with dynamic structure for the  period column if the total amount of each column  is > 0.  Any idea on how to do that? 
    For example if my itab1 has 20 rows and the sum of period1 = 35, sum of period2 = 0, sum of period3 = 5, sum of period4 =0, sum of period5 = 2 then I need to create a dynamic structure for the field column that have the total > 0, i.e  structure struct1 have field period1, period3 and period5 only.  Then I will need to load the data to itab2 from itab1.  Can someone help.
    Thanks.  I am on 4.7 and will upgrade to ERP 6.0 soon.

    go throgh this....
    REPORT  yusmm_text1  NO STANDARD PAGE HEADING
                         LINE-SIZE 199.
    T A B L E S
    TABLES: MARA,
            MAKT,
            THEAD.
    GLOBAL TYPE-POOLS
    TYPE-POOLS : SLIS.
       GLOBAL TYPES
    TYPES : BEGIN OF TP_FINAL,
           MATNR TYPE MARA-MATNR,
           BEGRU TYPE MARA-BEGRU,
           MTART TYPE MARA-MTART,
           MAKTX TYPE MAKT-MAKTX,
           SPRAS TYPE MAKT-SPRAS,
           LTXT(2000)  TYPE C ,
           SRNO TYPE N ,
          END OF TP_FINAL.
    TYPES : BEGIN OF TP_T002,
            SPRAS TYPE T002-SPRAS,
            LAISO TYPE T002-LAISO,
            SRNO TYPE N ,
            END OF TP_T002.
    TYPES : BEGIN OF TP_MARA_MAKT,
            MATNR TYPE MARA-MATNR,
            BEGRU TYPE MARA-BEGRU,
            MTART TYPE MARA-MTART,
            SPRAS TYPE MAKT-SPRAS,
            MAKTX TYPE MAKT-MAKTX,
           END OF TP_MARA_MAKT.
    Types: BEGIN OF tp_matnr,
           matnr TYPE mara-matnr,
           END OF tp_matnr.
       GLOBAL ELEMENTARY VARIABLES
    DATA : gv_date TYPE sy-datum.
    DATA : gv_repid TYPE sy-repid.
    DATA : g_var1(10) TYPE C.
    DATA : gv_index TYPE sy-tabix.
    DATA: gv_strg TYPE string,
          gv_strg1(2000) TYPE C.
    DATA : gv_lang TYPE sy-langu.
    DATA : g_v(3) TYPE N .
    DATA : gv_lines(3) TYPE N .
    DATA : gv_var(3) TYPE N .
    DATA : gv_var1(3) TYPE N.
    DATA: gv_str TYPE STRING.
    DATA: gv_str1 TYPE STRING.
    DATA : gv_li TYPE I,
           gv_lit TYPE I,
           gv_lin TYPE I.
    DATA: g_var11(3) TYPE N,
          gv_li1(3) TYPE N,
          g_var2(3) TYPE N.
    DATA : gv_i1 TYPE I.
    DATA : gv_i TYPE I.
    DATA: gl_lenght TYPE I.
       GLOBAL STRUCTURES
    DATA:   T_NEWTABLE TYPE REF TO DATA,
            T_NEWLINE  TYPE REF TO DATA,
            T_FLDCAT1   TYPE SLIS_T_FIELDCAT_ALV,
            T_FLDCAT   TYPE LVC_T_FCAT,
            WA_IT_FLDCAT TYPE LVC_S_FCAT,
            WA_IT_FLDCAT1 TYPE SLIS_FIELDCAT_ALV,
            WA_COLNO(2) TYPE N,
            WA_FLNAME(5) TYPE C,
            L_LT TYPE SLIS_LAYOUT_ALV.
       GLOBAL INTERNAL TABLES (WITH INCLUDE STRUCTURE)
    DATA : IG_MARA_MAKT TYPE STANDARD TABLE OF TP_MARA_MAKT,
           WG_MARA_MAKT TYPE TP_MARA_MAKT.
    DATA : IG_T002 TYPE STANDARD TABLE OF TP_T002,
           WG_T002 TYPE TP_T002.
    DATA : IG_FINAL TYPE STANDARD TABLE OF TP_FINAL,
           WG_FINAL TYPE TP_FINAL.
    data : IG_MATNR TYPE STANDARD TABLE OF TP_MATNR WITH HEADER  LINE,
           WG_MATNR TYPE TP_MATNR.
    DATA:BEGIN OF IG_THEAD OCCURS 0.
            INCLUDE STRUCTURE THEAD .
    DATA: END OF IG_THEAD.
    DATA:BEGIN OF IG_TLINE OCCURS 0.
            INCLUDE STRUCTURE TLINE  .
    DATA:END OF IG_TLINE.
    FIELD-SYMBOLS
    FIELD-SYMBOLS: <T_DYNTABLE> TYPE STANDARD TABLE,"Dynamic internal
                                                            "tablename
                   <FS_DYNTABLE>,  "Field symbol to create work area
                  <FS_FLDVAL> TYPE ANY.   " Field symbol to assign values
    COMPULSORY
    FIELD-SYMBOLS: <FS_DATA> TYPE REF TO DATA,
                   <FS_DATA1> TYPE REF TO DATA,
                   <FS_2>    TYPE STANDARD TABLE,
                   <FS_22>   TYPE STANDARD TABLE,
                   <FS_1>,
                   <FS_11>,
                   <F>,
                   <FA>,
                   <LWA_LINE_WA>,
                   <LWA_LINE_WA1>.
    ------- Create Dyn Table From FC
    DATA: LT_DATA        TYPE   REF TO DATA,
          LT_DATA1        TYPE   REF TO DATA,
          LWA_LINE       TYPE   REF TO  DATA,
          LWA_LINE1       TYPE   REF TO  DATA,
          LI_FIELD_CAT   TYPE   LVC_T_FCAT,
          LWA_FIELD_CAT  TYPE   LVC_S_FCAT.
       PARAMETERS & SELECT-OPTIONS
    SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS : S_SPRAS FOR MAKT-SPRAS NO INTERVALS  DEFAULT 'EN'
                                                            OBLIGATORY ,
                     S_MATNR FOR MARA-MATNR,
                     S_MTART FOR MARA-MTART.
    PARAMETERS: GP_SIZE TYPE I DEFAULT '200'.
    SELECTION-SCREEN : END OF BLOCK B1.
       INITIALIZATION
    INITIALIZATION.
      gv_repid = sy-repid.
      gv_date = sy-datum.
    AT SELECTION-SCREEN
    AT SELECTION-SCREEN.
      IF GP_SIZE < 0.
       MESSAGE E002(00).
      ENDIF.
      IF GP_SIZE > 50000.
       MESSAGE W130(26) WITH TEXT-004.
        SET CURSOR FIELD 'gp_size'.
      ENDIF.
    START-OF-SELECTION
    START-OF-SELECTION.
      PERFORM FIELDCAT.
      PERFORM LAYOUT.
      PERFORM DATA_FETCH.
      PERFORM READ_DATA_TO_FINAL.
      SORT ig_final BY matnr spras.
      gv_lin = gv_li.
      gv_li = gv_li - 2.
      LOOP AT ig_final INTO wg_final.
        ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'Material Number'.
        ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'Authorization Group'.
        g_VAR11 = wg_final-srno + 2.
        gv_li1 = gv_li1 + 2.
        MOVE : g_var11 TO gv_i1.
        ASSIGN COMPONENT g_var11 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'MatDesc'.
        g_var2 = g_var11 + gv_lines.
        ASSIGN COMPONENT g_var2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'BasicData'.
        APPEND <LWA_LINE_WA1> TO <FS_22>.
        EXIT.
       ENDLOOP.
      LOOP AT ig_final INTO wg_final.
        AT NEW matnr.
          gv_index = sy-tabix.
          ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA> TO <F>.
          <F> = wg_final-matnr.
          ENDAT.
        AT NEW MATNR.
        GV_INDEX = SY-TABIX.
        ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-matnr.
         ENDAT.
        ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA> TO <F>.
        <F> = wg_final-begru.
        ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-begru.
        gv_var = wg_final-srno + 2.
        gv_li = gv_li + 2.
        MOVE : gv_var TO gv_i.
        ASSIGN COMPONENT gv_var OF STRUCTURE <LWA_LINE_WA> TO <F>.
        <F> = wg_final-maktx.
        ASSIGN COMPONENT gv_var OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-maktx.
        gv_var1 = gv_var + gv_lines  .
        ASSIGN COMPONENT gv_var1 OF STRUCTURE <LWA_LINE_WA> TO <F>.
       <F> = wg_final-ltxt.
        ASSIGN COMPONENT gv_var1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-ltxt.
        AT END OF matnr.
          APPEND <LWA_LINE_WA> TO <FS_2>.
          CLEAR <LWA_LINE_WA>.
        ENDAT.
        AT END OF matnr.
         APPEND <LWA_LINE_WA1> TO <FS_22>.
         CLEAR <LWA_LINE_WA1>.
        ENDAT.
      ENDLOOP.
      PERFORM display..
    *&      Form  data_fetch
          text
    -->  p1        text
    <--  p2        text
    FORM DATA_FETCH .
      SELECT matnr
              from mara up to gp_size rows
             appending corresponding fields of table ig_matnr
             where matnr in s_matnr
             and mtart in s_mtart.
    loop at ig_matnr.
      SELECT  MARA~MATNR
              MARA~BEGRU
              MARA~MTART
              MAKT~SPRAS
              MAKT~MAKTX FROM MARA INNER JOIN MAKT
        ON MARAMATNR = MAKTMATNR
       appending corresponding fields of TABLE ig_mara_makt  UP TO GP_SIZE
    ROWS
        WHERE makt~spras IN s_spras
        AND   mara~matnr IN s_matnr
        AND   mara~mtart IN s_mtart
        AND   mara~matnr EQ ig_matnr-matnr.
        endloop.
      IF sy-subrc = 0.
        SORT ig_mara_makt.
      ENDIF.
    ENDFORM.                    " data_fetch
    *&      Form  read_data_to_final
          text
    -->  p1        text
    <--  p2        text
    FORM READ_DATA_TO_FINAL .
      LOOP AT ig_mara_makt INTO wg_mara_makt .
        wg_final-MATNR = wg_mara_makt-MATNR.
        wg_final-BEGRU = wg_mara_makt-BEGRU.
        wg_final-MTART = wg_mara_makt-MTART.
        wg_final-SPRAS = wg_mara_makt-SPRAS.
        wg_final-MAKTX = wg_mara_makt-MAKTX.
        READ TABLE ig_t002 INTO wg_t002 WITH KEY spras = wg_final-spras.
        IF sy-subrc = 0.
          wg_final-srno = wg_t002-srno.
        ENDIF.
        CLEAR ig_thead[].
        ig_thead-TDOBJECT = 'MATERIAL'.
        ig_thead-TDNAME   = wg_final-matnr.
        ig_thead-TDID     = 'GRUN'.
        ig_thead-TDSPRAS  = wg_final-spras.
        CALL FUNCTION 'TEXT_READ'
          EXPORTING
            I_HEADER   = IG_THEAD
            I_READONLY = 'X'
          IMPORTING
            E_HEADER   = IG_THEAD
          TABLES
            T_LINES    = IG_TLINE[]
          EXCEPTIONS
            NOTFOUND   = 1.
        IF sy-subrc  EQ 0.
          LOOP AT  ig_tline.
            gv_strg = ig_tline-tdline.
            IF gv_strg1 <> ' '.
              CONCATENATE gv_strg1 ';' gv_strg INTO gv_strg1.
            ELSE.
              gv_strg1 = gv_strg.
            ENDIF.
          ENDLOOP.
          wg_final-ltxt = gv_strg1.
          APPEND wg_final TO ig_final.
          CLEAR wg_final.
          gv_strg1 = ' '.
        ELSE.
          APPEND wg_final TO  ig_final.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " read_data_to_final
    " read_data_to_final
    *&      Form  layout
          text
    -->  p1        text
    <--  p2        text
    FORM LAYOUT .
      CLEAR L_LT.
      L_LT-ZEBRA = 'X'.
      L_LT-COLWIDTH_OPTIMIZE = 'X'.
      L_LT-WINDOW_TITLEBAR = 'MATERIAL DETAILS'.
    ENDFORM.                    " layout
    *&      Form  fieldcat
          text
    -->  p1        text
    <--  p2        text
    FORM FIELDCAT .
      SELECT SPRAS
               LAISO FROM t002 INTO  CORRESPONDING FIELDS OF TABLE ig_t002
          WHERE spras IN s_spras.
      DESCRIBE TABLE ig_t002 LINES gv_lines.
      LOOP AT ig_t002 INTO wg_t002.
        g_v = g_v + 1.
        Wg_t002-srno = g_v.
        MODIFY ig_t002 FROM wg_t002 TRANSPORTING SRNO.
      ENDLOOP.
      LOOP AT ig_t002 INTO wg_t002.
        CLEAR WA_IT_FLDCAT.
        MOVE SY-INDEX TO WA_COLNO.
        CONCATENATE 'MD-' wg_t002-LAISO
                          WA_COLNO
                         INTO WA_FLNAME.
        WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
        WA_IT_FLDCAT-DATATYPE = 'CHAR'.
        WA_IT_FLDCAT-SELTEXT = WA_FLNAME.
        WA_IT_FLDCAT-INTLEN = 250.
        WA_IT_FLDCAT-TABNAME = '<FS_2>'.
        APPEND WA_IT_FLDCAT TO T_FLDCAT.
        CLEAR wg_t002.
        ENDLOOP.
      LOOP AT ig_t002 INTO wg_t002.
        CLEAR WA_IT_FLDCAT.
        MOVE SY-INDEX TO WA_COLNO.
        CONCATENATE 'BD-' wg_t002-LAISO
                           WA_COLNO
                        INTO WA_FLNAME.
        WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
        WA_IT_FLDCAT-DATATYPE = 'CHAR'.
        WA_IT_FLDCAT-SELTEXT = WA_FLNAME.
        WA_IT_FLDCAT-INTLEN = 250.
        WA_IT_FLDCAT-TABNAME = '<FS_2>'.
        APPEND WA_IT_FLDCAT TO T_FLDCAT.
        CLEAR wg_t002.
        ENDLOOP.
      MOVE 'MATNR' TO WA_FLNAME.
      WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
      WA_IT_FLDCAT-DATATYPE = 'CHAR'.
      WA_IT_FLDCAT-SELTEXT = 'Material No'.
      WA_IT_FLDCAT-INTLEN = 18.
      WA_IT_FLDCAT-TABNAME = '<FS_2>'.
      INSERT WA_IT_FLDCAT INTO T_FLDCAT INDEX 1.
      MOVE 'BEGRU' TO WA_FLNAME.
      WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
      WA_IT_FLDCAT-DATATYPE = 'CHAR'.
      WA_IT_FLDCAT-SELTEXT = 'Authorization Group'.
      WA_IT_FLDCAT-INTLEN = 4.
      WA_IT_FLDCAT-TABNAME = '<FS_2>'.
      INSERT WA_IT_FLDCAT INTO T_FLDCAT INDEX 2.
      DESCRIBE TABLE T_FLDCAT LINES gv_li.
      ASSIGN LT_DATA TO <FS_DATA>.
    Creating the Dynamic Internal Table
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG           = T_FLDCAT         " Fieldcatalogue
        IMPORTING
          EP_TABLE                  = <FS_DATA>   " Dynamic Internal Table
        EXCEPTIONS
          GENERATE_SUBPOOL_DIR_FULL = 1
          OTHERS                    = 2.
    Assign Dyn Table To Field Sumbol
      ASSIGN <FS_DATA>->* TO <FS_1>.
    Assigning the Internal Table TYPE ANY to Standard internal Table
      ASSIGN <FS_1> TO <FS_2>.
    Creating a Workarea
      CREATE DATA LWA_LINE LIKE LINE OF <FS_2> .
    Assigning the Content to the workares as a Pointer
      ASSIGN LWA_LINE->* TO <LWA_LINE_WA>.
      LOOP AT T_FLDCAT INTO WA_IT_FLDCAT.
        WA_IT_FLDCAT1-FIELDNAME = WA_IT_FLDCAT-FIELDNAME.
        WA_IT_FLDCAT1-TABNAME =  WA_IT_FLDCAT-TABNAME.
        WA_IT_FLDCAT1-SELTEXT_L = WA_IT_FLDCAT-SELTEXT.
       WA_IT_FLDCAT1-REF_TABNAME = 'MARC'.
        APPEND WA_IT_FLDCAT1 TO T_FLDCAT1.
        CLEAR : WA_IT_FLDCAT,WA_IT_FLDCAT1.
      ENDLOOP.
      ASSIGN LT_DATA1 TO <FS_DATA1>.
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG           = T_FLDCAT         " Fieldcatalogue
        IMPORTING
          EP_TABLE                  = <FS_DATA1>  " Dynamic Internal table
        EXCEPTIONS
          GENERATE_SUBPOOL_DIR_FULL = 1
          OTHERS                    = 2.
    Assign Dyn Table To Field Sumbol
      ASSIGN <FS_DATA1>->* TO <FS_11>.
    Assigning the Internal Table TYPE ANY to Standard internal Table
      ASSIGN <FS_11> TO <FS_22>.
    Creating a Workarea
      CREATE DATA LWA_LINE1 LIKE LINE OF <FS_22> .
    Assigning the Content to the workares as a Pointer
      ASSIGN LWA_LINE1->* TO <LWA_LINE_WA1>.
    ENDFORM.                    " fieldcat
    *&      Form  show
          text
    -->  p1        text
    <--  p2        text
    FORM Display .
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
       I_INTERFACE_CHECK                 = ' '
       I_BYPASSING_BUFFER                = ' '
       I_BUFFER_ACTIVE                   = ' '
         I_CALLBACK_PROGRAM                = GV_REPID
        I_CALLBACK_PF_STATUS_SET          = 'PF_STATUS_SET'
        I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
       I_CALLBACK_TOP_OF_PAGE            = ' '
       I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
       I_CALLBACK_HTML_END_OF_LIST       = ' '
       I_STRUCTURE_NAME                  =
       I_BACKGROUND_ID                   = ' '
       I_GRID_TITLE                      =
       I_GRID_SETTINGS                   =
        IS_LAYOUT                         = L_LT
         IT_FIELDCAT                       = T_FLDCAT1[]
       IT_EXCLUDING                      =
       IT_SPECIAL_GROUPS                 =
       IT_SORT                           =
       IT_FILTER                         =
       IS_SEL_HIDE                       =
       I_DEFAULT                         = 'X'
       I_SAVE                            = ' '
       IS_VARIANT                        =
       IT_EVENTS                         =
       IT_EVENT_EXIT                     =
       IS_PRINT                          =
       IS_REPREP_ID                      =
       I_SCREEN_START_COLUMN             = 0
       I_SCREEN_START_LINE               = 0
       I_SCREEN_END_COLUMN               = 0
       I_SCREEN_END_LINE                 = 0
       I_HTML_HEIGHT_TOP                 = 0
       I_HTML_HEIGHT_END                 = 0
       IT_ALV_GRAPHICS                   =
       IT_HYPERLINK                      =
       IT_ADD_FIELDCAT                   =
       IT_EXCEPT_QINFO                   =
       IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
       E_EXIT_CAUSED_BY_CALLER           =
       ES_EXIT_CAUSED_BY_USER            =
        TABLES
          T_OUTTAB                          = <FS_2>
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " display
    FORM PF_STATUS_SET USING RS_EXTAB TYPE SLIS_T_EXTAB.
      SET PF-STATUS 'DISPLAY' .
    ENDFORM. "PF_STATUS_SET
    *& Form Name: user_command *
    *& Form Desc: For Handling USER_COMMAND *
    FORM USER_COMMAND USING IF_UCOMM TYPE SY-UCOMM
                         IS_SELFIELD TYPE SLIS_SELFIELD.
      CASE IF_UCOMM.
        WHEN 'DOWNLOAD'.
          CALL FUNCTION 'POPUP_TO_CONFIRM'
            EXPORTING
      TITLEBAR                    = ' '
      DIAGNOSE_OBJECT             = ' '
              TEXT_QUESTION               = 'Data download to excel'
      TEXT_BUTTON_1               = 'Ja'(001)
      ICON_BUTTON_1               = ' '
      TEXT_BUTTON_2               = 'Nein'(002)
      ICON_BUTTON_2               = ' '
      DEFAULT_BUTTON              = '1'
      DISPLAY_CANCEL_BUTTON       = 'X'
      USERDEFINED_F1_HELP         = ' '
      START_COLUMN                = 25
      START_ROW                   = 6
      POPUP_TYPE                  =
    IMPORTING
      ANSWER                      =
    TABLES
      PARAMETER                   =
    EXCEPTIONS
      TEXT_NOT_FOUND              = 1
      OTHERS                      = 2
          IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          CALL FUNCTION 'GUI_DOWNLOAD'
            EXPORTING
        BIN_FILESIZE                  =
              FILENAME                     = 'C:\Material-Text.xls'
             FILETYPE                      = 'ASC'
        APPEND                        = ' '
         WRITE_FIELD_SEPARATOR         = 'X'
        HEADER                        = '00'
         TRUNC_TRAILING_BLANKS         = 'X'
        WRITE_LF                      = 'X'
        COL_SELECT                    = ' '
        COL_SELECT_MASK               = ' '
         DAT_MODE                      = 'X'
       IMPORTING
         FILELENGTH                    = GL_LENGHT
            TABLES
              DATA_TAB                      = <FS_22>
      EXCEPTIONS
        FILE_WRITE_ERROR              = 1
        NO_BATCH                      = 2
        GUI_REFUSE_FILETRANSFER       = 3
        INVALID_TYPE                  = 4
        NO_AUTHORITY                  = 5
        UNKNOWN_ERROR                 = 6
        HEADER_NOT_ALLOWED            = 7
        SEPARATOR_NOT_ALLOWED         = 8
        FILESIZE_NOT_ALLOWED          = 9
        HEADER_TOO_LONG               = 10
        DP_ERROR_CREATE               = 11
        DP_ERROR_SEND                 = 12
        DP_ERROR_WRITE                = 13
        UNKNOWN_DP_ERROR              = 14
        ACCESS_DENIED                 = 15
        DP_OUT_OF_MEMORY              = 16
        DISK_FULL                     = 17
        DP_TIMEOUT                    = 18
        FILE_NOT_FOUND                = 19
        DATAPROVIDER_EXCEPTION        = 20
        CONTROL_FLUSH_ERROR           = 21
        OTHERS                        = 22
          IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          IF GL_LENGHT NE 0.
            MESSAGE S398(00) WITH 'DATA downloaded to EXCEL'.
          ENDIF.
      ENDCASE.
    ENDFORM.                    "user_command
    Thanks

  • Create data base table with EXEC SQL

    Hello,
    I nead to create o data base table with EXEC SQL in an Abap program.
    My code is :
    TRY.
       EXEC SQL.
          CREATE table zt_hello ( mandt char(4) NOT NULL,
                                  kunnr char(10) NOT NULL,
                                  PRIMARY KEY (mandt, kunnr) )
        ENDEXEC.
      CATCH cx_sy_native_sql_error INTO exc_ref.
        error_text = exc_ref->get_text( ).
    ENDTRY.
    IF sy-subrc = 0.
      COMMIT WORK.
    ENDIF.
    But it still not working.
    Can you help me please.
    Thanks.
    Edited by: widad soubhi on Jul 14, 2010 5:26 PM

    Please refer this code
    REPORT z_struct_create .
    DATA: my_row(500) TYPE c,
    my_file_1 LIKE my_row OCCURS 0 WITH HEADER LINE.
    DATA: dd02v TYPE dd02v.
    DATA: my_file_tab1 LIKE dd03p OCCURS 0 WITH HEADER LINE.
    SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text
    NO INTERVALS.
    PARAMETERS:
    name TYPE ddobjname,
    testo TYPE text40,
    file_1 LIKE rlgrap-filename.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN END OF BLOCK blk.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR file_1.
    PERFORM file_selection USING file_1.
    INITIALIZATION.
    text = text-001.
    START-OF-SELECTION.
    IF file_1 IS INITIAL.
    MESSAGE ID 'Z0017_BDI' TYPE 'I' NUMBER 001.
    EXIT.
    ENDIF.
    CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
    filename = file_1
    filetype = 'ASC'
    TABLES
    data_tab = my_file_1.
    IF sy-subrc 0.
    MESSAGE ID 'Z0017_BDI' TYPE 'I' NUMBER 002.
    EXIT.
    ENDIF.
    LOOP AT my_file_1.
    IF sy-tabix > 1.
    CLEAR my_file_tab1.
    SPLIT my_file_1 AT ';' INTO
    my_file_tab1-fieldname
    my_file_tab1-datatype
    my_file_tab1-leng
    my_file_tab1-decimals
    my_file_tab1-ddtext
    my_file_tab1-inttype = 'C'.
    my_file_tab1-INTLEN = my_file_tab1-leng.
    my_file_tab1-tabname = name.
    my_file_tab1-position = sy-tabix - 1.
    my_file_tab1-ddlanguage = sy-langu.
    my_file_tab1-OUTPUTLEN = my_file_tab1-leng.
    APPEND my_file_tab1.
    ENDIF.
    ENDLOOP.
    dd02v-tabname = name.
    dd02v-ddlanguage = sy-langu.
    dd02v-tabclass = 'INTTAB'.
    dd02v-DDTEXT = testo.
    dd02v-MASTERLANG = sy-langu.
    IF NOT my_file_tab1[] IS INITIAL.
    CALL FUNCTION 'DDIF_TABL_PUT'
    EXPORTING
    name = name
    dd02v_wa = dd02v
    TABLES
    dd03p_tab = my_file_tab1
    EXCEPTIONS
    tabl_not_found = 1
    name_inconsistent = 2
    tabl_inconsistent = 3
    put_failure = 4
    put_refused = 5
    OTHERS = 6
    IF sy-subrc 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ELSE.
    MESSAGE ID 'Z0017_BDI' TYPE 'I' NUMBER 003.
    EXIT.
    ENDIF.
    *& Form file_selection
    -->P_FILE_1 text
    FORM file_selection USING p_file.
    CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
    def_filename = ''
    def_path = 'c:\'
    mask = ',.,..'
    mode = '0'
    title = 'Selezione file'
    IMPORTING
    filename = p_file
    RC = RCODE
    EXCEPTIONS
    inv_winsys = 1
    no_batch = 2
    selection_cancel = 3
    selection_error = 4
    OTHERS = 5.
    ENDFORM. " file_selection
    File Template:
    Fieldname;Data Type;Lentgh;Dec.;Descr.
    FIELD1;CHAR;000020;000000;my field 1
    FIELD2;CHAR;000008;000000;my field 2
    FIELD3;CHAR;000007;000000;my field 3
    FIELD4;CHAR;000006;000000;my field 4

  • Help with dynamic SQL

    Hello,
    I have the following function that works ok:
    CREATE OR REPLACE FUNCTION Get_Partition_Name (sTable VARCHAR2, iImportIndex INTEGER)
    RETURN VARCHAR2 IS
    cursor c is select A.partition_name from (select table_name, partition_name,
    extractvalue (
    dbms_xmlgen.
    getxmltype (
    'select high_value from all_tab_partitions where table_name='''
    || table_name
    || ''' and table_owner = '''
    || table_owner
    || ''' and partition_name = '''
    || partition_name
    || ''''),
    '//text()') import_value from all_tab_partitions) A where table_name = sTable and A.import_value = iImportIndex;
    sPartitionName VARCHAR(20);
    err_num NUMBER;
    BEGIN
    open c;
    fetch c into sPartitionName;
    IF c%ISOPEN THEN
    CLOSE c;
    END IF;
    RETURN sPartitionName;
    EXCEPTION
    WHEN OTHERS THEN
    err_num := SQLCODE;
    --save error in log table
    LOG.SAVELINE(SQLCODE, SQLERRM);
    END Get_Partition_Name;
    I am trying to replace the cursor statement with dynamic SQL, something like (see below) but it doesn't work any more; I think I am missing some quotes.
    CREATE OR REPLACE FUNCTION Get_Partition_Name (sTable VARCHAR2, iImportIndex INTEGER)
    RETURN VARCHAR2 IS
    TYPE t1 IS REF CURSOR;
    c t1;
    sSql VARCHAR2(500);
    sPartitionName VARCHAR(20);
    err_num NUMBER;
    BEGIN
    sSql := 'select A.partition_name from (select table_name, partition_name,
    extractvalue (
    dbms_xmlgen.
    getxmltype (
    ''select high_value from all_tab_partitions where table_name=''''
    || table_name
    || '''' and table_owner = ''''
    || table_owner
    || '''' and partition_name = ''''
    || partition_name
    || ''''''),
    ''//text()'') import_value from all_tab_partitions) A where table_name = :a and A.import_value = :b';
    OPEN c FOR sSql USING sTable, iImportIndex;
    fetch c into sPartitionName;
    IF c%ISOPEN THEN
    CLOSE c;
    END IF;
    RETURN sPartitionName;
    EXCEPTION
    WHEN OTHERS THEN
    err_num := SQLCODE;
    --save error in log table
    LOG.SAVELINE(SQLCODE, SQLERRM);
    END Get_Partition_Name;
    Please advise,
    Regards,
    M.R.

    Assuming the requirement is to find the partition in the supplied table with the supplied high value and the issue is that dba/all_tab_partitions.high_value is a long, one alternative along the same lines as you've done already is as follows. (I've just used a cursor rather than a function for simplicity of demo).
    SQL> var r refcursor
    SQL> set autoprint on
    SQL> declare
      2   ctx dbms_xmlgen.ctxhandle;
      3   v_table_name VARCHAR2(40) := 'LOGMNR_USER$';
      4   v_value      NUMBER       := 100;
      5  begin
      6   ctx := DBMS_XMLGEN.NEWCONTEXT
      7          ('select table_name
      8            ,      partition_name
      9            ,      high_value  hi_val
    10            from   dba_tab_partitions
    11            where  table_name     = :table_name');
    12   dbms_xmlgen.setbindvalue(ctx,'TABLE_NAME',v_table_name);
    13   open:r for
    14   with x as
    15   (select xmltype(dbms_xmlgen.getxml(ctx)) myxml
    16    from   dual)
    17   select extractvalue(x.object_value,'/ROW/TABLE_NAME') table_name
    18   ,      extractvalue(x.object_value,'/ROW/PARTITION_NAME') partition_name
    19   ,      extractvalue(x.object_value,'/ROW/HI_VAL') hi_val
    20   from   x
    21   ,      TABLE(XMLSEQUENCE(EXTRACT(x.myxml,'/ROWSET/ROW'))) x
    22   where  extractvalue(x.object_value,'/ROW/HI_VAL') = v_value;
    23  end;
    24  /
    PL/SQL procedure successfully completed.
    TABLE_NAME
    PARTITION_NAME
    HI_VAL
    LOGMNR_USER$
    P_LESSTHAN100
    100
    SQL> I'm sure there are other ways as well. Especially with XML functionality, there's normally many ways to skin a cat.

  • Unable to create table with column default value with date interval

    Please help to create table with calculated date defaullt value:
    CREATE TABLE emp (
      birth_date  DATE  DEFAULT sysdate + interval '3' day NOT NULL
    or
    CREATE TABLE emp (
      some_date DATE,
      birth_date  DATE  DEFAULT some_date NOT NULL
    or
    CREATE TABLE emp (
      some_date DATE,
      birth_date  DATE  DEFAULT some_date + interval '3' day NOT NULL
    below syntax error:
    TT1001: Syntax error in SQL statement before or at: "+"

    I'm afraid this is not possible; as per the SQL Reference, TimesTen only supports 'constant expressions' for the DEFAULT clause and none of these are constant expressions.
    Chris

  • Backup DB with dynamic sql - want to substitute in dbname and disk file path

    Re: Backup DB with dynamic sql - want to substitute in dbname and disk file path
    Hope I can explain this. Below is a small snippet of code. I want to set @SQLTemplate_TSQL once at the top of the script and then execute the SET @SQLCommand and sp_executesql in a loop that reads a list of databases. It all works, except for the
    BACKUP DATABASE. Right now it evaluates when the SET @SQLTemplate_TSQL is evaluated. I want it to evaluate when it is executed. I want the DB_NAME() of the USE @dbname.
    -- change @dbname and @dbbackuppath
    DECLARE @SQLCommand NVARCHAR(MAX)
    DECLARE @SQLTemplate_TSQL NVARCHAR(MAX)
    DECLARE @dbname varchar(128) = 'Bank04'
    -- one time setting of @SQLTemplate_TSQL
    set @SQLTemplate_TSQL =
    DECLARE @dbbackuppath varchar(128) = ''''d:\backups''''
    IF RIGHT(@dbbackuppath, 1) <> ''''\''''
    SET @dbbackuppath = @dbbackuppath + ''''\''''
    SET @dbbackuppath = @dbbackuppath + DB_Name() + ''''.bak''''
    PRINT @dbbackuppath
    BACKUP DATABASE ' + DB_NAME() + ' to DISK=''' + QUOTENAME(@dbbackuppath, CHAR(39)) + '''
    -- Execute this several times over different databases
    SET @SQLCommand = '
    USE ' + QUOTENAME(@dbname) + ';
    EXEC(''' + @SQLTemplate_TSQL + ''') '
    PRINT @SQLCommand
    EXECUTE sp_executesql @SQLCommand

    Here is a stripped down version of my code. Someone writes a script. I then take the script and seperate it by GO statement block. Each GO block gets its own row into the
    #SQLTemplate_TSQL. I then replace single quote with 4 quotes and run it. Then I run against my list of databases. I am unable to get the BACKUP DATA base to work with this model.
    Run scripts against multiple databases.sql
    Do a FIND on "CHANGE THIS" to see the databases returned from the SELECT statement
    DECLARE @DatabaseName varchar(128)
    DECLARE @SQLCommand NVARCHAR(MAX)
    DECLARE @SQLTemplate_Seq INT
    DECLARE @SQLTemplate_OperationDesc NVARCHAR(128)
    DECLARE @SQLTemplate_TSQL NVARCHAR(MAX)
    DECLARE @SQLTemplate_Diagnostics INT
    DECLARE @Note VARCHAR(500)
    IF OBJECT_ID('tempdb..#SQLTemplate_TSQL') IS NOT NULL
    DROP TABLE #SQLTemplate_TSQL
    CREATE TABLE [dbo].[#SQLTemplate_TSQL](
    [SQLTemplate_RecID] [int] Identity,
    [SQLTemplate_ID] [int] NOT NULL,
    [SQLTemplate_Seq] [int] NOT NULL,
    [SQLTemplate_OperationDesc] [varchar](128) NOT NULL,
    [SQLTemplate_TSQL] [varchar](max) NOT NULL,
    [SQLTemplate_Diagnostics] [int] NOT NULL,
    [SQLTemplate_Enabled] [int] NOT NULL)
    DELETE FROM #SQLTemplate_TSQL WHERE SQLTemplate_Seq = 65
    DECLARE @SeqID INT
    SELECT @SeqID = MAX(SQLTemplate_ID) FROM #SQLTemplate_TSQL
    SET @SeqID = ISNULL(@SeqID,0)
    SET @SeqID = @SeqID + 1
    INSERT INTO #SQLTemplate_TSQL VALUES(@SeqID ,65,@SeqID,'
    SELECT * FROM ifs_config
    ',1,1)
    SET @SeqID = @SeqID + 1
    INSERT INTO #SQLTemplate_TSQL VALUES(@SeqID ,65,@SeqID,'
    DECLARE @HistoryODS INT
    SET @HistoryODS = 1
    SELECT * FROM ifs_tablelist WHERE HistoryODS = @HistoryODS and Tablename like ''''%HIST%''''
    ',1,1)
    -- Setup Cursor to Loop through each of the Prior Period databases
    DECLARE db_cursor CURSOR FOR
    SELECT [Database Name] --<<<<<<<< CHANGE THIS SELECT statement to select DBs >>>>>>
    FROM v_ifs_PPODSDBInfo_Curr
    WHERE [Database Frequency] <> 'CURRENT'
    ORDER BY [Database Frequency], [Database Number]
    OPEN db_cursor
    FETCH NEXT FROM db_cursor INTO @DatabaseName
    -- Loop through each of the databases
    WHILE @@FETCH_STATUS = 0
    BEGIN
    -- Setup Cursor to Loop through each of the SQL Statements
    DECLARE #SQLTemplate_TSQL_cursor CURSOR FOR
    SELECT [SQLTemplate_TSQL], [SQLTemplate_OperationDesc], [SQLTemplate_Seq], [SQLTemplate_Diagnostics]
    FROM #SQLTemplate_TSQL
    WHERE [SQLTemplate_Enabled] = 1 AND SQLTemplate_Seq = 65
    ORDER BY SQLTemplate_ID
    OPEN #SQLTemplate_TSQL_cursor
    FETCH NEXT FROM #SQLTemplate_TSQL_cursor INTO @SQLTemplate_TSQL, @SQLTemplate_OperationDesc, @SQLTemplate_Seq, @SQLTemplate_Diagnostics
    -- Loop through each of the SQL statements
    WHILE @@FETCH_STATUS = 0
    BEGIN
    SET @SQLCommand = '
    USE ' + QUOTENAME(@Databasename) + ';
    EXEC(''' + @SQLTemplate_TSQL + ''') '
    EXECUTE sp_executesql @SQLCommand
    FETCH NEXT FROM #SQLTemplate_TSQL_cursor INTO @SQLTemplate_TSQL, @SQLTemplate_OperationDesc, @SQLTemplate_Seq, @SQLTemplate_Diagnostics
    END
    CLOSE #SQLTemplate_TSQL_cursor
    DEALLOCATE #SQLTemplate_TSQL_cursor
    FETCH NEXT FROM db_cursor INTO @DatabaseName
    END
    CLOSE db_cursor
    DEALLOCATE db_cursor

Maybe you are looking for

  • When opening a folder, its takes ages to show the files

    Hi All, I have a 2012 Macbook Pro running Lion (as you can probably guess!), with a 512Gb SSD and 8Gb Ram. Its a pretty fast machine and i'm really happy with the way it runs, however when I open a folder to view files, it opens and shows a blank fol

  • 3 USB not showing up in device tree

    Hi folks, I have a May 2010 17 inch Macbook Pro with 3 USB ports on the left side. I was just checking to see that they were USB 2.0. When clicking on the Apple Logo > About This Mac > More Info > USB, shouldn't I see 3 USB High-Speed Bus in the devi

  • Can't change background to graphics - help please?

    Have trawled the help topics but I've been unsuccessful. I'm importing a tif or a jpeg and am getting it onto the browser but then I want to alter the background so the graphic blends in better. Any suggestions on the best way please? Thanks

  • Novice: How do you manually "move" one file above another file

    Hi, Sorry if this a FAQ, I'm an iTunes novice. I have a series of MP3s that need to stay/be played in sequence. Changing/renaming them will be a royal pain. The filenames are numeric, e.g.: 1009x09 1009x10 1011x11 The problem I have as I'm "Importing

  • Roles & Autjorization

    hi all, I am looking for a Reporting scenarios ( prefarably with respect to MM & SD). If u have any documents if u can write here, please do me that favour. Email: [email protected] Points assured Regards Pushkar