Application Development 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: 

How do i transfer data from one internal tabe to another.

Former Member
0 Kudos

Hi All,

How do i transfer data from one internal tabe to another.

Can i do it ebven if he tables are different in structure.

Please Advice.

Thanks in advance.

8 REPLIES 8

Former Member
0 Kudos

u can use this code

itab1[] = itab[].

If both itabs have the same line type.

0 Kudos

that was

itab1[ ] = itab2[ ].

Former Member
0 Kudos

Hi,

If two internal tables are same you can use below :

itab2[] = itab1[].

append lines of itab1 to itab2.

Thanks,

Sri,

Former Member
0 Kudos

Hi Saket,

If u want to copy data from itab1 to itab2 then you can use,

itab2[] = itab1[].

If u want to copy only few lines(say from 1 to 3) of itab1 to itab2 then yo can use,

append lines of itab1 from 1 to 3 to itab2.

If both the internal tables are not of the same structure,

say only fields f1 and f2 are common,then ypu have to copy the data in the following way,

loop at itab1.

itab2-f1 = itab1-f1.

itab2-f2 = itab1-f2.

append itab2.

clear itab2.

endloop.

if there are many common fields then...

loop at itab1.

move-corresponding itab1 to itab2.

append itab2.

clear itab2.

endloop.

If the internal tables are not of the same structure, you'll need to loop through itab1 and write the corresponding fields to itab2.

If the internal table contains fields with character types and if the tables are of different structures,then you will have to copy from the first internal table to the sesond internal table using the offset of the first internal table.

itab2-f1 = itab1-f1 + O(index)

Reward points if usefull

Regards

Kashyap Ivaturi

Edited by: Kashyap Ivaturi on Jan 9, 2008 8:33 PM

Edited by: Kashyap Ivaturi on Jan 9, 2008 8:41 PM

Former Member
0 Kudos

Hi Saket,

Using Move statement you can copy the values.

To copy entire contents of one table into another in one execution

Syntax MOVE <itab1> To <itab2>.

OR

<itab1> = <itab2>.

Original data in target table overwritten.

Regards,

Sreekar

Edited by: sreekar nethagani on Jan 9, 2008 9:07 PM

former_member313782
Active Participant
0 Kudos

Hi Saket Tiwari,

I hope the earlier post by kashyap is good enough an answer. anywas in addition to it let me give a detailed

explanation of how you can populate an internal table.

1) Append data line by line.

Syntax : APPEND [<wa> TO / INITIAL LINE TO] <itab>.

this appends new line to internal table <itab>.

2) Using COLLECT statement.

COLLECT is another form of statement used for populating the internal tables. Generally COLLECT is used while inserting lines into an internal table with unique standard key. The syntax for COLLECT statement is as shown

Syntax : COLLECT [<wa> INTO] <itab>.

3) Using INSERT statement

Syntax INSERT [<wa> INTO / INITIAL LINE INTO] <itab> [index <idx>].

INSERT statement adds a line/work area to the internal table. You can specify the position at which the new line is to be added by using the INDEX clause with the INSERT statement.

Now coming to your request..

To append part or all of an internal table

Syntax

APPEND LINES OF <itab1> [FROM <n1>] [TO <n2>] TO <itab2>.

* Note:

Without the FROM and TO options, this statement appends the entire table <itab1> to <itab2>.*

b) To insert part or all of an internal table into another internal table

Syntax

INSERT LINES OF <itab1> [FROM <n1>] [TO <n2>]

INTO <itab2> [INDEX <idx>].

c) Using Move statement.

To copy entire contents of one table into another in one execution

Syntax MOVE <itab1> To <itab2>.

OR

<itab1> = <itab2>.

but u hav to be careful because he contents of itab2 will eb overwritten on the execution of this statement.

These copy the contents of ITAB1 to ITAB2. Incase of internal tables with header line we have to use [] inorder to distinguish from work area. So, to copy contents of internal tables with header line the syntax becomes,

ITAB1[] = ITAB2[].

Coming to the letter part of your question, Yes, we can copy values between tables having different structures.

for this we use

MOVE-CORRESPONDING <itab1> TO <itab2>

this executes the statement for their header lines. Searches for the sub-fields which occur both in itab1 and itab2 and then generates, for all relevant field pairs which correspond to the

sub-fields ni , statements of the form MOVE itab1-ni TO itab2-ni. The other fields remain unchanged.

I hope the information provided has been of your help.

Reward if useful.

Regards,

Jose

Former Member
0 Kudos

Hi,

If table have different structure then copying one internal table into another then it will give 'syntax error as two table are incompatible'.

if two internal table are compatible then internal table is copied in sequence of fields (based on the data type length), it may result into merging multiple columns of first table into single column of second.

but you can copy portion of table.

for example,

Types : begin of ty_data,

                    field1 type char4,

                    field2 type char4,

                    field3 type char3,

          end of ty_data.

data it_data type standard table of ty_Data with header line.

Types : begin of ty_data1,

                    field1 type char4,

                    field2 type char4,

          end of ty_data1.

data it_data1 type standard table of ty_Data1 with header line.

then you can copy first 2 fields of it_data into it_data2.

it_Data1[] = it_data[].

but movement of columns based on data type compatibility and length.

 

regards,

Pritesh.

0 Kudos

This message was moderated.