‎2006 Nov 21 11:32 AM
Can anyone tell me How to modify the Database table using the internal table? I have to change only one field value of a particular row and column ?????
I have to use only Modify command . I have done it with update ..its working but with modify it is changing the entire line of the database table which I m modifying .. as
I m passing only the primary keys and the fields to be edited . What should I do now ??
‎2006 Nov 21 11:53 AM
Hi nilesh,
1. I have to change only one field value of a particular row and column ?????
a) First SELECT the data from DBTABLE for the corresponding record in
DTAB eg.
b) then change the value of the field in that DTAB.
c) then using loop
LOOP AT DTAB.
MODIFY ZTABLE FROM DTAB.
ENDLOOP.
d) DTAB should have same structure as that of ZTABLE.
regards,
amit m.
‎2006 Nov 21 11:36 AM
Hi Nilesh,
Modify Command basically overwrites the value of existing fields with the new fields. Now since you are passing only the primary key & the fields to be edited, the statement considers all other fields as blank & so the database table also gets modified.
If u still need to use modify statement, first select the data from the database table into the internal table. Then modify the fields in the internal table & then modify the database table from the internal table.
Regards,
Chetan.
PS:Reward points if this is helpful.
‎2006 Nov 21 11:37 AM
if you have to modify a few fields then..
1. try to look for some stadard SAP ransaction.
because SAP do not recommend direct modifications
2. if there is no transaction or function module then read the table with primary keys it will fetch all the old values now first modify iternal table then use MODIFY table command to update database.
hope this helps
‎2006 Nov 21 11:37 AM
Declare internal table same as ur database table
then use
Modift ztable from table itab.
but ur modify statement will append a record if doesnt exist in database table , so safe to use UPDATE
‎2006 Nov 21 11:39 AM
Hi Nilesh,
First select the original data from the database table, make changes in required fields in the internal table & then modify.
When u say modify, it overwrites all the non key fields in the database table.
‎2006 Nov 21 11:39 AM
Hi
use the following logic
Select from (dbtable)
into (itab of same type as dbtable)
loop at itab into wa_itab.
change the values required
modify itab from wa_itab.
endloop.
modify (dbtable) from table itab.
This should solve your problem
‎2006 Nov 21 11:41 AM
modify <database> from <internal table>
or else
update <database> from <internal table> where <condition>
‎2006 Nov 21 11:53 AM
Hi nilesh,
1. I have to change only one field value of a particular row and column ?????
a) First SELECT the data from DBTABLE for the corresponding record in
DTAB eg.
b) then change the value of the field in that DTAB.
c) then using loop
LOOP AT DTAB.
MODIFY ZTABLE FROM DTAB.
ENDLOOP.
d) DTAB should have same structure as that of ZTABLE.
regards,
amit m.
‎2006 Nov 21 12:08 PM
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 IINSERT - 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.
You cannot change the value of a key field. Select to internal table, update data in internal table .
-Regards
charitha