Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Reg: Modify,Insert and Update.

Former Member
0 Likes
5,393

Hi Friends,

I want excact Purpose of Modify, Insert and Update . Rewards are helpful.

Regards,

Narasimha Rao.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,233

MODIFY - Will update the table, if the data already exists, if NOT inserts new rows.

UPDATE - Will update the table, errors out if the data is not found.

In case of MODIFY the sy-subrc is always 0 so you would't know whether the data is actually updated or not.

INSERT - Inserting Data in Database Tables

10 REPLIES 10
Read only

Former Member
0 Likes
3,234

MODIFY - Will update the table, if the data already exists, if NOT inserts new rows.

UPDATE - Will update the table, errors out if the data is not found.

In case of MODIFY the sy-subrc is always 0 so you would't know whether the data is actually updated or not.

INSERT - Inserting Data in Database Tables

Read only

Former Member
0 Likes
3,233

ALso check these threads.

Read only

Former Member
0 Likes
3,233

Update Modify Insert stmts we use when we want to do some change / Insertion

(1) to database table from internal table or

(2) from work area to internal table.

( AA ) Update

If the intended record in the internal table is found in databse table means it will just update that record.

syntax to update database table from itab:::::

UPDATE dbtab FROM TABLE itab

Changes to lines made with the UPDATE command only becomefinal after a database commit

Without using internal table we can update database table directly as shown below:::::::::::::::::::::

TABLES SFLIGHT.

UPDATE SFLIGHT SET SEATSOCC = SEATSOCC + 3

WHERE CARRID = 'LH' AND

CONNID = '0400' AND

FLDATE = '19950228'.

( BB ) Modify is used to insert new record if the record doesnt exist in datbase table.system check this on primary key basis.

If the intended record in the internal table is found in databse table means it will just update that record.So here its equal to UPDATE stmt.

For changes to database table we use syntax as below ::::

MODIFY DatabaseTable FROM TABLE itab.

For changes to Internal table we use syntax as below ::::

MODIFY itab FROM wa INDEX idx.

[TRANSPORTING f1 ... fn WHERE cond].

( CC ) Insert stmt is used to insert New records into databse table from internal table or to internal table from work area.

By default, data is only inserted in the current client. However, ifyou use the CLIENT SPECIFIED addition, you can switch off theautomatic client handling.

You cannot insert a table line if the table alreadycontains a record with the same primary key.

Syntax::::::::::

INSERT INTO dbtab CLIENT SPECIFIED VALUES wa.

or

INSERT (dbtabname) CLIENT SPECIFIED FROM TABLE itab.

Example

Adding customer "Robinson" to client 002:

TABLES SCUSTOM.

SCUSTOM-MANDT = '002'.

SCUSTOM-ID = '12400177'.

SCUSTOM-NAME = 'Robinson'.

SCUSTOM-POSTCODE = '69542'.

SCUSTOM-CITY = 'Heidelberg'.

SCUSTOM-CUSTTYPE = 'P'.

SCUSTOM-DISCOUNT = '003'.

SCUSTOM-TELEPHONE = '01234/56789'.

INSERT INTO SCUSTOM CLIENT SPECIFIED VALUES SCUSTOM.

/message/4622903#4622903 [original link is broken]

Please reward points if helpful....

Read only

Former Member
0 Likes
3,233

Hi,

MODIFY for Database Tables

Inserts or changes lines in database tables.

Syntax

MODIFY <dbtab> FROM <wa>.

MODIFY <dbtab> FROM TABLE <itab>.

Works like INSERT for database tables, if there is not yet a line in the table with the same primary key. Works like UPDATE if a line already exists with the same primary key.

MODIFY for any Internal Table

Changes the content of lines in internal tables of any type.

Syntax

MODIFY TABLE <itab> FROM <wa> [TRANSPORTING <f1> <f 2>...]

[ASSIGNING <FS> | REFERENCE INTO <dref>].

Copies the work area <wa> into the line of the internal table with the same table key as <wa>. If you use ASSIGNING or INTO REFERENCE, field symbol <FS> refers to the modified line or the relevant data reference is stored in <dref> after the statement. You can use the TRANSPORTING addition to specify the exact components that you want to change.

MODIFY <itab> FROM <wa> TRANSPORTING <f1> <f 2>... WHERE <logexp>.

