‎2008 Apr 10 12:31 PM
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.
‎2008 Apr 10 12:42 PM
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.
‎2008 Apr 12 7:29 AM
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.
‎2008 Apr 14 1:13 PM
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.