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 data from dynamic internal table to another dynamic internal table

Former Member
0 Likes
2,113

hi! can some one help me how i move data from one dynamic internal table to another dynamic internal table. structures are different. dyn_table1 has only one field and dyn_table2 has 3 fields but both have one field in common. i want to populate that common field in dyn_itab2 from dyn_itab1.

ex:

dyn_itab1 dyn_ itab2

field3 field1 field2 field3 field4

i did assign component 1 of structure <dyn_table0> to <dyn_table>.

got sy-subrc '4'.

hi! can some one help me how i move data from one dynamic internal table to another dynamic internal table. structures are different. dyn_table1 has only one field and dyn_table2 has 3 fields but both have one field in common. i want to populate that common field in dyn_itab2 from dyn_itab1.

ex:

dyn_itab1 dyn_ itab2

field3 field1 field2 field3 field4

i did assign component 1 of structure <dyn_table0> to <dyn_table>.

got sy-subrc '4'.

2 REPLIES 2
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
867

HI,

You need to loop through one table and then populate the other table as follows.

LOOP AT <dyn_table0> ASSIGNING <dyn_table_line>.

READ TABLE <dyn_table1> INDEX sy-tabix ASSIGNING <dyn_table1_line>.

ASSIGN COMPONENT 1 OF STRUCTURE <dyn_table_line> to <fs_1>.

ASSIGN COMPONENT 1 OF STRUCTURE <dyn_table1_line> to <fs_2>.

<fs_1> = <fs_2>.

ENDLOOP.

Regards,

Sesh

Read only

Former Member
0 Likes
867

Hi Priya,

U need to create a line type of second internal table. Check this program. Check the code in bold.

REPORT YDYNAMIC .

data : it_fcat type lvc_t_fcat.

data : new_table type ref to data.

field-symbols : <i_tab> type standard table,

<i_tab1> type standard table,

<i_line> type any,

<i_line1> type any,

<fs> type any,

<fs1> type any.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

I_STRUCTURE_NAME = 'VBAK'

CHANGING

ct_fieldcat = it_fcat

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fcat[]

IMPORTING

EP_TABLE = new_table

EXCEPTIONS

GENERATE_SUBPOOL_DIR_FULL = 1

others = 2

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

assign new_table->* to <i_tab>.

clear new_table.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fcat[]

IMPORTING

EP_TABLE = new_table

EXCEPTIONS

GENERATE_SUBPOOL_DIR_FULL = 1

others = 2

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

assign new_table->* to <i_tab1>.

select * from vbak into table <i_tab>.

<b>data : tdref TYPE REF TO data.

CREATE DATA tdref LIKE LINE OF <i_tab1>.

assign tdref->* to <i_line1>.</b>

<b>loop at <i_tab> assigning <i_line>.

assign component 'VBELN' of structure <i_line> to <fs>.

assign component 'VBELN' of structure <i_line1> to <fs1>.

<fs1> = <fs>.

append <i_line1> to <i_tab1>.

endloop.</b>

-SatyaPriya