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: 

Copying internal table

Former Member
0 Kudos
150

Hi all,

How can i copy a internal table whose fields are of specific data type into another internal table all whose fields are of character data type.

9 REPLIES 9

Former Member
0 Kudos
123

Hi..,

if the character data type fields are of enough length to hold the value in the other internal table .. then it is very easy to copy...

itab2 is the table of fields of character type.

<b>loop at itab1.

itab2-field1 = itab1-field1.

itab2-field2 = itab1-field2.

itab2-field3 = itab1-field3.

itab2-field4 = itab1-field4.

append itab2.

endloop.</b>

reward if it helps u...

sai ramesh

former_member673464
Active Contributor
0 Kudos
123

hi,

You can directly assign them using move keyword if their lengths are same and The line types are convertible, but not compatible. you can also you "write to" keyword to copy an internal table.

regards,

veeresh

Former Member
0 Kudos
123

If Both the tables are of same structure...

itab2 = itab1.

else use move-corresponging to....

Former Member
0 Kudos
123

hi,

Make sure that the lenghts of target fields are same as the lengths of source field.


loop at itab.
move-corresponding fields of itab to itab2.
append itab2.
endloop.

Regards,

Santosh

Former Member
0 Kudos
123

this is also one of the method

ASSIGN SPFLI_WA TO <WA>.

SELECT *

FROM SPFLI

INTO SPFLI_WA.

DATA COUNT.

WHILE SY-SUBRC = 0.

ASSIGN COMPONENT SY-INDEX OF STRUCTURE <WA> TO <COMP>.

IF SY-SUBRC EQ 0.

WRITE <COMP> TO FS1.

CONDENSE FS1 NO-GAPS.

CONCATENATE CHAR FS1 INTO CHAR IN CHARACTER MODE SEPARATED BY

' '.

IF COUNT = 0.

MOVE FS1 TO CHAR.

COUNT = 1.

ENDIF.

ELSE.

EXIT.

ENDIF.

ENDWHILE.

*CONDENSE CHAR NO-GAPS.

APPEND CHAR TO T_CHAR.

CLEAR: CHAR,COUNT.

ENDSELECT.

Former Member
0 Kudos
123

hi prashanth,

If they are exactly the same structure.

itab2[] = itab1[].

or if the structures are diff the,...

Loop at itab1.

move-corresponding itab1 to itab2.

append itab2.

Endloop.

al the best!!

Regards,

Aparna

Former Member
0 Kudos
123

Hi,

You can use move-corresponding fields from itab1 to itab2. This statement copy the data from one internal table to another internal table.

Regards,

Bhaskar

Former Member
0 Kudos
123

You can do the following:

loop at itab1.

itab2-field1 = itab1-field1.

itab2-field2 = itab1-field2.

append itab2.

endloop.

Or:

loop at itab1.

move-corresponding syntax

append itab2.

endloop.

hope this will help

Former Member
0 Kudos
123

looping will effect the performance of your program. Just write one single line like below:

append lines of itab1 to itab2.

Ensure both table are of same structure.