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

Copy between 2 dynamic internal tables

Former Member
0 Likes
1,099

Hello experts,

I have 2 dynamic tables (field symbol) that are supposed to contain the same data, however, they have different field names (but same line type)

illustration :

Table 1

-------------

0d_version    0fiscvarnt            0fiscyear            0d_customer            0currency          0d_reven

Table 2

-------------

field1      field2      field3             field4      field5      field6

Need: How to Copy the contents of Table 1 in Table 2?

Thanks in advance

Best regards

Mounaim

2 REPLIES 2
Read only

wol
Active Participant
0 Likes
637

Hello Mounaim,

the solution is as easy as it could be: Move the data: Table2 = Table1.

The Move-Statement ("=") does not matter about type and Fieldnames. It moves the data "raw". This is fast and flexible, but dangerous if you change one of the variables so that it no longer matches "raw".

This is true for ITabs and Structures.

This is an example:

Did I get the problem right?

Best regards

Stefan Wolf

Read only

alex_campbell
Contributor
0 Likes
637

If the line types truely are the same type (each field is the same data type and length) than you can just use the move operation "=". If not, you can use field symbols and the ASSIGN COMPONENT ... OF STRUCTURE statement to refer to fields by their sequential number, instead of their name:

DATA: BEGIN OF la_struct1,
                 0d_version TYPE c LENGTH 2,
                 0fiscvariant TYPE c LENGTH 4,
                 0fiscyear TYPE int4,
            END OF la_struct1.
DATA: BEGIN OF la_struct2,
                 field1 TYPE c LENGTH 10,
                 field2 TYPE c LENGTH 10,
                 field3 TYPE c LENGTH 10,
            END OF la_struct2.
FIELD-SYMBOLS: <l_field1> TYPE any,
                                   <l_field2> TYPE any.

WHILE sy-subrc = 0.
      ASSIGN COMPONENT sy-index OF STRUCTURE la_struct1 TO <l_field1>.
      CHECK sy-subrc = 0.
      ASSIGN COMPONENT sy-index OF STRUCTURE la_struct2 TO <l_field2>.
      CHECK sy-subrc = 0.
      TRY.
           <l_field2> = <l_field1>.
      CATCH cx_sy_move_cast_error.
           " Handle data type mismatch here
      ENDTRY.
ENDWHILE.

Message was edited by: Alex Campbell