Overwriting an existing record.

Hi..
I want to know whether we can overwrite an existing record in a database table.
That is when a user accidently insert a data for a particular primary key which is already existing, the data entered latter should be overwirted?..
Please help me..

You can use a syntax like this :
begin
    insert into <table> values(<Empid>,<Name>,<No.of resource>);
exception
    when dup_val_on_index then
      update <table) set Name = <Name>, No_of_resource = <No.of resource>
      where Empid = <Empid>;
end;

Similar Messages

  • Creating new records while querying existing record

    Hi,
    I have one master - detail form.
    First i created 1 record. Request ID is the primary key. Now request id generated. For ex.: 10
    Request Id, date, requestor , location, status fields are in header block.
    In lines block, i hv some other fields.. and one field called 'Activity'.
    While creating first record, the activity will be 'New'.
    Then i'll query the record '10'.
    when i'm changing the activity 'New' into 'Upgrade', it should create new record with new request ID.
    How to do this?
    I hv written procedure that, i'm taking field values to local variables. Then assigning the local variable values to field values.
    It is not creating as new record. It overwriting the existing record with new values. Existing record is missing.
    Pl. give steps.
    Thanks
    Kavi

    Hi,
    Okk, you will have to do two things. Create two trigger on block level on which you want to do your changes.
    1. First trigger. (PRE-UPDATE)
    In pre-update trigger u will have to write the complete insert statement into the same table with new req id. like
    DECLARE
    vReqNo DATA_TYPE;
    BEGIN
    SELECT MAX(REQ_ID)
    INTO vReqNo
    FROM your_table;
    INSERT INTO your_table
    (req_no, fields....)
    VALUES
    (vReqNo, :forms_values);
    END;
    2. Create 2nd trigger on block level (ON-UPDATE)
    write in this trigger
    NULL;
    for viewing the inserted record. What u have to do is in ON-UPDATE after null; create one timer NO_REAPEAT.
    and in timer u will have to set the block property to req_id = generated_req_id_from_pre_update_trigger and
    execute_query;
    hope it will work...
    -Ammad

  • Workflow rules doesn't work for existing record!!?!?!?

    Hi all,
    I've created one workflow rule to update value from one filed to another. Here is my expression:
    [<QuickSearch1>] <> [<plStatus_ITAG>]
    and my action is
    field name = "*Status" (QuickSearch1)
    Value = <plStatus_ITAG>
    and I tick on the Overwrite the existing value
    This is work for new record, but for the existing one the field value doesn't chnage. Any suggestion??
    Thanks
    Note

    The syntax should be: PRE('< QuickSearch1>') <> [<QuickSearch1>] for the condition.

  • Keeping existing record

    how can i prevent my existing records from overwrite by new records everytime i input a new data
    here's my code
    String filename = "payments";
    try
                   output = new DataOutputStream(new FileOutputStream(filename));
              catch(IOException io)
                   JOptionPane.showMessageDialog(null,"The program could not create a storage location. Please check the disk drive and then run the program again.","Error",JOptionPane.INFORMATION_MESSAGE);
                   System.exit(1);
              }

    Append to the file. When you instantiate your FileOutputStream, do something like:
    output = new DataOutputStream(new FileOutputStream(filename,true));

  • How to only update existing records when loading master data ?

    Hello experts, I need your lights one more time.
    Here is my need :
    I have created an infoobject (IO) which is a very simple version of 0material, let's call it Znewmat --> Znewmat has material type and trademark as attributes, those two fields are available in 2 different datasources :
    - 0MATERIAL_ATTR for material type (field MTART)
    - 0MAT_SALES_ATTR for trademark (field MVGR2)
    When loading my new IO from 0MATERIAL_ATTR I use a filter (at DTP level) to get only a few material types (I get something like 1000 records),
    here is my issue : when I load from 0MAT_SALES_ATTR the field "material type" is not available to keep the same filter as for 0MATERIAL_ATTR and existing records are updated with the trademark, but I also get 5000 records I don't need, and my master data is "polluated" with useless lines.
    *and my question : is there a way while performing the second loading to ONLY UPDATE EXISTING RECORDS AND NOT ADD ANY
    NEW RECORDS ? (i didn't find anything in main options of my DTP)*
    (I'd like to avoid the solution to update the 0MAT_SALES_ATTR datasource to add the missing field)
    Thanks in advance for any help, points will be distributed.
    Guillaume P.
    Still no idea ?

    in the start routine of transformation from 0MAT_SALES_ATTR to znewmat do the following:
    select materials from /BIC/PZNEWMAT into i_mat
    for all entries in source_package where material eq source_package-material.
    loop at source_package.
    p_ind = sy-tabix.
    read table i_mat with key material = source_package-material.
    if sy-subrc ne 0.
    delete i_mat index p_ind.
    endif.
    this way you'll only update records that have previously been loaded by 0MATERIAL_ATTR DS
    loading sequence:
    first load ZNEWMAT from 0MATERIAL_ATTR. then activate ZNEWMAT. then load 0MAT_SALES_ATTR to ZNEWMAT.
    M.

  • How to write the new records not with existing records.

    hi,
    I have a script.If i execute the script it writes the records.but its writing with the exisiting records.It writes not only the new records but also the old records.
    for eg: the exisiting records are:
    1111115-2,USD,DINESH,1,1,,,,9,,,,123456184001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111116-2,USD,DINESH,1,1,,,,9,,,,123456184001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111117-2,USD,DINESH,1,1,,,,9,,,,123456184001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111118-2,USD,DINESH,1,1,,,,9,,,,123456184001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111119-2,USD,DINESH,1,1,,,,9,,,,123456184001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    but now what happend is the new records such as
    1111116-2,USD,DINESHBABU,1,1,,,,9,,,,123456184003,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111117-2,USD,DINESHBABU,1,1,,,,9,,,,123456184003,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111118-2,USD,DINESHBABU,1,1,,,,9,,,,123456184003,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111119-2,USD,DINESHBABU,1,1,,,,9,,,,123456184003,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    it gets appended with the old existing records,
    1111117-2,USD,DINESH,1,1,,,,9,,,,123456184001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111118-2,USD,DINESH,1,1,,,,9,,,,123456184001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111119-2,USD,DINESH,1,1,,,,9,,,,123456184001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111113-2,USD,DINESHBABU,1,1,,,,9,,,,123456184003,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111114-2,USD,DINESHBABU,1,1,,,,9,,,,123456184003,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111115-2,USD,DINESHBABU,1,1,,,,9,,,,123456184003,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111116-2,USD,DINESHBABU,1,1,,,,9,,,,123456184003,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111117-2,USD,DINESHBABU,1,1,,,,9,,,,123456184003,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111118-2,USD,DINESHBABU,1,1,,,,9,,,,123456184003,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    1111119-2,USD,DINESHBABU,1,1,,,,9,,,,123456184003,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,9999,,,,
    there will be some problem happens when we are going to upload a bulk data of say 25000 records.if its gonna update 20000 records,rest 5000 records i have to do it in next step,if this is going to happen then the first 20000 records will be displayed forever.because it have the capacity to write 20000 records.thenext 500 records will not be written.so there is a chance of redundancy.how to avoid this redundancy while running this script
    my script is
    create or replace procedure input_tables(table1 in varchar2)
    is
    str varchar2(32767);
    cnt number(2);
    cursor c1(tname in varchar2)
    is
    select column_name
    from all_tab_columns
    where table_name = tname
    order by column_id;
    rec c1%rowtype;
    begin
    cnt:= 1;
    str:= 'declare '||
    'cursor c2 '||
    'is '||
    'select ';
    open c1(table1);
    loop
    fetch c1 into rec;
    exit when c1%notfound;
    if cnt = 1 then -- Added New
    str:= str||rec.column_name; -- Added New
    cnt:= cnt + 1; -- Added New
    else -- Added New
    str:= str||'||'',''||'||rec.column_name; -- Added New
    end if; -- Added New
    end loop;
    close c1;
    str:= str||' SRC from '||table1||';'||
    ' r2 c2%rowtype;'||
    ' ft UTL_FILE.file_type;'||
    ' str2 varchar2(200);'|| --Added New
    ' begin '||
    ' ft := UTL_FILE.fopen(''SAMPLE'',''OUTPUT.csv'',''w'');'||
    ' for r2 in c2'||
    ' loop '||
    ' UTL_FILE.put_line(ft,r2.SRC);'||
    ' end loop;'||
    ' UTL_FILE.fclose(ft);'||
    ' end;';
    execute immediate(str);
    end;
    thanks,
    Ratheesh.

    Hi!
    U can check the following script --
    create or replace procedure input_tables(table1 in varchar2,start_col in number,last_col in number)
    is
         str varchar2(32767);
         cnt number(2);
         cursor c1(tname in varchar2)
         is
           select column_name
           from all_tab_columns
           where table_name = tname
           order by column_id;
         rec c1%rowtype;
    begin
         cnt:= 1;
         str:= 'declare '||
         'cursor c2 '||
         'is '||
         'select ';
         open c1(table1);
         loop
              fetch c1 into rec;
              exit when c1%notfound;
                   if cnt = 1 then -- Added New
                        str:= str||rec.column_name; -- Added New
                        cnt:= cnt + 1; -- Added New
                   else -- Added New
                        str:= str||'||'',''||'||rec.column_name; -- Added New
                   end if; -- Added New
         end loop;
         close c1;
         str:= str||' SRC from '||table1||
         ' where rownum between '||start_col||' and '||last_col||';'|| -- Added New
         ' r2 c2%rowtype;'||
         ' ft UTL_FILE.file_type;'||
         ' str2 varchar2(200);'|| --Added New
         ' begin '||
         ' ft := UTL_FILE.fopen(''SAMPLE'',''OUTPUT.csv'',''w'');'||
         ' for r2 in c2'||
         ' loop '||
         ' UTL_FILE.put_line(ft,r2.SRC);'||
         ' end loop;'||
         ' UTL_FILE.fclose(ft);'||
         ' end;';
         execute immediate(str);
    end;
    / To print first ten rows --
    exec input_tables('EMP',1,10);  --first 10 rowsTo print next remain rows --
    exec input_tables('EMP',11,15);N.B: No tested....
    Regrads.
    Satyaki De.

  • JDBC Scenario: Delete all the existing records and Insert

    Dear All,
    Scenario: IDoc to JDBC
    PI need to delete all the existing records in the SQL table then need to insert the records.I have created a two statements in the target structure.
    Statement1
       -> TableName
           -> action : DELETE
           -> Table : TableName
    Statement2
       -> TableName
           -> action : INSERT
           -> Table : TableName
           ->Access
               -> Elements
    I am getting below error while try to delete the records in the table.
    JDBC message processing failed; reason Error processing request in sax parser: Error when executing statement for  table/stored proc. 'Tablename' (structure 'Statement1'): java.sql.SQLException: FATAL ERROR document format: structure 'Statement1', no key element found
    Note: we use above structure in the another interface without specifying any Key for Delete operation(Server is same but different database for this two interface) and it works fine. Although the Primary keys has been set in the SQL table i am getting the above error.
    let me know what are the setting need to make in PI and SQL DB to achieve this.
    Regards,
    Manikandan Shanmugam
    Edited by: Manikandan Shanmugam on Nov 8, 2011 6:19 AM

    The straucture what you have deined for Delete is not correct, you should have key field in statement structure then only you can perform Delete operation.
    refer below link
    http://help.sap.com/saphelp_nwpi71/helpdata/EN/44/7b6e85fde93673e10000000a114a6b/content.htm
    Regards,
    Raj

  • (Administration - Marketing - Import), you can set a parameter value "Import mode" for what to do in case of duplication as "update existing records", "Import new records". The final report of this import is presented as a text file that can be viewed in

    Administration - Marketing -> Import, you can set a parameter value "Import mode" for what to do in case of duplication as "update existing records", "Import new records". The final report of this import is presented as a text file that can be viewed in Business Administration - Marketing -> Import -> Exceptions. Whatever the exception, including duplication import occurs during import and recorded in a text file.   What are the fields that determine the duplicity? How I can I can change those?

    You will be returned anything that is in the option's value parameter. What is displayed in the dropdown and what is put in the value attribute do NOT need to be the same, so maybe you should start there.

  • Howto use an existing record as template in a create new record form

    hi all,
    I have a table with configuration lines, Currently accessible via a report/form combination. This works fine to create, view & edit data.
    However users often need to create a new record which is 90% like an existing record.
    So what they want is to go to an existing record and use it as template for creating a new record (by clicking a button "create copy from"
    My solution attempt
    -when the button is pressed send users to the normal create form, and prefill some of the items with data from the "template record", after which everything is the same as creating a record from scratch
    What did I try
    - as above redirect user to the "create page" and sent the desired items values via URL Syntax. Failed since I have about 20 items and the button settings won't allow me to add more then 10 (besides it not a pretty sight)
    - Instead of sending via URL I've tried only sending the record id for the template and have a "before header process" load the item values in session state. Failed since the page items are all (load form source each time) since they are database columns
    Constraints for the solution
    - No, I can't go first inserting a copy of the record and then display it in edit mode since the remaining 10% of the record can not to be copied because of table constraints. They have serious constraints, which needs user input.
    - (and no I can't first insert dummy data, that's a poor man's solution)
    - I'd like to reuse the current create/edit form since it contains quite some business rules and constraints. So dubbing the page will put me up with a double load of maintenance in case of future changes in business rules
    I'd appreciate any good clues in solving this requirement
    best regards,
    Geert

    Hi Shunt,
    Not entirely what I wanted accomplished but it held the key.
    Removing the PK wouldn't trigger the DML to respond differently on it's own, since the DML decides the database action based on the request.
    I have the create/edit page working on with a "COPY" request
    This way I can call the page both from the report as the form page.
    When called with COPY request the page is loaded as normal edit except
    - I hide the delete and apply changes button
    - I show the create button
    When the create button is pressed a computation removes the PK
    Since the create button is pressed instead of apply_changes it will indeed perform an insert
    Thanx again for the hint
    Sometimes you need an new perspective
    Geert

  • Overwriting an existing document in a KM folder

    Hi.
    In EP5 (SP5) you got prompted ("do you want to overwrite or not") when ever you tried to upload a document to a KM folder and that document already existed in that specific folder.
    In EP6 (NW04) though you are not prompted anymore but the file is uploaded with an "_[number]" added to the document id (you are informed though that a file already exists and that the new file is saved as described before).
    Is there a setting somewhere where you can choose to be prompted or not when uploading an already existing document to a folder or do we have to live with this feature?
    Thanks in advance.
    BR
    Søren Bessermann

    Hi,
    This should be fixed in Stack 11. The behavior is not configurable. You now get something like this:
    <b>An item with this name already exists. You can overwrite the existing item or create a new item with the same name or a different name. Overwriting the existing item will retain any additional information associated with that item such as the description or any annotations.
    o Overwrite the existing item, retaining associated information
    o Save As   [ uploaded filename in input box ]
    [Ok] [Cancel]</b>
    The overwrite option is selected by default.
    Regards,
    Darin Krasle

  • Problem in modifying existing records in dbtab

    Hi Experts,
    I am doing a report where I have created two dbtab's , one for data getting saved and
    other for fetching data and modifying exsiting records..
    For eg - let ZABC be the table where I need to insert or update records and ZXYZ is the table where
    I need to fetch and modify existing records.
    Now my probelm is :
    In case of inserting new records (multiple records ) into my dbtab ( ZABC ) its working ,
    but modifying existing records in another dbtab (ZXYZ ) its not wroking !! plz advice !!
    If my select querry for modifying exsiting records is:
    SELECT *  FROM ZXYZ  INTO TABLE ITAB WHERE MATNR EQ S_MATNR.
    *****then its inserting a newline along with the existing records.
    but when my querry is,
    SELECT single *  FROM ZXYZ  WHERE MATNR EQ S_MATNR.
    then its modifying the existing records, but only the first record.
    Loop at itab.
    if sy-tabix  = 1.
    zabc-matnr = matnr.
    zabc-idnrk  = idnrk.
    zabc-budat = s_budat.
    zabc-menge = menge1.
    ZXYZ-menge = ZABC-Menge + MENGE1.
    ZXYZ-BALC  = ZXYZ-Menge   -   MENGE1.
    ELSEIF sy-tabix  = 2.
    zabc-matnr = matnr.
    zabc-idnrk  = idnrk.
    zabc-budat = s_budat.
    zabc-menge = menge2.
    ZXYZ-menge = ZABC-Menge + MENGE2.
    ZXYZ-BALC  = ZXYZ-Menge  -  MENGE2.
    ELSEIF sy-tabix  = 3.
    zabc-matnr = matnr.
    zabc-idnrk  = idnrk.
    zabc-budat = s_budat.
    zabc-menge = menge3.
    ZXYZ-menge = ZABC-Menge + MENGE3.
    ZXYZ-BALC  = ZXYZ-Menge   -  MENGE3.
    ENDIF.
    INSERT ZABC.
    IF SY-SUBRC EQ 0.
    MODIFY ZXYZ.
            IF SY-SUBRC = 0.
              MESSAGE : I002 WITH 'RECORD CREATED'.
                ENDIF.
    ENDIF.
    Please advice
    Karthik
    Edited by: Karthik R on Aug 24, 2009 9:42 PM

    Hi,
    This is because in the second case you are not selecting records into an internal table.
    As a result only the first record which satisfies the where condition is fetched.
    Check if the program goes into the loop when you write second select query.
    KR Jaideep,

  • How to create idocs  for  existing records

    Hi
    are there any standard program by which i could create and send the existing customer invoice (VF01) data thru EDI idoc to a 3rd party system even if the output type is not defined during the creation of the invoices?
    Regards
    Sujai

    I am supposed to send all customer invoice data to an external system. I have been able to configure the system to trigger an idoc when an invoice is saved. That takes care of my delta transfer. But i would like to know if there is a way by which i can send all the existing customer invoice data to the 3rd party system that were already created in the SAP system. Something like an initial download of all the existing records.
    I am asked to keep the abap development to Zero as far as possible, hence i am exploring the idea of finding any standard program that could do this for me.
    just like Tx: BD10 for the material master data.
    I tried VF31 but the problem is that the invoice that would have been created might not contain the output type as EDI. So is there a way by which i can achieve this task with any standard program?
    I also have another question:
    how do i do the configuration to send all the SD invoices to a specific partner all the time thru EDI by default?
    Sujai

  • BDC for existing record in table control

    Hi,
    I have a requirement to change existing records in table control through BDC. Is there any way I can choose the respective record from Table Control through BDC dynamically.
    Regards
    Akash

    /J4I/015PER, this transaction is used for adding permits to Operation in WEC. It has list of operations in Table Control. Permit can be added for choosing the operation from table control.
    Our custom program is designed to add permits for the operation. So if I have to use the above transaction for adding permits, then first I have to choose the correct operation from the table control and then add permit.

  • Disabling the dropdown LOV for existing records in SQL updateable report

    Hi All -
    I have a SQL updateable report which has 3 columns. One of the column is a named-LOV. This report also provides the functionality of inserting new rows.
    Is there a way to only show the named-LOV dropdown list for only the new records to be inserted i.e. when we click on "Add Row". For existing records, I donot want to show the dropdown.
    Please provide your thoughts.
    Thanks,
    -Seenu

    Thanks Robert -
    I guess I didn't put my question right in my earlier posting.
    Basically this report provides updates and inserts both (Its a SQL Updateable report)
    One of the column is a Named-LOV (select list dropdown). For the existing records shown in this report, this select list should be disabled. But for the new records while inserting a new row into this report, the select list dropdown should be shown to the user with an option to choose values from selectlist.
    Thanks,
    -Seenu

  • Patch installer not overwriting the existing one

    Patch installer not overwriting the existing one
    Hi, for one my LabVIEW application, I have created two installers
    Including all the required additional installers (Installer)
    With no additional installer (patch installer)
    So that, for further versions they can use only patch installer.
    When I try to installer both the installer of same version which created two icons in “Control Panel\Programs\Programs and Features” as shown below.
    When I am installing the second installer (patch), I expected that it will either overwrite the existing or it will not allow me to install. But both didn’t happen.
    Please share your thoughts on the above.
    Thanks in advance
    Phani
    Solved!
    Go to Solution.

    Thank you..
    I got another doubt on the same.
    "Upgrade Code" should be same
    1.)For both installers (normal and patch)?
    2.)For all the versions?
    which one is correct in the above two?

Maybe you are looking for

  • HT2534 How Can I Use Itunes Without A Credit Card?

    This problem is really starting to annoy me. At first, I tried to make my Apple ID in Itunes, I wasn't able to make it though because I did not have a credit card. I had a look at the support and found out that there should be a 'None' option next to

  • Problem using template in database configuration assistant Oracle 10g

    Hi, I created a database using the database configuration assistant for Oracle 10g on a Windows Server 2003 box. The database I created worked perfectly, and I had saved it as a template so I could save some time when creating similar databases (whic

  • Question about dataset in demo photo Gallery V.2

    So I'm going to try and be as specific as possible. I'm trying to use the code on the Spry demo page to create a gallery and I'm stuck on how to get it to load my .xml files instead of the china, egypt, and paris files. The only reference I see to a

  • Mail from Workflow to external system with mail text in body of mail

    Hi All, I have extended workflow WS12300111 to send mail to external system. But in external system mail text is coming in attachment & without formating (Multiple lines are coming in single Row). I want to know how to send text in body of mail (inst

  • Executing a native process and getting the text output

    Hi, I have the following problem. When I execute a native DOS process (lets say a batch file), and expect some text output from this process I use the following code: String command = "test.bat"; Process process = runtime.exec(command); BufferedReade