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

Copying a COMPLETE database table into another

Former Member
0 Likes
8,637

QUESTION : How can I copy a existing table (including some records) into another table . The copy function on Application tool bar of ABAP dictionary copies the table structure into a new table having a user given name OK .No problems till here. Now how can i copy the contents of 1st table to 2nd table ?????

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,798

1. Created a small program for that. Read the data from 1st table into a internal table and then update the second database table my the internal table.

2. Second option is Download the first Internal table and then through the program upload the downloaded data into another table.

To download a database table contents as follows:

1. Reach to the table contents acreen in se11.

2. Menu bar -> system -> list -> save -> Local file.

11 REPLIES 11
Read only

Former Member
0 Likes
4,799

1. Created a small program for that. Read the data from 1st table into a internal table and then update the second database table my the internal table.

2. Second option is Download the first Internal table and then through the program upload the downloaded data into another table.

To download a database table contents as follows:

1. Reach to the table contents acreen in se11.

2. Menu bar -> system -> list -> save -> Local file.

Read only

0 Likes
4,798

Hi,

It looks a weird way to pull data to somewhere (to the application server or client-side file) and then push it back to the database instead of just simply copying data at the database level:

data(l_conn) = cl_sql_connection=>get_connection( ).

cl_demo_output=>display(
       l_conn->create_statement( )->execute_update(

          'insert into your_dest_tabname select * from your_src_tabname' ) && ' rows processed.'
     ).

l_conn->commit( ).

l_conn->close( ).


It should work for most of databases and platform-dependency should not be an issue (moreover, it's a single task).


Using of internal table is very interesting in case of millions of records and lots of GB table size. Use import/export database utilities instead or insert ... select inside the database.


Regards,

Andrew.

Read only

Former Member
0 Likes
4,798

Hi,

download the Entire Contents to some EXCEL Sheet.

Then create the program where u copy that contents to some internal table and insert that data into ur database table.

*If useful Reward with Points*

Read only

Former Member
0 Likes
4,798

Hi,

To copy the contents of the database table to copied, you have to write a se 38 program. First fetch all the data into an internal table. The internal table is declared like database table. Then modify your copied database table from internal table.

regards,

kamala.

Read only

0 Likes
4,798

Im asking that I have got the data from database table into internal table. NOW how can i move data from my internal table to the database table. Say itab is the int table and dtab is the data base table. Plz write the exact syntax.

Read only

0 Likes
4,798

Hi,

If you want to pass the data from internal table to Database table..use INSERT statement

First Declare the internal table structure as Database Table.

and fill the internal table with data.

and use INSERT statement.

Check this program...

TABLES:MARA.
 
DATA:ITAB LIKE MARA OCCURS 0 WITH HEADER LINE.
 
START-OF-SELECTION.
 
ITAB-MATNR = '123ABCDA'. .
ITAB-MBRSH = 'C'.
ITAB-MTART = 'FERT' .
ITAB-MEINS = 'KG' .
APPEND ITAB.
 
ITAB-MATNR = '123ABCDB'. .
ITAB-MBRSH = 'C'.
ITAB-MTART = 'FERT' .
ITAB-MEINS = 'KG' .
APPEND ITAB.
 
LOOP AT ITAB.
INSERT MARA FROM ITAB.
MODIFY MARA .
ENDLOOP.

Read only

0 Likes
4,798

OK problem solved but the portion

LOOP AT ITAB.

INSERT MARA FROM ITAB.

MODIFY MARA .

ENDLOOP.

should be as

LOOP AT ITAB.

INSERT MARA FROM ITAB.

ENDLOOP.

secondly plz tell me the other way i.e uploading / downloading..

ive downloaded my table records in .txt / .xls format... NOW Where should i click 2 upload it ?

Read only

Former Member
0 Likes
4,798

I wouldn't bother. Your DBAs can do this much more quickly using their database utilities.

Rob

Read only

Former Member
0 Likes
4,798

WAS a ANSWER WHICH FULFIL THE REQUIREMENT BUT IS NOT THE CORRECT WAY.

Read only

Former Member
0 Likes
4,798

kk

Read only

JPT
Participant
0 Likes
4,798

In a 7.50 Release you can write following if the tables are identical:

INSERT znewtab FROM ( SELECT * FROM zoldtab ).