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: 

appending internal tables.

Former Member
0 Kudos

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

sbhutani1
Contributor
0 Kudos

you can use move corresponding statement for this

move-corresponding itab1 to itab2.

ps reward pts if helpful

Regards

Sumit Bhutani

13 REPLIES 13

Former Member
0 Kudos

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.

sbhutani1
Contributor
0 Kudos

you can use move corresponding statement for this

move-corresponding itab1 to itab2.

ps reward pts if helpful

Regards

Sumit Bhutani

laxmanakumar_appana
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

Hi Karthik,

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

Laxman

0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

LOOP AT ITAB1.

MOVE-CORRESPONDING ITAB1 TO ITAB2.

ENDLOOP.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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