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

working of modify statement

Former Member
0 Likes
1,434

Hye folks,

There is a scenario where there 4 fields in a data base.

Table Fields.

Serial Number PK

Article number

Article name

Price.

i have inserted the entry as 12... 123... xyz... 100...

13... 101... abc... 120...

now i wish to change the price of serial number 13 to 150 and also insert a new entry to table, i am getting the new entry created with modify and also a new entry for already existing row 13 with a changed price. there is a primary key violation.

internal table rows: 13... ... ... 150

modify dbtab from itab.

As per the definiton of modify it should update the existing row with a price of 150 but it is not happening, instead a new row is created.

As per the definiton of Primary key (PK), it shuld not allow duplicate.

How does a modify statement work in this scenario, why is ti giving a new entry.

Please help me in understanding the same.

thanks in advance.

Imran.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,179

Imran try this one...

use UPDATE statement instead of Modify.

Regards,

Balaram D

Hye folks,

There is a scenario where there 4 fields in a data base.

Table Fields.

Serial Number PK

Article number

Article name

Price.

i have inserted the entry as 12... 123... xyz... 100...

13... 101... abc... 120...

now i wish to change the price of serial number 13 to 150 and also insert a new entry to table, i am getting the new entry created with modify and also a new entry for already existing row 13 with a changed price. there is a primary key violation.

internal table rows: 13... ... ... 150

modify dbtab from itab.

As per the definiton of modify it should update the existing row with a price of 150 but it is not happening, instead a new row is created.

As per the definiton of Primary key (PK), it shuld not allow duplicate.

How does a modify statement work in this scenario, why is ti giving a new entry.

Please help me in understanding the same.

thanks in advance.

Imran.

7 REPLIES 7
Read only

Former Member
0 Likes
1,179

here you need to use a condition WHERE for primary key field.

By using the condition a particular field will be replaced.

Thanks,

Balaram

Edited by: Balaram Devineni on Mar 18, 2008 8:25 AM

Read only

Former Member
0 Likes
1,179

Hi,

To Modify an entry:

Loop at itab into wa_tab where serial_no = '13'.

wa_itab-price = '150'.

modify itab from wa_itab transporting price.

endloop.

To add new entry, you have to append the values from the internal table to the table where you want to create new entries.

<REMOVED BY MODERATOR>

Thanks,

Parul.

Edited by: Alvaro Tejada Galindo on Mar 19, 2008 4:19 PM

Read only

Former Member
0 Likes
1,179

I am trying to update into a database table not into an internal table. So, please suggest accordingly.

thanks.

Read only

0 Likes
1,179

Hi,

Try this.

Loop at itab into wa_tab where serial_no = '13'.

wa_itab-price = '150'.

modify itab from wa_itab transporting price.

clear wa_itab.

endloop.

update dbtable from table itab where serial_no = '13'

<REMOVED BY MODERATOR>

regards,

Ramya

Edited by: Alvaro Tejada Galindo on Mar 19, 2008 4:19 PM

Read only

Former Member
0 Likes
1,179

suppose Itab is the internal table with the data,

then try it this way

itab-srno = 13.

modify dbtab from itab.

It worked for me.

and does dbtab has only SRNO as the primary key?

Thanks and regards,

Pavithra

Read only

Former Member
0 Likes
1,180

Imran try this one...

use UPDATE statement instead of Modify.

Regards,

Balaram D

Read only

Former Member
0 Likes
1,179

modify .. this checks for the primary key, if a record has same primary key as in the internal it updates other wise a new row is created.