Copies the work area <wa> into the line of the internal table for which the logical expression is true. In each comparison of the logical expression, the first operand must be a component of the line structure.

MODIFY for Index Tables

Changes the content of lines in index tables.

Syntax

MODIFY <itab> FROM <wa> [INDEX <idx>] [TRANSPORTING <f1> <f 2>...]

[ASSIGNING <FS> | REFERENCE INTO <dref>].

Copies the work area <wa> into the line of the internal table with the index <idx>. If you omit the INDEX addition, you can only use the statement within a LOOP. In this case, you change the current loop line If you use ASSIGNING or INTO REFERENCE, field symbol <FS> refers to the modified line or the relevant data reference is stored in <dref> after the statement.

MODIFY for Lists

Changes a list line.

Syntax

MODIFY LINE <n> [INDEX <idx>] [OF CURRENT PAGE|OF PAGE <p>]

|CURRENT LINE

LINE FORMAT <option1> <option2>...

FIELD VALUE <f1> [FROM <g1>] <f2> [FROM <g2>]...

FIELD FORMAT <f1> <options1> <f2> <options2>.

Changes either line <n> on the current or specified list (or page), or the last line to be chosen. The exact nature of the change is specified in the additions

MODIFY SCREEN

Changes the SCREEN table.

Syntax

MODIFY SCREEN...

Like changing an internal table. The system table SCREEN contains the names and attributes of all of the fields on the current screen.

UPDATE

Changes entries in database tables.

Syntax

UPDATE <dbtab> SET <si> = <f>

|<si> = <s i> + <f>

|<si> = <s i> - <f> [WHERE <cond>].

The value in the column <si> is set to the value <f>, increases it by <f>, or decreases it by <f> for all lines selected. The WHERE clause specifies the lines that are changed. If you omit the WHERE clause, all lines are changed.

Syntax

UPDATE <dbtab> FROM <wa>.

UPDATE <dbtab> FROM TABLE <itab>.

This deletes the line that has the same primary key as the work area <wa>, or deletes all the lines in the database that have the same primary key as a line in the internal table <itab>. The work area <wa> or the lines of the internal table <itab> must have at least the same length and alignment as the lines of the database table.

INSERT for Database Tables

Inserts entries from database tables.

Syntax

INSERT <dbtab> FROM <wa>.

INSERT <dbtab> FROM TABLE <itab> [ACCEPTING DUPLICATE KEYS].

Inserts one line from the work area <wa> or several lines from the internal table <itab> into the database table <dbtab>. The ACCEPTING DUPLICATE KEYS addition prevents a runtime error from occurring if two entries have the same primary key. Instead, it merely discards the duplicate

INSERT for Field Groups

Defines the structure of field groups for extract datasets.

Syntax

INSERT <f1>... <f n> INTO <fg>.

Includes the fields <fi> in the field group <fg>, thus defining a line structure for an extract dataset.

INSERT for any Internal Table

Inserts lines from internal tables of any type.

Syntax

INSERT <line>|LINES OF <jtab> [FROM <n1>] [TO <n 2>]

INTO TABLE <itab>

[ASSIGNING <FS> | REFERENCE INTO <dref>].

Inserts a line <line> or a set of lines from the internal table <jtab> into the internal table <itab>. If <jtab> is an index table, you can use the FROM and TO additions to restrict the lines inserted. If you use ASSIGNING or INTO REFERENCE, field symbol <FS> refers to the inserted line or the relevant data reference is stored in <dref> after the statement.

INSERT for Index Tables

Inserts entries in index tables.

Syntax

INSERT <line>|LINES OF <jtab> [FROM <n1>] [TO <n 2>]

INTO <itab> [INDEX <idx>]

[ASSIGNING <FS> | REFERENCE INTO <dref>].

Inserts a line <line> or a set of lines from the internal table <jtab> into the internal table <itab>before the line with the index <idx>. If <jtab> is an index table, you can use the FROM and TO additions to restrict the lines inserted. If you omit the INDEX addition, you can only use the statement within a LOOP. A new line containing values is inserted before the current line. If you use ASSIGNING or INTO REFERENCE, field symbol <FS> refers to the inserted line or the relevant data reference is stored in <dref> after the statement.

INSERT for Programs

