Inserting new records into database table at runtime

Hi all ,
How to insert new records into database table at runtime on click update?
Thanks.

Hi Sasikala,
Just for your understanding am giving a sample code snippet which you can use to read the contents of your Table UI element & save the data on to your database. Suppose you have a button up on pressing which you want to read the data from your screens table & save on to the database then you can proceed as shown below:
1) Obtain the reference of your context node.
2) Fetch all the data present in your table into an internal table using methods of if_wd_context_node
3) Use your normal ABAP logic to update the database table with the data from your internal table
In my example I have a node by name SFLIGHT_NODE and under this I have the desired attributes from SFLIGHT. Am displaying these in an editable table & the user would press up on a push button after making the necessary changes to the tables data. I would then need to obtain the tables information & save on to the database.
data: node_sflight           type ref to if_wd_context_node,
        elem_sflight           type ref to if_wd_context_element,
        lt_elements            type WDR_CONTEXT_ELEMENT_SET,
       stru_sflight           type if_main=>element_sflight_node,
       it_flights             type if_main=>elements_sflight_node.
"   navigate from <CONTEXT> to <SFLIGHT_NODE> via lead selection
    node_sflight_node = wd_context->get_child_node( name = 'SFLIGHT_NODE'  ).
   lt_elements = node_sflight->get_elements( ).
"   Get all the rows from the table for saving on to the database
    loop at lt_elements into elem_sflight.
      elem_sflight->get_static_attributes( importing static_attributes = stru_sflight ).
      append stru_sflight to it_flights.
    endloop.
" Finally save the entries on to the database
    modify ZSFLIGHT99 from table it_flights.
    if sy-subrc eq 0.
