2008 Mar 18 7:20 AM
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.
2008 Mar 18 8:11 AM
Imran try this one...
use UPDATE statement instead of Modify.
Regards,
Balaram D
2008 Mar 18 7:24 AM
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
2008 Mar 18 7:27 AM
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
2008 Mar 18 7:41 AM
I am trying to update into a database table not into an internal table. So, please suggest accordingly.
thanks.
2008 Mar 18 8:15 AM
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
2008 Mar 18 8:02 AM
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
2008 Mar 18 8:11 AM
Imran try this one...
use UPDATE statement instead of Modify.
Regards,
Balaram D
2008 Mar 19 3:54 PM
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.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |