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

INSERT or MoDIFY statement

Former Member
0 Likes
5,406

hi,

I have to insert a data for my ztable,for 1st time it is updating the data,but for the second time (since all the key fields are same as 1st record),it is going to modify the data in my table.(since i have used modify statement),But i want both the records.

any idea?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,347

Hello,

You cann't insert two records with all the key fields same values. atleast one key field value should be different.

Thanks,

6 REPLIES 6
Read only

Former Member
0 Likes
2,348

Hello,

You cann't insert two records with all the key fields same values. atleast one key field value should be different.

Thanks,

Read only

Former Member
0 Likes
2,347

Hi,

insert => New record is set

update => Exits record is changed

modify => If record exitst, it´s updated. If not, new one is created

New records are allowed, if you don``t set key-fields or the key-fields are not the same.

Regards

Nicole

Edited by: Nicole Lorenz on May 29, 2008 7:23 AM

Read only

Former Member
0 Likes
2,347

Hi,

For the next time also you need to use INSERT statement, but you have to add extension INSERT <dbtable> FROM wa ACCEPTING DUPLICATE KEYS.

Rgds,

Bujji

Read only

Former Member
0 Likes
2,347

Hi,

If you want to insert the record to Z table, use the INSERT command. Anyway it is not possible to insert second entry with same key fields.

MODIFY statement will insert the record in table if it is not existing in table. If the record exists in table then it will modify the existing record in table.

Read only

vinod_vemuru2
Active Contributor
0 Likes
2,347

Hi Priya,

U can't insert 2 records with same primary key. But i have small clue for u.

Add one more primary key field to ur Ztable i. e counter. First get the record from Ztable with all primary keys u r trying to insert(For second or subsequent time) Then Get the counter value for that row. Now add 1 to counter and INSERT that record.

u can do this if ur table is not there in production already(New

one)*

Thanks,

Vinod.

Read only

Former Member
0 Likes
2,347

hi

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

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.

http://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]

regards,

Vipul