QUERY FOR INSERT INTO  SQL TABLE

Hi all,
i want to insert some records into SQL table but not SAP database table. This table is only present in SQL database &
not present in SAP database.
  i want to write a program in SAP to update the SQL table(not present in SAP database). is it possible?
   if yes, plz give me the query for inserting records into SQL table.
Regards

Hello,
working on the same issue:
Try this:
DATA : Begin Of XY Occurs 1000,
        id(15)    TYPE C,
        Name(50)  TYPE C,
        ArtNr(50) TYPE C,
        lieferant TYPE I,
     End Of XY.
Fill this internal Table with the SAP-Table
START Connection to your Database
  EXEC SQL.
      Connect TO 'TEST_FH'
  ENDEXEC.
  IF SY-SUBRC EQ 0.
    EXEC SQL.
    Set Connection 'TEST_FH'     " <-- this is defines with TCode dbco
    ENDEXEC.
    IF SY-SUBRC EQ 0.
    Else.
      " OUT_Msg = '... won't connect'.
      Exit.
    EndIf.  " Else IF SY-SUBRC EQ 0
  Else.
    " OUT_Msg =  'Error at Set Connection Test_FH'.
    Exit.
  EndIf.  " IF SY-SUBRC EQ 0
ENDE  Connection to your Database
START Insert your table XY to an external database
    Loop AT XY.
      Try.
       EXEC SQL.
           INSERT INTO stoff
           (id, name , artnr, lieferant)
           VALUES
           ( :XY-ID,  :XY-Name, :XY-ArtNr, :XY-Lieferant )
       ENDEXEC.
       COMMIT WORK AND WAIT.     " <=== Maybe VERY important
      CATCH cx_sy_native_sql_error INTO exc_ref.
          error_text = exc_ref->get_text( ).
          Concatenate 'Table-INSERT: ' error_text Into error_text.
          MESSAGE error_text TYPE 'I'.
      ENDTRY.
    ENDLoop.     " Loop AT XY     
END   Insert your table XY to an external database
START: Clear Connection
    EXEC SQL.
      DISCONNECT 'TEST_FH'
    ENDEXEC.
END : Clear Connection
Hope it works
Best wishes
Frank

