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

modify database table

Former Member
0 Likes
1,050

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 ..it’s 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 ??

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
949

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.

8 REPLIES 8
Read only

Former Member
0 Likes
949

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.

Read only

Former Member
0 Likes
949

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

Read only

Former Member
0 Likes
949

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

Read only

Former Member
0 Likes
949

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.

Read only

Former Member
0 Likes
949

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

Read only

Former Member
0 Likes
949

modify <database> from <internal table>

or else

update <database> from <internal table> where <condition>

Read only

Former Member
0 Likes
950

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.

Read only

Former Member
0 Likes
949

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