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 internal table

Former Member
0 Kudos
588

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
Read only

Former Member
0 Kudos
561

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

Read only

former_member673464
Active Contributor
0 Kudos
561

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

Read only

Former Member
0 Kudos
561

If Both the tables are of same structure...

itab2 = itab1.

else use move-corresponging to....

Read only

Former Member
0 Kudos
561

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

Read only

Former Member
0 Kudos
561

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.

Read only

Former Member
0 Kudos
561

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

Read only

Former Member
0 Kudos
561

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

Read only

Former Member
0 Kudos
561

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

Read only

Former Member
0 Kudos
561

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.