Similar Messages

  • Query for inserting into dynamic partitioned table

    i want to insert into a table which is partitioned (partition name will be obtained dynamically) based on some select statement using execute immediate statement can some one help with query

    First u create table with partition.when u will insert record it will automatically enter in right partition in dynamically.
    and when u will select that record give SELECT query with partition
    Ex:
    SELECT * FROM table_name PARTITION(partition name);

  • Creating a button for inserting into a table

    What I can't do, because I've never needed to, is to create in a page (where I have a Interactive report) a button that when is clicked performs a simple sql (for example an insert into a table using some page item values).
    How can I do it?
    Thanks

    Here are some of the steps:
    1) Create the button.
    2) Then right click on the button name and select Create Dynamic Action
    3) Give the DA a name, click next
    4) On the "When" Step, Event should already be "Click" and the button name should be filled in
    5) For Condition, you would have a condition for when you want the button display.  Say, if your page items have a certain range of values then display this button.  No condition means the button is always displayed.
    6) For the "True Action" Step, for Action select "Execute PL/SQL Code"
        [There are other ways to do this, but this is straight-forward for me.]
    7) The in the PL/SQL Code block enter say:
    Begin
      INSERT INTO EMP (EMPNO, ENAME, HIREDATE)        
              VALUES (:P6_EMPNO, 'MARK1970', :P6_HIREDATE);
      COMMIT;
    END;   --- You would likely make them all page item variables
    8) Here the part I'm not 100% sure of.
        For "Page Items to Submit", name the page items used in YOUR QUERY -- in my example these are  P6_EMPNO,P6_HIREDATE   (Note no use of & or : or . here)
        Hmm.  Start by putting nothing in the "Page Items to Return".   If that fails, then try the same page items  P6_EMPNO,P6_HIREDATE there as well.
    [ I'm too lazy to go run this down at the moment.]
    9) I think that's it.
    Howard

  • Powershell insert into sql table is failling

    function Do-FilesInsertRowByRow ([Data.SqlClient.SqlConnection] $OpenSQLConnection) {
    $sqlCommand = New-Object System.Data.SqlClient.SqlCommand
    $sqlCommand.Connection = $sqlConnection
    $sqlCommand.CommandText = "SET NOCOUNT ON; " +
    "INSERT INTO dbo.dir (Database_Name,Dir_Path,Script_Out_Time) " +
    "VALUES ('$DbName','$Dir',$creation_time);"
    #Invoke-Sqlcmd -Query $CommandText
    $sqlCommand.ExecuteScalar()
    # Open SQL connection (you have to change these variables)
    $DBServer = "svrp00027025"
    $DBName = "Script_Out_Test"
    $dir = "D:\Script_Out\01292015_0156\"+$DBName
    $creation_time = Get-Item $dir | Select LastWriteTime
    $sqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $sqlConnection.ConnectionString = "Server=$DBServer;Database=$DBName;Integrated Security=True;"
    $sqlConnection.Open()
    # Call the function that does the inserts.
    Do-FilesInsertRowByRow ($sqlConnection)
    # Close the connection.
    if ($sqlConnection.State -eq [Data.ConnectionState]::Open) {
    $sqlConnection.Close()
    The above code is failing with an error saying:
    Exception calling "ExecuteScalar" with "0" argument(s): "Must declare the scalar variable
    At line:16 char:5
    +     $sqlCommand.ExecuteScalar()
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : SqlException

    I tried using the below script. I was able to print just the time on the console but it is not storing into the variable.. .
    $creation_time=$creation_time-match@{LastWriteTime=(?<content>.*)}
    $matches ['content']

  • JDBC Receiver adapter Error for insert into DB2 table

    Hi all,
    I want to insert data into a DB2 table on AS400 via a Receiver JDBC adapter.
    The communication channel seems to be ok but when I try to send the message, I obtain the following message on the adapter monitoring :
    Error: TransformException error in xml processor class, rollback:
    Error processing request in sax parser: Error when executing statement for table/stored proc. 'GIK.GDT01' (structure 'Statement'): java.sql.SQLException: La table GDT01 de la bibliothèque GIK est incorrecte pour cette opération.
    Could someone help me?
    In the communication channel I have seen we can choose "native SQL String" as message protocol.
    Do you think it could be a workaround for me? if yes, could someone send me an example about it?
    thanks a lot,
    Philippe

    Hi,
    Try to remove GIK.GDT01 in table tag of your XML structure and put GDT01 alone and see.
    The solution to your problem is found on this particular link.
    http://www.websina.com/bugzero/faq/exception-as400.html
    Tell me if it works
    Best regards,
    Felix

  • Using Bulk operations for INSERT into destination table and delete from src

    Hi,
    Is there any way to expediate the process of data movement?
    I have a source set of tables (with its pk-fk relations) and a destination set of tables.
    Currently my code as of now, is pickin up the single record in cursor from the parentmost table, and then moving the data from other respecitve tables. But this is happening one by one... Is there any way I can make this take less time?
    If I use bulk insert and collections, i will not be able to use the DELETE in the same block for same source record.
    Thanks
    Regards
    Abhivyakti

    Abhivyakti
    I'm not 100% sure how your code flows from what you've stated, but generally you should try and avoid cursor FOR LOOPS and possibly BULK COLLECTING.
    I always follow the sequence in terms of design:
    1. Attempt to use bulk INSERTS, UPDATES and/or DELETES first and foremost. (include MERGE as well!)
    2. If one cannot possibly do the above then USE BULK COLLECTIONS using a combination of RETURNING INTO's and
    FORALL's.
    However, before you follow this method and if you relatively new to Oracle PL/SQL,
    share the reason you cannot follow the first method on this forum, and you're bound to find some
    help with sticking to method one!
    3. If method two is impossible, and there would have to be a seriously good reason for this, then follow the cursor FOR LOOP
    method.
    You can combine BULK COLLECTS with UPDATES and DELETES, but not with INSERTS
    bulk collect into after insert ?
    Another simple example of BULK COLLECTING
    Re: Reading multiple table type objects returned
    P;

  • How to delete the Table Contents before inserting records into SQL table ?

    Hello Experts,
            I have a scenario where in I have to Pick up some records from SAP RFC & insert into SQL table.
            i know how to do this scenario but the proble with this is before inserting we first have to ZAP the SQL table & insert a new records. One more twist is The Triggering is happening from SAP side with Sender RFC. If this would have been from SQL Side i could have written a Stored Procedure/ Trigger & could have called this before the SENDER JDBC communciation channel picks up the Triggering event from SQL side.
    So how to do this scenarioin XI, First deleting all the Records of SQL table & then inserting the new reocrds. without using the BPM.
    Regards,
    Umesh

    hi umesh,
    you can achieve this by writing SQL query in message mapping level..
    refer this link:
    http://help.sap.com/saphelp_nw04/helpdata/en/b0/676b3c255b1475e10000000a114084/frameset.htm
    regards.

  • Fetch data from one table and insert into two tables in desired format

    I have similar to the following data in a table and it is not normalized. The groupID is being used to group two records of similar nature.
    DECLARE @OldDoc TABLE (oldDocID INT, groupID INT, deptID INT)
    INSERT INTO @OldDoc (oldDocID, groupID) VALUES (1, NULL, 111),(2,NULL,111),(3,1,111),(4,NULL,333),(5,1,222),(6,NULL,333),(7,2,222),(8,2,333),(9,NULL,111),(10,3,222),(11,NULL,333),(12,3,444)
    I need to process the data from the above table (@OldDoc) and write into two new tables (@NewDoc and @NewDocGroup) as follows.
    oldDocID should be stored as newDocID when inserting to @NewDoc table. Only records with groupID NULL and one record (first one) per group should be considered (For example, oldDocID 5 is not considered as 3 and 5 belong to the same groupID 1) for insertion. 
    DECLARE @NewDoc TABLE (newDocID INT)
    INSERT INTO @NewDoc (newDocID) VALUES (1),(2),(3),(4),(6),(7),(9),(10),(11)
    All records from @OldDoc should be considered for insertion into @NewDocGroup table. OldDocID is inserted as NewDocID and deptID is as-is. Instead of groupID, the ID of the first record in the 
    group should be considered as parentNewDocID (For example, 3 is considered as parentNewDocID for newDocID 5 as 3 and 5 belong to the same groupID in @OldDoc table) for the newDocID.
    DECLARE @NewDocGroup (newDocID INT, parentNewDocID INT, deptID INT)
    INSERT INTO @NewDocGroup (newDocID, parentNewDocID, deptID) VALUES (1,1,111),(2,2,111),(3,3,111),(4,4,333),(5,3,222),(6,6,333),(7,7,222),(8,7,333),(9,9,111),(10,10,222),(11,11,333),(12,10,444)
    How do I accomplish the above using SQL ? Thanks for the help.

    >> I have similar to the following data in a table and it is not normalized. The group_id is being used to group two records [sic] of similar nature. <<
    Rows are not records. Tables have to have a key by definition. You do not do math with identifiers, so they should not be numeric. Let's ignore that error for now. In short, you are posting garbage. If you had followed Forum Netiquette, would you have posted
    this? 
    CREATE TABLE Old_Documents
    (old_doc_id INTEGER NOT NULL PRIMARY KEY, 
     group_id INTEGER, 
     dept_nbr INTEGER NOT NULL
       REFERENCES Departments (dept_nbr));
    INSERT INTO Old_Documents(old_doc_id, group_id, dept_nbr) 
    VALUES  (1, NULL, 111), 
    (2, NULL, 111), 
    (3, 1, 111), 
    (4, NULL, 333), 
    (5, 1, 222), 
    (6, NULL, 333), 
    (7, 2, 222), 
    (8, 2, 333), 
    (9, NULL, 111), 
    (10, 3, 222), 
    (11, NULL, 333), 
    (12, 3, 444);
    >> I need to process the data from the above table (Old_Documents) and write into two new tables (New_Documents and New_Documents_Groups) as follows. <<
    Just like punch cards and mag tape data processing! Being old and being new are a status, not another kind of entity. But that is how mag tapes work. And you even use the verb "fetch" from tape files. This design flaw is called  attribute splitting.
    Do you have a Male_Personnel and Female_Personnel table? NO! It is just Personnel! 
    >> old_doc_id should be stored as new_doc_id when inserting to New_Documents table. Only records [sic] with group_id NULL and one record [sic] (first [sic; no ordering in a table] one) per group should be considered (For example, old_doc_id 5 is not considered
    as 3 and 5 belong to the same group_id =1) for insertion. <<
    Think about your punch card mindset. Why did you physically materialize that redundant New_Documents table? Let me answer that: this is how you work with punch cards! In SQL we use a VIEW:
    CREATE VIEW New_Documents (new_doc_id)
    AS 
    SELECT old_doc_id 
      FROM Old_Documents;
    >> All records [sic] from Old_Documents should be considered for insertion into New_Documents_Groups table. The old_doc_id is inserted as new_doc_id and dept_nbr is as-is. Instead of group_id, the ID [sic: which identifier??] of the first [sic: tables
    have no ordering like a deck of punch cards] record [sic] in the group should be considered as parent_new_doc_id (For example, 3 is considered as parent_new_doc_id for new_doc_id 5 as 3 and 5 belong to the same group_id in Old_Documents table) for the new_doc_id.
    <<
    Why not use 5 as the parent? My guess is that you are trying to form equivalence classes. See:
    https://www.simple-talk.com/content/print.aspx?article=2020
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Build a sql query fro different table and insert into a table

    Hi I have a requirement ,
    i have some table 1 table which holds rules which rules i have to apply on the sql query
    2 table will hold table name and column name and transformation
    with these help of 2 tables i want to build a sql quey and the sql query need to be insert into another  table.

    Hi Karthick,
    I am not going to build Dynamic Data Model.
    i already have table 1 contains rules let's say COUNT,
    and another table contain source table name , column name , Target table name, Source Table name like that
    so with the help of these 2 tables i want to build Sql query and going to insert into 3rd table.

  • How to Improve inserts into Template table for Query Processing

    Hi guys!
    I need your advice. How can i improve inserts into template table (/BI0/0P00000010 for exemple)? In my scenario i forced to load data from cube C_X to cubes C_1, C_2 and C_3.
    To get a goal i created a transformations and a DTP process with delta upload to each of cubes (C_1, C_2, C3). And that proccess takes about 3 hours! (it doesn't matter 1.000 or 100.000 records). But when i tried to load data with full update (with a filter) a proccess get data takes about 1 minutes.
    I traced process and saw that inserting into template table (which create each time when proccess started) take the longest time. How can i improve it?

    Hi Mahendar,
    It will require some efforts to investigate it so I propose to open a support ticket with Microsoft (through portal).
    Your first question interest me and I am not sure if you are doing proactive or reactive real time reporting. You can try with
    HBase for storing and retrieving data. HBase known for providing good read and write speed. If you are not comfortable writing HBase syntax then you can add an abstraction layer i.e. HIVE. It might take little more time when you
    query HBase from Hive.
    If you are doing real time analytic, then you can choose from Strom and Microsoft Azure Stream Analytic.
    Thanks and Regards,  
    Sudhir Rawat

  • Looking for an insert statement to insert into a table around 500 rows

    Hi  Gurus,
    Your help is greatly appreciated !!,
    I need to have a query to insert into the mer_spec_feature table with the following , Please sugesst apart from the Utl_file ,input thing
    as the data is differnt in the regions and am lokking if it workes out with a insert and select query .
    1)I have to create a  script for inserting records into  mer_spec_feature where  on appl_id ‘VXRR’
    having feature ID 786 and have to Exclude TIDs which already have the 786 feature added for this appl_id like in the eblwo select query .
    2)There are 509 such TIDs where it doesnt have the 786 feature with appl_id -'VXRR' in the mer_spec_feature table
    3)
    select distinct terminal_id,  appl_id, from  mer_spec_feature
    where appl_id = 'VXRR'
    minus
    select distinct terminal_id, appl_id from mer_spec_feature
    where appl_id = 'VXRR'
    and terminal_feature_id = 786
    desc mer_spec_feature :
    Terminal_id  --varachr2(9)
    appl_id    --varcahr2(10 )
    terminal_feature-id --number(8)
    TERMINAL_FEATURE_ID
    TERMINAL_APPL_ID
    TERMINAL_ID
    299
    405T330a
    1004665
    786
    VXRR
    1004665

    @Frank Kulash !!
    Thanks always for your replys .!!
    i have tried with the above sql , and am having issue with the pk constraint after inserting  232 rows.
    And a Tertminal_id  will have 100 feature_id's for one  appl_id.
    becoz it has pk constraint on  -- TERMINAL_FEATURE_ID, APPL_ID, TERMINAL_ID
    TERMINAL_FEATURE_ID
    APPL_ID
    TERMINAL_ID
    299
    405T330a
    1004665
    786
    VXRR
    1004665
    can you please sugeest any other option.

  • RE:ora-28500 when trying to insert into SQL Server table

    Hi all!
    I'm getting this when i attempt to insert into my table test in a SQL Server database. As u can see from the select, the database link seems ok. Any ideas plz. Thnx..
    SQL> select "idAges" from test@try2;
    no rows selected
    SQL> insert into test@try2 ("idAges","nARAges","nAPAges") values(10,'','');
    insert into test@try2 ("idAges","nARAges","nAPAges") values(10,'','')
    ERROR at line 1:
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    [Generic Connectivity Using ODBC][Microsoft][ODBC SQL Server Driver][SQL
    Server]Cannot insert explicit value for identity column in table 'test' when
    IDENTITY_INSERT is set to OFF. (SQL State: 23000; SQL Code: 544)
    ORA-02063: preceding 2 lines from TRY2

    IDENTITY_INSERT on works only for particular session and for one table. It's not global variable.
    The only idea what I have is to create link from MS Sql to Oracle (right now You have oracle ->ms sql)and then before insert You will set identity_insert on and will run insert.

  • How to insert into SQL server table form oracle forms

    I created a form with oracle as my database. But there one trigger where I need to insert the data into a sql server table.
    Is this possible. If so can any help me out.
    Thanks in advance.
    Asha

    Hi,
    You can insert into sql server database using the following steps
    Note: Check wether you are using Forms 32 bit drivers. If not the Odbc data source will not work.
    step 1: Create ODBC data source for SQL server(one time creation);
    step 2: Logout from Oracle and login to SQL server giving the user name,password and host string as odbc:<odbc datasource name>;
    step 3: use EXEC SQL statement to insert the values into the SQL server and then logout and login again to your oracle database.
    Second Method.
    Check the sql server documentation to insert the values using command line parameters. Then you can call the host command to execute this.
    Third Method.
    Write a VB exe to enter the values in the sql server making two connections one to oracle another to SQL server and then getting values from Oracle and putting in the SQL server database. You can call this exe using the Host command.
    Hope this will help You.
    Regards
    Gaurav Thakur

  • "Create Table from select Query" Vs "Insert into"

    Hi
    Schenaio:
    My Select Query returns more than 10 million records, these records needs to be inserted into another table.
    Approach 1:
    I created table called TABLE1, and inserted the records using INSERT statement as a batch (batch size is 5000).
    Approach 2:
    I create table like,
    CREATE TABLE TABLE1 AS <SELECT QUERY>
    Here Apporach-1 took almost 40 minutes to complete the insert but Approach-2 took only 6 minutes.
    If anybody knows why it is? And is there any way to improve the performance of Approach-1?.
    Thanks
    Nidhi

    Most "batch" methods execute the same query multiple times. Row filtering is done after the rows are fetched from the source. The process of fetching all the rows could be a FullTableScan.
    Therefore, a FullTableScan is executed for each batch of 5000 rows.
    However, your query and batch definitions may well be different. We haven't seen the query and the execution plan.
    Another point : How are you "filtering" the rows (i.e the second execution inserts rows 5001 to 10000 and does not attempt to reinsert rows 1 to 5000) ?
    What is the overhead imposed by the filter ? (does the third execution have to exclude rows 1 to 10000 and inserts rows 10001 to 15000 and so on)
    Hemant K Chitale

  • Query for inserting data from OAF page to database table

    I need to insert a row into a table by getting parameters from pageContext. The fields in this page are from multiple view objects and the data in these fields should be inserted into a table. If anyone can provide solution in this regard will be very much helpful.

    Hi Rma,
    My Understanding is...
    Say you want to display information of 10 customers. Hence there will be 10 rows to display.
    Say number 5 customer has maximum accounts 15 (In case there is variable number of accounts for each customer). Hence there will be max 15 columns.If the above under standing is correct, then a question...is there an upper limit on number of accounts for a customer?
    If yes then I may say...
    Create a custom table with that many columns as of max number of alloweed accounts.
    Write a plsql api to insert column of existing table as row in the custom table.
    Now base your EOs and VOs on that custom table. That may show columns in term of rows on your screen.
    The logic is, instead of converting column data to row in oaf, do it in plsql.
    Now again if it has to be updated by user, create a reverse api to put data from custom table to existing table.
    However, this approach can lack automatic features on existing seeded table(like validations), provided by EO. Hence you must explore PL/SQL Entity objects in Dev guide before going with this approach (both are near same but you may be able to better judge which one will be more suitable for your need.
    Another insant approach which strike in mind is just modifying logic in controller to modify bean hierarchy (adding columns at run time) or by create VO dynamically.
    However, possibly that can put other complexities of personalization and maintainance of code etc.
    Hence the suggestion is...Evaluate all three and judge which one is most suitable for you over all needs (First try with PL/SQL Base EOs Or with the above approach or pure java manipulation)
    Seems too complex approaches all. Other users must pour there thoughts.
    Abdul Wahid

Maybe you are looking for