Hi Paul,
Paul wrote :
i have 2 tables with 3 fields: 1. Tab1 - f1a, f1b, f1c 2. Tab2 - f2a, f2b, f3b 1 internal table with 3 fields: 1. itab - f1, f2, f3 the condition is: if Tab1-f1a = Tab2-f2a and Tab1-f1b = Tab2-f2b then itab-f1 = Tab1-f1a itab-f2 = Tab1-f1b itab-f3 = Tab1-f1c + Tab2-f2c
Make your select query something like this below :
Select * into corresponding fields of itab from tab1 join tab2 on tab1-f1a = tab2f2a and tab1-f1b = tab2-f1b.
Regards,
Swapna.
First ,you need to take 2 internal table compatible to Tab1 and Tab2 say, itab1 and itab2 respectively then select (field list) from TAB1 into itab1. and select (field list) from TAB2 into itab2. then, loop at itab1. read table itab2 index sy-tabix. if itab1-f1a = itab2-f2a and itab1-f1b = itab2-f2b itab-f1 = Tab1-f1a itab-f2 = Tab1-f1b itab-f3 = Tab1-f1c + Tab2-f2c endif. endloop.
Hi, I think that the two tables are ddic table ,so you can't use loop command on those table.
So create three types .
one for TAb1.
one for tab2.
one for itab.
try this and see if this is useful.
----
types : begin of t_tab1,
if1a type Tab1-f1a,
if1b type Tab1-f1b,
if1c type Tab1-f1c,
end of t_tab1,
begin of t_tab2,
if2a type Tab2-f2a,
if2b type Tab2-f2b,
if2c type Tab2-f2c,
end of t_tab2,
begin of t_tab3,
f1 type Tab1-f1a,
f2 type Tab1-f1b,
f3 type tab1-f1c,
end of t_tab3.
data : i_tab1 type standard table of t_tab1,
i_tab2 type standard table of t_tab2,
i_tab3 type standard table of t_tab3,
wa_tab1 type t_tab1,
wa_tab2 type t_tab2,
wa_tab3 type t_tab3.
start-of-selection.
select f1a
f1b
f1c
from tab1 into table i_tab1.
select f2a
f2b
f2c from Tab2 into table i_tab2.
if not i-tab1 is initial.
loop at i_tab1 into wa_tab1.
select if2a
if2b
if2c
from i_tab2 into wa_tab3 where wa_tab1-f1a = wa_tab3-f1a
and wa_tab1-f1b = wa_tab3-f1b.
if not wa_tab3 is initial.
wa_tab3-f1 = wa_tab1-f1a.
wa_tab3-f2 = wa_tab1-f1b.
wa_ tab3-f3 = wa_tab1-f3a + wa_tab3-f3. " I added the value in wa_tab3-f3 because it actuall contain the valut in f2b field in Tab2.
append wa_tab3 to i_tab3.
clear wa_tab3.
endif.
endloop.
endif.
----
please let me know if it works or not.
Hi, I think that the two tables are ddic table ,so you can't use loop command on those table.
So create three types .
one for TAb1.
one for tab2.
one for itab.
try this and see if this is useful.
----
types : begin of t_tab1,
if1a type Tab1-f1a,
if1b type Tab1-f1b,
if1c type Tab1-f1c,
end of t_tab1,
begin of t_tab2,
if2a type Tab2-f2a,
if2b type Tab2-f2b,
if2c type Tab2-f2c,
end of t_tab2,
begin of t_tab3,
f1 type Tab1-f1a,
f2 type Tab1-f1b,
f3 type tab1-f1c,
end of t_tab3.
data : i_tab1 type standard table of t_tab1,
i_tab2 type standard table of t_tab2,
i_tab3 type standard table of t_tab3,
wa_tab1 type t_tab1,
wa_tab2 type t_tab2,
wa_tab3 type t_tab3.
start-of-selection.
select f1a
f1b
f1c
from tab1 into table i_tab1.
select f2a
f2b
f2c from Tab2 into table i_tab2.
if not i-tab1 is initial.
loop at i_tab1 into wa_tab1.
select if2a
if2b
if2c
from i_tab2 into wa_tab3 where wa_tab1-f1a = wa_tab3-f1a
and wa_tab1-f1b = wa_tab3-f1b.
if not wa_tab3 is initial.
wa_tab3-f1 = wa_tab1-f1a.
wa_tab3-f2 = wa_tab1-f1b.
wa_ tab3-f3 = wa_tab1-f3a + wa_tab3-f3. " I added the value in wa_tab3-f3 because it actuall contain the valut in f2b field in Tab2.
append wa_tab3 to i_tab3.
clear wa_tab3.
endif.
endloop.
endif.
----
please let me know if it works or not.
Select data from the two database tables (tab1 and tab2) into internal tables (itab1 and itab2)
SELECT F1A F1B F1C FROM TAB1 INTO ITAB1.
SELECT F2A F2B F2C FROM TAB2 INTO ITAB2.
LOOP AT ITAB1 INTO WA_TAB1.
READ ITAB2 INTO WA_TAB2 WITH KEY F2A = WA_TAB1-F1A AND F2B = WA_TAB1-F1B.
IF SY-SUBRC EQ 0.
WA_TAB2-F2C = WA_TAB2-F2C + WA_TAB1-F1C.
MOVE: WA_TAB1-F1A TO WA_TAB-F3A,
WA_TAB1-F1B TO WA_TAB-F3B,
WA_TAB2-F2C TO WA_TAB-F3C.
APPEND WA_TAB INTO ITAB.
ENDIF.
ENDLOOP
Add comment