06-29-2006 10:05 AM
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
06-29-2006 10:08 AM
you can use move corresponding statement for this
move-corresponding itab1 to itab2.
ps reward pts if helpful
Regards
Sumit Bhutani
06-29-2006 10:08 AM
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.
06-29-2006 10:08 AM
you can use move corresponding statement for this
move-corresponding itab1 to itab2.
ps reward pts if helpful
Regards
Sumit Bhutani
06-29-2006 10:08 AM
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
06-29-2006 10:10 AM
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
06-29-2006 10:12 AM
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
06-29-2006 10:14 AM
Hi Karthik,
In that case whatever code i mentioned , it will work.
Laxman
06-29-2006 10:15 AM
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.
06-29-2006 10:14 AM
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
06-29-2006 10:15 AM
By MOVE STATMENT.............
LOOP AT ITAB1.
MOVE-CORRESPONDING ITAB1 TO ITAB2.
ENDLOOP.
06-29-2006 10:19 AM
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
06-29-2006 10:20 AM
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
06-29-2006 10:34 AM
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
06-29-2006 10:45 AM
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