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

Adding fields to database table and copying data from other fields

Former Member
0 Likes
514

Hi All,

I am having a database table where in I am having a column 'FIELD1'.

My requirement is that I want to add two more fields in the table 'FIELD2' and 'FIELD3'.

I then want to copy all the data in field1 to field2 and field3. then I want to delete the original field1.

for Ex.

lets say FIELD1 = 100.

now I want to add FIELD2 and FIELD3 in the table and make FIELD2 = 100 AND FIELD3 = 100. The FIELD1 will be deleted from table.

Please suggest the methods to do so.

It is urgent.

3 REPLIES 3
Read only

Former Member
0 Likes
489

Hi Gaurav,

do this way ...


data : begin of it_ztab occurs 0 with header line,
          fld1 like ztab-fld1,
          fld2 like ztab-fld2,
          fld3 like ztab-fld3,
        end of it_ztab. 

data : wa_ztab like it_ztab.

it_ztab-fld1 = '100'.
append it_ztab. 
clear    it_ztab.

loop at it_ztab.
  wa_ztab-fld2 = it_ztab-fld1.
  wa_ztab-fld3 = it_ztab-fld1.
  wa_ztab-fld1 = ' '.
* Make sure that the structure of internal table/ workarea and database table shoud be same
  modify ztab from wa_ztab.
endloop.
 

Read only

Former Member
0 Likes
489

for ex: if your table name is ZTABLE

data:

it_tab type table of ZTABLE with headerline.

select * from ZTABLE

into table it_itab.

loop at it_itab.

it_itab-field2 = it_itab-field1.

it_itab-field3 = it_itab-field1.

clear it_itab-field1.

modify it_itab.

endloop.

modify ZTABLE from table IT_ITAB.

Read only

Former Member
0 Likes
489

You can add fields into table using Append structure or you can use include to add the structure or fields to current table.

Than write a loop to table and copy the value of the field1 to field2 and field3 and make field1 is initial than update the database table ( its compulsory otherwise this changes wont get reflected to Database.)

Now you have to go to SE11 and select change after writing the table name and need to remove the field from the Database table.