2008 Jul 17 1:05 PM
hi
i have two internal table
itab1 having fields
f1
f2
f3
f4
and second internal table having fields
HERE F1 IS COMMON FIELD BETTWEEN TWO
f1
f5
f6
f7
f8
f9
f10
i want the data of both the internal table into one final table having data
F1
F2
F3
F4
F5
F6
F7
F8
F9
F10
IE COMBINED DATA OR BOTHE IE I AM ADDING THE COLUIMNS OF INTERNAL TABLE 1 AND INTERNAL TABLE 2 TO FINAL OUTPUT TABLE
PLEASE SUGGEST ?
REGARDS
ARORA
2008 Jul 17 1:18 PM
Something like this should work - code is off top of my head and not tested - but the principle should work. It assumes tab1 is a parent of tab2, if not then you'll need to tweak it a bit for your purpose. Reason for Read inside the Loop is to avoid Loop within Loop which causes performance overhead.
sort tab1 by f1.
sort tab2 by f1.
loop at tab1 into wa1.
read table tab2 into wa2
with key f1 = wa1-f1
binary search.
if sy-subrc eq 0.
l_tabix = sy-tabix.
loop at itab2 into wa2 from l_tabix.
if wa2-f1 ne wa1-f1.
exit.
endif.
[move wa2 and wa1 fields into wa3]
append wa3 to itab3.
endloop.
endif.
endloop.
2008 Jul 17 1:11 PM
Hi Arora,
Please check this code...
LOOP at itab1.
read table itab2 with key f1 = itab1-f1.
move: itab1-f1 to itab3-f1,
itab1-f1 to itab3-f1,
itab1-f2 to itab3-f2,
itab1-f3 to itab3-f3,
itab1-f4 to itab3-f4,
itab2-f5 to itab3-f5,
itab2-f6 to itab3-f6,
itab2-f7 to itab3-f7,
itab2-f8 to itab3-f8,
itab2-f9 to itab3-f9,
itab2-f10 to itab3-f10.
append itab3.
endloop.
Best regards,
raam
2008 Jul 17 1:20 PM
hi RAm
i need to know if ther is no primary key then how to move the data?
like the field common in both the internal table is bukrs ie company code
but duplicate values also exists
so if i read internal table using key.....bukrs though it is acually not will this work...
also once this data is into a interanla table2 i want this to be appendied to a third internal table it_Final_Data
so for that i suppose appent itab3 to it_Final_Data will work right?
please answer both the questions
regards
Arora
2008 Jul 17 1:58 PM
Hi Arora,
If there is no primary key then you need to sort the table by BURKS and delete the duplicate entries.
or
You need to take any other field without the duplicate entries.
Best regards,
raam
2008 Jul 18 6:59 AM
hi Ramm
i dont want to delete the duplicate bukrs entries as i want all
so it fi sort and read and loop as u told above so all records will be taken into third internal table right with new columns added? right
regards
Arora
2008 Jul 17 1:18 PM
Something like this should work - code is off top of my head and not tested - but the principle should work. It assumes tab1 is a parent of tab2, if not then you'll need to tweak it a bit for your purpose. Reason for Read inside the Loop is to avoid Loop within Loop which causes performance overhead.
sort tab1 by f1.
sort tab2 by f1.
loop at tab1 into wa1.
read table tab2 into wa2
with key f1 = wa1-f1
binary search.
if sy-subrc eq 0.
l_tabix = sy-tabix.
loop at itab2 into wa2 from l_tabix.
if wa2-f1 ne wa1-f1.
exit.
endif.
[move wa2 and wa1 fields into wa3]
append wa3 to itab3.
endloop.
endif.
endloop.
2008 Jul 18 7:03 AM
Hi,
If ITAB1 and ITAB2 are of same structures , then try this
APPEND LINES OF ITAB2 TO ITAB1.
DELETE ADJACENT DUPLICATES FROM ITAB1.
2008 Jul 18 7:20 AM
Hi Arora,
I think you have to do 2 loops.
Try the following:
Loop at itab1 into wa_tab1.
Loop at itab2 into wa_tab2 where f1 = wa_tab1-f1.
wa_tab3-f1 = wa_tab1-f1.
wa_tab3-f2 = wa_tab1-f2.
wa_tab3-f3 = wa_tab1-f3.
wa_tab3-f4 = wa_tab1-f4
wa_tab3-f5 = wa_tab2-f5.
wa_tab3-f6 = wa_tab2-f6.
wa_tab3-f7 = wa_tab2-f7.
wa_tab3-f8 = wa_tab2-f8.
wa_tab3-f9 = wa_tab2-f9.
wa_tab3-f10 = wa_tab2-f10.
Append wa_tab3 into itab3.
Clear wa_tab3.
Endloop.
Endloop.
2008 Jul 18 8:07 AM
hi RAAM
the situation is like this
her is the internal table with data and rows
IT_APC Table[58x64]
it_dep Table[14x48]
it_Dep_Apc Table[1x108]
now iand combining data of itapc and itdep to it_dep_apc
both have only one common firled bukrs
and as rows and columns as displayed above
now if i do below as suggeted by u
LOOP AT IT_APC INTO WA_APC.
READ TABLE IT_DEP INTO WA_DEP WITH KEY BUKRS = WA_APC-BUKRS
BINARY SEARCH.
then the all the data is not combined i suppose as i need to have the final table all the data from both the internal tables....
ie common rows plus extra rows for bukrs
regards
Arora
2009 Apr 07 1:13 AM