Inserts ABAP programs into the program library.

Syntax

INSERT REPORT <prog> FROM <itab>.

The lines of the internal table <itab> are added to the program library as the program <prog>.

Regards,

Priya.

Read only

Former Member
0 Likes
3,233

hi,

refer to the thread

With Modify Option, If the current record is already available in the database, it will update the Changes. If it not available it will insert as a new record.

INSERT - Add a new record into the database table.

MODIFY - If record is available it modifies otherwise it wont modify.

UPDATE - If record is available its update the record otherwise it creates a new record.

insert-used to insert the records modify-used for alter the table field names update-used for modify the data

insert:Insert a set of new data’s into database table., update:Chance the existing data field in data base table., modify:If the record is present then you how to Update the data’s otherwise,Insert the new data.,

Regards,

sreelakshmi

Read only

Former Member
0 Likes
3,233

The MODIFY statement inserts one or several lines specified in source in the database table specified in target, or overwrites existing lines.

The MODIFY statement sets a database lock until the next database commit or database rollback; incorrect usage can result in a deadlock kommen kann.

The number of rows that can be inserted into or changed in the tables of a database within a database LUW is restricted database-specifically by the fact that a database system can only manage a limited amount of locks and data in the rollback area.

The statement UPDATE assigns the content of f to the columns col in all the rows defined by the WHERE condition. If the data types are not compatible, conversion is as follows:

During the assignment of a data object, the content - if necessary - is converted according to the conversion rules into the ABAP data type that corresponds to the data type of the column. An error during conversion causes an exception that cannot be handled.

During the assignment of another column, the content - if necessary - is converted in the database system. The option of conversion and the conversion rules depend on the database system concerned. An error during conversion would - in releases prior to 6.10 - cause an exception that cannot be handled. In releases after 6.10, it causes an exception CX_SY_OPEN_SQL_DB that can be handled.

The new row is inserted in the database table if this does not already contain a row with the same primary key or the same unique secondary index. If it does, the row is not inserted and sy-subrc is set to 4.

If a view is specified in target that does not include all columns in the database table, these are set to the type-related initial value or to the null value in the inserted rows. The latter applies only if, for the relevant database column, the attribute initial value is not selected in the ABAP Dictionary.

Notes

Work area wa should always be declared in the ABAP Dictionary with respect to the database table or the view.

If the database table or the view is specified statically, then outside classes you do not have to specify the work area using FROM wa in the variant without INTO if a table work area dbtab is declared for the relevant database table or for the view with statement TABLES. The system then enhances the INSERT statement implicitly with the addition FROM dbtab.

Example

Inserting a new airline company in the database table SCARR.

DATA scarr_wa TYPE scarr.

scarr_wa-carrid = 'FF'.

scarr_wa-carrname = 'Funny Flyers'.

scarr_wa-currcode = 'EUR'.

scarr_wa-url = 'http://www.funnyfly.com'.

INSERT INTO scarr VALUES scarr_wa.

Read only

Former Member
0 Likes
3,233

hi,

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

Hope this helps, Do reward.

Read only

Former Member
0 Likes
3,233

Modify----it modifies the record , if the record is already existed.

Insert----it inserts the record into the internal table/database table.

Update-----it modifies the record ,if the record already exists and if the record does not exist it inserts the record.

Regards,

Vineela.

Read only

Former Member
0 Likes
3,233

hi,

MODIFY - modify will act like insert 7 update.

Will update the table, if the data already exists, else inserts new rows.

INSERT - Inserts new records in Database Tables

UPDATE - Will update the table for existing records only.

Reward points if useful

Chandra

Read only

Former Member
0 Likes
3,233

Hi

INSERT:this is to insert a record into internal table.

syntax:

insert <itab> index <i>.

Whenever you need to create new records in the database table use INSERT. Whenever using INSERT be sure that a duplicate entry having the same values for the primary key fields are not present. Else it may throw a dump.

MODIFY:this is to modify a particular record or records of a internal table.

syntax:

modify <itab> index <i>.

When you use MODIFY it makes a check for the matching key field values. If present it modifies the matching record, else it creates a new record in the database table.

UPDATE:this is to update a particular record or records of an internl table.

When you use UPDATE it makes a check for the matching key field values.if it presents it updates the matching record.