14 Replies Latest reply: May 9, 2007 10:48 AM by Vinutha YV RSS

difference between modify, update and insert stmt

alson dsouza
Currently Being Moderated

Hi experts

             can u plz tell me the difference between MODIFY, UPDATE AND INSERT statements while updating a DBtable.

 

Thanks and Regards

alson

  • Re: difference between modify, update and insert stmt
    Manjunath MS
    Currently Being Moderated

    hi..

     

    insert ... will only insert a new record ...

    update : will only  update the existing record...

    modify : will change the existing record or will add a new record based on the

               condition .

     

     

    Reward Points if it is useful.

     

    Thanks,

    Manjunath MS

  • Re: difference between modify, update and insert stmt
    Priyanka Neelam
    Currently Being Moderated

    Hi Alson,

     

    Insert - inserts the records into the dbtable.

    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/insert_d.htm

     

    Update - updates the existing records.

    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/update.htm

     

    Modify  - modifys the existing records or creates a new record if the primary key does not match.

    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/modify_d.htm

     

    Regards,

    Priyanka.

  • Re: difference between modify, update and insert stmt
    Nilesh Gaikwad
    Currently Being Moderated

    Hi,

    Modify:

    If the value of key fields in the internal table matches with the key fields values in database table,modify will update the existing entry.Otherwise,it will insert new entry.

     

    Update:

    To update db table,it is mandatory that the value of key fields in internal table should match with database table.

     

     

    go through this link...

     

    Re: Update and Modify

     

     

    u will get more information

     

    modify

    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/modify_d.htm

     

    update

    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/update.htm

     

     

    Reward points if useful..

     

    Regards

     

    Nilesh

  • Re: difference between modify, update and insert stmt
    Bharat Kalagara
    Currently Being Moderated

    Hi,

     

    modify:it is to modify an existing record in the DB table if the primary keys matches.if they didn't match it will create a new record

    update:it is to modify an existing record in the DB table if the primary keys matches

    insert:it will create a new record in the DB table.

     

     

    rgds,

    bharat.

  • Re: difference between modify, update and insert stmt
    Anji Reddy Vangala
    Currently Being Moderated

    Hi

    Insert: Inserts a single record

    modify: Modify existing record or if no record is there inserts a fresh record.

    Update: updates the existing record.

     

    To insert or change a single line in a database table, use the following:

     

    MODIFY <target> FROM <wa> .

     

    The contents of the work area <wa> are written to the database table <dbtab>. The work area <wa> must be a data object with at least the same length and alignment as the line structure of the database table. The data is placed in the database table according to the line structure of the table, and regardless of the structure of the work area. It is a good idea to define the work area with reference to the structure of the database table.

     

    If the database table does not already contain a line with the same primary key as specified in the work area, a new line is inserted. If the database table does already contain a line with the same primary key as specified in the work area, the existing line is overwritten. SY-SUBRC is always set to 0.

     

    A shortened form of the above statement is:

     

    MODIFY <dbtab>.

     

    In this case, the contents of the table work area <dbtab> are inserted into the database table with the same name. You must declare this table work area using the TABLES statement. In this case, it is not possible to specify the name of the database table dynamically. Table work areas with the same name as the database table (necessary before Release 4.0) should no longer be used for the sake of clarity.

     

    Reward points if useful

    Regards

    Anji

  • Re: difference between modify, update and insert stmt
    Santosh Kumar Kezkhepatmelathil
    Currently Being Moderated

    hi,

     

    update : changes(updates) the existing record.

    insert : inserts a new reord.

    modify: if the record exists it modifies the record, if it doesnot exists new record will be inserted.

     

    regards,

    santosh.

  • Re: difference between modify, update and insert stmt
    Arun Ramachandran
    Currently Being Moderated

    Hi Alson ,

       MODIFY Command will modify a record if a record with the same key feilds exists else it will insert a new record.

    UPDATE : If will modify a record in the data base , so a basic prerequisit is that a similar record with the same key must exist in the database table.

    INSERT : This will insert a new record in the database , if a record with the same key already exists then an error will occure.

     

    So it is genreally safer to use the MODIFY command.

     

    Regards

    Arun

  • Re: difference between modify, update and insert stmt
    Mrutyunjaya Tripathy
    Currently Being Moderated

    hi

    good

     

    Inserting or Changing Lines

     

    To insert lines into a database table regardless of whether there is already a line in the table with the same primary key, use the following:

     

    MODIFY <target> <lines>.

     

    If the database table contains no line with the same primary key as the line to be inserted, MODIFY works like INSERT, that is, the line is added.

     

    If the database already contains a line with the same primary key as the line to be inserted, MODIFY works like UPDATE, that is, the line is changed.

     

    For performance reasons, you should use MODIFY only if you cannot distinguish between these two options in your ABAP program.

     

    You can add or change one or more lines <lines> in a database table <target>. You can only insert or change lines in an ABAP Dictionary view if it only contains fields from one table, and its maintenance status is defined as Read and change. You may specify the database table <target> either statically or dynamically.

     

    Specifying a Database Table

     

    To specify the database table statically, enter the following for <target>:

     

    MODIFY <dbtab> [CLIENT SPECIFIED] <lines>.

     

    where <dbtab> is the name of a database table defined in the ABAP Dictionary.

     

    To specify the database table dynamically, enter the following for <target>:

     

    MODIFY (<name>) [CLIENT SPECIFIED] <lines>.

     

    where the field <name> contains the name of a database table defined in the ABAP Dictionary.

     

    You can use the CLIENT SPECIFIED addition to disable automatic client handling.

     

    Inserting or Changing Single Lines

     

    To insert or change a single line in a database table, use the following:

     

    MODIFY <target> FROM <wa> .

     

    The contents of the work area <wa> are written to the database table <dbtab>. The work area <wa> must be a data object with at least the same length and alignment as the line structure of the database table. The data is placed in the database table according to the line structure of the table, and regardless of the structure of the work area. It is a good idea to define the work area with reference to the structure of the database table.

     

    If the database table does not already contain a line with the same primary key as specified in the work area, a new line is inserted. If the database table does already contain a line with the same primary key as specified in the work area, the existing line is overwritten. SY-SUBRC is always set to 0.

     

    A shortened form of the above statement is:

     

    MODIFY <dbtab>.

     

    In this case, the contents of the table work area <dbtab> are inserted into the database table with the same name. You must declare this table work area using the TABLES statement. In this case, it is not possible to specify the name of the database table dynamically. Table work areas with the same name as the database table (necessary before Release 4.0) should no longer be used for the sake of clarity.

     

    Inserting or Changing Several Lines

     

    To insert or change several lines in a database table, use the following:

     

    MODIFY <target> FROM TABLE <itab> .

     

    Those lines of the internal table <itab> for which there is not already a line in the database table with the same primary key are inserted into the table. Those lines of the internal table <itab> for which there is already a line in the database table with the same primary key overwrite the existing line in the database table. The same rules apply to the line type of <itab> as to the work area <wa> described above.

     

    SY-SUBRC is always set to 0. SY-DBCNT is set to the number of lines in the internal table.

     

    thanks

    mrutyun^

  • Re: difference between modify, update and insert stmt
    bhargavi dosapati
    Currently Being Moderated

    Hi,

     

    <b>  Modify :</b> This statement creates a new record if  the  mentionedrecord does not exist in the database table ( works same as INSERT ), and it it modifies the record   (By comparing the  key fields of the work area )if the record exists in the database table.

    <b>Works for  INTERNAL TABLES also....</b>

     

    <b>

      Update:</b>  It updates the record in the database table

    by comparing the key fields with the required information. ( it will not work for Internal tables )

        

    <b>Insert:</b> It inserts the new record into the database table at specified location.

     

    reward all helpful answers !!

     

    Regards,

      Bhargavi.

    • Re: difference between modify, update and insert stmt
      Currently Being Moderated

      Hi,

       

      INSERT inserts a new record in a internal table

      UPDATE statement just update the existing record, does not insert if the record does not exist

      while MODIFY statement update as well as insert, means update existing record and if it doesnt exist, inserts new one..

       

      Thanks & Regards

  • Re: difference between modify, update and insert stmt
    madhuri vuggina
    Currently Being Moderated

    hi,

     

     

    insert is where u try to insert a new record....in insert u can make insert to qork as append also....when u try to insert a record u insert it at some index but not at last...where as when append statement is used the record gets append at the last n not in the first.....so insert can be used as append also...by specying the table...n not the index..

     

    modify is used to make changes in the existing records but it cannot update the records tht r persent.

     

    update is usd to make changes in the existing records or if the record is not present then it should be appended......

     

    modify n update r some wht same but modify does not append a new record...

     

    if useful then dont forget to reward with points.

    with regards,

    madhuri.

  • Re: difference between modify, update and insert stmt
    Lakshmanan Narasimhan
    Currently Being Moderated

    Insert : inserts a record to a table.

    Update: this updates that record which are inserted .

    Modify : Thisl changes the existing record or will add a new record based on the

    condition .

  • Re: difference between modify, update and insert stmt
    Suresh Babu Aluri
    Currently Being Moderated

    hi alson,

     

    insert --- used to insert data into a interval table [single or multiple records] at specified index.

     

    update --- to change a existing record of internal table at given index

     

    modify---- [update + insert]

    means when a record exists in a internal table we can change the record

    if record not exists then it creates a new record at given  index.

  • Re: difference between modify, update and insert stmt
    Vinutha YV
    Currently Being Moderated

    hi,

     

    modify : will help in changing the data.

     

    update : will update the new data .

     

    insert : will insert the data .this will insert a new value.no modifications can be done on existing data.

     

     

     

    reward with points if helpful.

Actions