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

appending internal tables.

Former Member
0 Likes
2,281

Hello All,

Can any of you let me know

How can we append one internal contents to other when their structure do not match??

Is it possible? Or is there an other approach for this??

Thanks

Karthik Krishna

1 ACCEPTED SOLUTION
Read only

sbhutani1
Contributor
0 Likes
1,808

you can use move corresponding statement for this

move-corresponding itab1 to itab2.

ps reward pts if helpful

Regards

Sumit Bhutani

Hello All,

Can any of you let me know

How can we append one internal contents to other when their structure do not match??

Is it possible? Or is there an other approach for this??

Thanks

Karthik Krishna

13 REPLIES 13
Read only

Former Member
0 Likes
1,808

Hello Karthik.

No you can't append contents if the structures don't match. You will have to loop over the first table and use the MOVE-CORRESPONDING statement for the fields that do match, and your own logic for the remaining fields.

Regards,

John.

Read only

sbhutani1
Contributor
0 Likes
1,809

you can use move corresponding statement for this

move-corresponding itab1 to itab2.

ps reward pts if helpful

Regards

Sumit Bhutani

Read only

Laxmana_Appana_
Active Contributor
0 Likes
1,808

Hi,

Do like this.check the lengths of a and c fields before moving the data.

Loop at i_tab1.

move itab1-a to itab2-c.

.....

append i_tab2.

endloop.

Laxman

Read only

Former Member
0 Likes
1,808

I am guessing there are some common fields between the two internal tables.

LOOP AT ITAB1.

MOVE-CORRESPONDING ITAB1 TO ITAB2.

APPEND ITAB2

ENDLOOP.

Regards,

Ravi

Note : Please mark the helpful answers

Read only

Former Member
0 Likes
1,808

Hello John & Sumit,

Move corresponding works only if the two internal table+

have something in common. Here i am talking about

two internal tables that do not have anything in common.

Rgds,

Karthik

Read only

0 Likes
1,808

Hi Karthik,

In that case whatever code i mentioned , it will work.

Laxman

Read only

0 Likes
1,808

Hello Karthik,

Then you will have to the coding completely yourself:

Loop at table1 assigning <zlf_table1>.

zls_table2_wa-field1 = ....

zls_table2_wa-field2 = ....

zls_table2_wa-field3 = ....

append zls_table2

to table2.

endloop.

Regards John.

Read only

Former Member
0 Likes
1,808

hi,

you can use MOVE-CORRRESPNDING ITAB1 TO ITAB2.

OR

you can assign values of one internal table to another, component by component. i.e

LOOP at itab into wa_itab.

wa_itab2-field1 = wa_itab-field1.

wa_itab2-field2 = wa_itab-field2.

wa_itab2-field3 = wa_itab-field3.

append wa_itab2 to itab2.

endloop.

you can also make use of FIELD-SYMBOLS.

Regards

Anurag

Read only

Former Member
0 Likes
1,808

By MOVE STATMENT.............

LOOP AT ITAB1.

MOVE-CORRESPONDING ITAB1 TO ITAB2.

ENDLOOP.

Read only

Former Member
0 Likes
1,808

Hi Karthik,

U can do that by Taking second internal table itab2 which has all char type fields, or else atleast their datatype should match with first table itab1.

ex:

data:begin of itab1 occurs 0,

matnr like mara-matnr,

mtart like mara-mtart,

end of itab1.

data:begin of itab2 occurs 0,

matnr(18)TYPE C ,

mtart(40)TUYPE C,

end of itab1.

loop at itab1.

itab2-MATNR= itab1-MATNR.

itab2-MTART= itab1-MTART.

endloop.

REGARDS,

Kiran B

Read only

Former Member
0 Likes
1,808

Hi Karthik,

there are two ways, it depends on your structures:

PROGRAM ZGRO_TEST MESSAGE-ID ZZ LINE-COUNT 70.

*

TABLES: MARA.

*

DATA: BEGIN OF ITAB1 OCCURS 0,

MATNR LIKE MARA-MATNR,

GROES LIKE MARA-GROES,

WRKST LIKE MARA-WRKST,

END OF ITAB1.

*

DATA: BEGIN OF ITAB2 OCCURS 0,

GROES LIKE MARA-GROES,

WRKST LIKE MARA-WRKST,

END OF ITAB2.

*

SELECT * FROM MARA WHERE MATNR

BETWEEN '000000000000016184' AND '000000000000016186'.

*

ITAB1-MATNR = MARA-MATNR.

ITAB1-GROES = MARA-GROES.

ITAB1-WRKST = MARA-WRKST.

*

APPEND ITAB1.

*

ENDSELECT.

*

LOOP AT ITAB1.

MOVE-CORRESPONDING ITAB1 TO ITAB2. "First

  • ITAB2 = ITAB1. "second

APPEND ITAB2.

ENDLOOP.

*

try both ways and look in itab2 where the differenc is.

Regards, Dieter

Read only

Former Member
0 Likes
1,808

Thanks for your support!

These two internal tables

are dynamically generated in my code. I am trying to merge this two dynamically generated internal table

I will get back after i accomplish that!!

Rgds

CK

Read only

Former Member
0 Likes
1,808

hi,

i think if the two tables don't have the commod field,don't move.

maybe you can do like below:

loop at itab1.

itab2-field1 = itab1-field1.

itab2-field2 = itab1-field2.

append itab2.

endloop.

if you have many fields,it's a hard work.

Message was edited by: Romeo Long