endif.
However a word of caution here.... SAP doesn't ever recommend directly modifying the database through an SQL query. You would preferably make use of a BAPI for the same. Try go through Thomas Jung's comments in [here|modify the data base table which is comming dynamiclly;.
Regards,
Uday

Similar Messages

  • How to insert new record into oracle table from GridView in VS2005.

    I need to insert records into Oracle10g table from VS2005 GridView using the Insert Method in Business Logic Class. The Update and Delete Methods are working fine. What's the best way out?

    How is it "not possible"?
    Either modify the Class for the new fields, or give the new fields default values (if applicable). If the type of an existing column has changed, then only the first option is available.
    Where's the problem?

  • How to insert new record into altered table

    I am using JDBC with MySQL. I altered existing table and want to insert new record using java class. But it is not possible.How to do?

    How is it "not possible"?
    Either modify the Class for the new fields, or give the new fields default values (if applicable). If the type of an existing column has changed, then only the first option is available.
    Where's the problem?

  • How do you insert new records into multiple tables using the same unique primary key?

    I’ve created a PHP site and MySQL server using a free app called XAMPP.  I have successfully created a form in Dreamweaver that will write data to a (name) table in the SQL database.  Here’s my question: How do you write to two (or more) tables in the same database and pass the same primary key to both tables?  In the SQL database, I defined the first field as ID and set it as the primary key with auto update.  So, when you insert a new record, it creates a unique primary key for that record.  In my form, I’m capturing info that needs to be stored to two tables at the same time; a Name table and Address table. Since the Name and Address tables use the ID field as the primary key, I believe I will need to pass the ID value from the Name table to the insert of the Address table to insure they both have the same primary key, right?

    No. You probably need the primary key from one table to be a foreign key in the other tables. In any case, I believe you can use two methods to obtain the auto generated key. First with SQL:
    http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
    And the other using a PHP function:
    http://us3.php.net/mysql_insert_id

  • Insert multiple records into database through internal table

    Hi
      please help me how to insert multiple records into database through internal table

    Hi,
    Welcome to SCN.
    Press F1 on INSERT statement and you will teh syntax as well the docu for the same.

  • Add a new record in database table without using table maintance generator

    Hi Expart ,
                  Plz. tell me how to add new record in database table without using table maintance ganerator ....give me one ex.
    Regards
    Bhabani

    Hi,
    The other way to safely handle the modification of tables is through is by programs that can be done with SE38 or SE80.
    To insert into database table we use INSERT statement :
    1. To insert a single line into a database table, use the following:
    INSERT INTO <target> VALUES <wa>.
    INSERT <target> FROM <wa>.
    2. To insert a several lines into a database table, use the following:
    INSERT <target> FROM TABLE <itaba>.
    Or even we can use MODIFY statementas this single statement is used to insert as well as update the records of database table.
    MODIFY <target> FROM <wa>.
    or MODIFY <target> FROM TABLE <itab>.
    thanx.
    Edited by: Dhanashri Pawar on Sep 10, 2008 12:25 PM
    Edited by: Dhanashri Pawar on Sep 10, 2008 12:30 PM

  • Entity Framework doesn't save new record into database

    Hy,
    I have problem with saving new record into database using Entity Framework.
    When I run program, everything seems normal, without errors . Program shows existing, manually added records into the database, and new one too. But new one isn't save into database after running program.
    I've got no idea where's problem. There is code for add new record, show existing.
    Thanks for help!!
    // add new record
    using (var db=new DatabaseEntitiesContext())
    var person = new Table()
    First_Name = "New_FName",
    Second_Name = "New_SName",
    PIN = "4569"
    db.Tables.Add(person);
    db.SaveChanges();
    //show all records
    using (var db=new DatabaseEntitiesContext())
    var selected = from x in db.Tables
    select x;
    foreach (var table in selected)
    Console.WriteLine("{0}{1}{2}",table.First_Name,table.Second_Name,table.PIN);

    Hi BownieCross;
    If you are using a local database file in your project the following may be the cause.
    From Microsoft Documentation:
    Issue:
    "Every time I test my application and modify data, my changes are gone the next time I run my application."
    Explanation:
    The value of the Copy
    to Output Directory property is Copy
    if newer or Copy
    always. The database in your output folder (the database that’s being modified when you test your application) is overwritten every
    time that you build your project. For more information, see How
    to: Manage Local Data Files in Your Project.
    Fernando (MCSD)
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects
    and unknown namespaces.

  • To add new record into the table Data Service client

    When I am trying to add new record into the table Employeedetails using Data Service client it is giving a sql exception: "java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK__EmployeeDetails__6383C8BA'. Cannot insert duplicate key in object 'EmployeeDetails'. Severity 14, State 1, Procedure 'PC-P41403 null', Line 1."
    Code:
    DataService ds=DataServiceFactory.newDataService(getInitialContext(),"EmplDetApp","ld:EmplDetAppDataServices/EmployeeDetails");
    EmployeeDetailsDocument edoc=EmployeeDetailsDocument.Factory.newInstance();
    edoc.addNewEmployeeDetails();
    //here I set the primary key value empid
    edet.setEmpid("1212");
    edet.setEmpname("manu");
    ds.submit(edoc);
    Error
    EmpName 5 java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK__EmployeeDetails__6383C8BA'. Cannot insert duplicate key in object 'EmployeeDetails'. Severity 14, State 1, Procedure 'PC-P41403 null', Line 1
    com.bea.ld.dsmediator.DataServiceException: java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK__EmployeeDetails__6383C8BA'. Cannot insert duplicate key in object 'EmployeeDetails'. Severity 14, State 1, Procedure 'PC-P41403 null', Line 1
         at com.bea.ld.dsmediator.update.JDBCAdaptor.save(JDBCAdaptor.java:247)
         at com.bea.ld.dsmediator.update.DataServiceMediator.submit(DataServiceMediator.java:528)
         at com.bea.ld.dsmediator.update.DataServiceMediator.submit(DataServiceMediator.java:245)
         at com.bea.ld.ServerBean.submit(ServerBean.java:529)
         at com.bea.ld.Server_ydm4ie_EOImpl.submit(Server_ydm4ie_EOImpl.java:910)
         at com.bea.ld.Server_ydm4ie_EOImpl_WLSkel.invoke(Unknown Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:492)
         at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:108)
         at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:435)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
         at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:430)
         at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:35)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
         at java.lang.Thread.startThreadFromVM(Unknown Source)
    Caused by: java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK__EmployeeDetails__6383C8BA'. Cannot insert duplicate key in object 'EmployeeDetails'. Severity 14, State 1, Procedure 'PC-P41403 null', Line 1
         at weblogic.jdbc.mssqlserver4.TdsStatement.processWarning(TdsStatement.java:1178)
         at weblogic.jdbc.mssqlserver4.TdsStatement.parseMsWarning(TdsStatement.java:1089)
         at weblogic.jdbc.mssqlserver4.TdsStatement.getMoreResults(TdsStatement.java:756)
         at weblogic.jdbc.mssqlserver4.TdsStatement.execute(TdsStatement.java:210)
         at weblogic.jdbc.mssqlserver4.TdsStatement.executeUpdate(TdsStatement.java:97)
         at weblogic.jdbc.mssqlserver4.TdsStatement.executeUpdate(TdsStatement.java:1455)
         at weblogic.jdbc.wrapper.PreparedStatement.executeUpdate(PreparedStatement.java:147)
         at com.bea.ld.dsmediator.update.JDBCAdaptor.save(JDBCAdaptor.java:151)
         ... 15 more
    But I am not sure why it is giving an exception as Violation of PRIMARY KEY.
    The update method works fine for the same client.
    The exception only happens when I am trying to insert a new record.
    Please help me to figure out this problem.

    If you are absolutely sure that you do not have such a row already in your table, open a case with customer support and reference CR321312. I believe the work-around is to put ld-server-core.jar in your client classpath.
    Correction: put ld-server-app.jar in the client classpath
    Edited by mreiche at 09/17/2007 3:28 PM

  • Insert multiple records into a table(Oracle 9i) from a single PHP statement

    How can I insert multiple records into a table(Oracle 9i) from a single PHP statement?
    From what all I've found, the statement below would work if I were using MySQL:
         insert into scen
         (indx,share,expire,pitch,curve,surface,call)
         values
         (81202, 28, 171, .27, 0, 0, 'C' ),
         (81204, 28, 501, .25, 0, 0, 'C' ),
         (81203, 17, 35, .222, 0, 0, 'C' ),
         (81202, 28, 171, .27, 2, 0, 'C' ),
         (81204, 28, 501, .20, 0, 1, 'C' ),
         (81203, 28, 135, .22, 1, 0, 'C' )
    The amount of records varies into the multiple-dozens. My aim is to utilize the power of Oracle while avoiding the i/o of dozens of single-record inserts.
    Thank you,
    Will

    You could look at the INSERT ALL statement found in the documentation here:
    http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_913a.htm#2133161
    My personal opinion is that you probably won't see any benefit because under the hood I think Oracle will still be doing single row inserts. I could be wrong though.
    The only way to confirm was if you did a test of multiple inserts vs an INSERT ALL, that is if the INSERT ALL met your requirements.
    HTH.

  • Insert Records into database table.

    Hello Friends,
                         I am trying to insert set of records from an Internal table into Database table.
    INSERT SPFLI FROM TABLE ITAB ACCEPTING DUPLICATE KEYS.
    This is my statement. But It inserts only one record in to SPFLI table.
    Cheers
    Senthil

    Hi Sentil,
    USE THIS STATEMENT.
    MOVE-CORRESPONDING ITAB TO SPFLI.
    SPFLI-MANDT = SY-MANDT.
    MODIFY SPFLI.
    thy this....
    <b>reward if useful</b>
    regards,
    sunil kairam.

  • Different methods involved in insertion of records into the table

    hi all,
    i am using Forms [32 Bit] Version 6.0.8.24.1 (Production)
    Oracle Database 10g Release 10.2.0.1.0 - Production
    i have parameters like emp_code(optional) and year(mandatory field-four digit year).
    Based on the parameter i have to get the details from one table and those records should be inserted into other table along with additions columns(by hardcoding the additional columns).
    To acheive this i am planning to get a cursor by selecting the necessay fields from the table passing the parameters in the where clause of the cursor.
    by looping through the cursor i will insert the records into the other table.
    here the thing is the data is going to be huge (since year is the parameter).
    so is my approach leads to the performance issue.
    i heard that there are different method of insetions,
    can anybody suggest me the better way(peformance wise) other than what i have mentioned (if you are aware of)..
    Thanks..

    This is not really a Forms issue, so you'd better go to the sql and pl/sql forum. Here, this question has been asked many times: how do I insert large volumes of data in a table?
    insert into ...
    select ....
    or CTAS (create table as select ....)
    by looping through the cursor i will insert the records into the other table.That is really the worst idea. If you can do it in sql (insert into ... select ...) DON'T do it in pl/sql.

  • Inserting Multiple Records into two table

    I want to insert records from a ADF swing form into two tables. In the first table the primary key is generated by a trigger and then I need to retrieve the primary id generated and then insert multiple records in another table using the primarykey obtained from the first table as foreign key.
    How to do this ?

    User,
    If you're using ADF Business components, have a read on the DBSequence data type. If you have two VO's linked by a view link, and the FK is a DBSequence type, all this happens for you out-of-the-box.
    Hope this helps,
    john

  • Inserting Multiple Rows into Database Table using JDBC Adapter - Efficiency

    I need to insert multiple rows into a database table using the JDBC adapter (receiver).
    I understand the traditional way of repeating the statement multiple times, each having its <access> element. However, I am just wondering whether this might be performance-inefficient, as it might insert records one by one.
    Is there a way to ensure that the records are inserted into the table as a block, rather than record-by-record?

    Hi Bhavesh/Kanwaljit,
    If we have multiple ACCESS tags then what happens is that the connection to the database is made only once. But the data is inserted row by row.
    Why i am saying this?
    If we add the following in JDBC Adapter..logSQLStatement = true. Then incase of multiple inserts we can see that there are multiple
    <i>Insert into tablename(EMP_NAME,EMP_ID) VALUES('J','1000')
    Insert into tablename(EMP_NAME,EMP_ID) VALUES('J','2000')</i>
    Doesnt this mean that rows are inserted one by one?
    Correct me if i am wrong.
    This does not mean that the transaction is not guaranted. Either all the rows will be inserted or rolled back.
    Regards,
    Sumit

  • Update new record in database table

    I'm working with TestStand 4.2 and MySQL database with user-defined tables.
    There is "test_results" table with autoincrement "id" (primary index).
    I want to:
    1. write a new record to the test_results table - some data and status "Running"
    2. run a test (pass to a test sequence its "id", test uses this id for writing data to database)
    3. update the record: set execution time and update status.
    So, the steps are as below:
    1. Open database
    2. Open SQL statement: "select * from test_results".
    3. Data Operation: operation - "Set and Put", record to operate on - "New - Create New Record". In the "Column/Parameter Values" tab I set the new record values.
    Here I want to retrieve the new record "id". How to do it?
    Thanks in advance.

    I am not sure how to implement this in Test Stand, but from an SQL programming perspective, you want to run:
    SELECT @@IDENTITY
    Here is a link to the description:  http://msdn.microsoft.com/en-us/library/ms187342.aspx
    It will retrieve the record ID of the row you just inserted.

  • How i can Insert selected records in database table using check box.

    Hi Friends,
    I have non database block, which displayed multiple records, now I add a Check Box to this block and now I want to insert the records in a database table which I checked. So when I press a button, all the checked records are inserted in the table.
    Please send me the code of this solution.
    Thanks in advance.
    Shahzad

    I have almost the exact scenario but instead of inserting into the DB, I want to find the Checked records and process them in PL/SQL script.
    I currently have a cursor that looks for all the checked records. It's only getting the first record, so I figured I need to loop through the block looking for checked records.
    Also can I save them to a temp or PL/SQL table to process later?

Maybe you are looking for

  • How can I update single plot in multi plot xy graph?

    Hi all, I'm working on an HMI "front" for a larger acquisition/analysis system, that includes continuous performance monitoring of a turbine. The results of the measurements are stored arrays of contour lines, that represents turbine efficiency and g

  • PROCESS CHAIN error "Incorrect start date"

    hi sap gurus, I have parent chain in that a newly created meta chain is creating problem.I am getting error in the process chains since two days i am not able to solve this.Can anybody try to help me. error: Incorrect start date: 00.00.0000; Start ti

  • Why won't it print everything?

    i can't seem to get the first part of my code to print. it just prints the last few iterations but it won't let me scroll up to see the beginning part of my results. does anyone know why this happens? thanks in adavnce. public class GEGS       public

  • All Site Replication connection from particular one Server

    Hi, I have AD structure with multiple Site. All site have one Domain Controller. But KCC automatically create connection from one particular server (DC) for all site DC. Example : I have 5 Site and 5 DC. Each DC belongs to each site. I check all DC c

  • ITunes does not see new Event from iPhoto

    I imported photos from Halloween into iPhoto on my iMac with the intention of displaying them on my AppleTV. In the iTunes - AppleTV - Photos sync page (that displays Photos, Events, Faces) all but the most recent Events are present. I tried "Last Im