08-02-2008 1:40 PM
Hi Experts,
I have a scenario like this
Itab1
A | B | C
1050 | 10 | 88
1051 | 20 | 99
itab2
A | D
1050 | 1
1050 | 2
1050 | 3
1051 | 4
1051 | 5
now I want to combine these values in itab3
my result should be
A | B | C | D
1050 10 88 1
1050 10 88 2
1050 10 88 3
1051 20 99 4
1051 20 99 5
i did code like this
LOOP AT i_tab1 INTO w_tab1.
CLEAR w_tab3.
w_tab3-A = itab1-A.
w_tab3-B = itab1-B.
w_tab3-C = itab1-C.
APPEND w_tab3 TO i_tab3.
loop at i_tab2 INTO w_tab2 where A = w_tab2-A.
IF sy-tabix EQ 1.
w_tab3-D = w_tab2-D.
MODIFY i_tab3 INDEX sy-tabix FROM w_tab3 TRANSPORTING D.
else.
w_tab3-A = itab1-A.
w_tab3-B = itab1-B.
w_tab3-C = itab1-C.
w_tab3-D = itab2-D.
APPEND w_tab3 TO i_tab3
ENDIF.
CLEAR w_vttp.
CLEAR w_vttk_tknum.
endloop.
ENDLOOP.
ENDIF.
Probelm:
When I am pocessing 2 record of itab1, the value of sy-tabix for in internal table i_tab2 is not resetting, it's picking the old value.
Can you please tell me how i can reset the sy-tabix of inner loop for the second pass of outer loop.
Thnaks
Krishan
Edited by: Krishan Kumar on Aug 2, 2008 2:40 PM
08-02-2008 1:57 PM
You can try it like this:
data:
count type i value 1,
w_line type i.
describe table i_tab1 lines w_line.
do w_line time.
read i_tab1 into w_tab1 index count.
loop at tab2 into w_tab2 where A = itab1-A.
w_tab3-A = itab1-A.
w_tab3-B = itab1-B.
w_tab3-C = itab1-C.
w_tab3-D = itab2-D.
APPEND w_tab3 TO i_tab3
endloop.
count = count + 1.
enddo.
With luck,
Pritam.
08-02-2008 1:57 PM
You can try it like this:
data:
count type i value 1,
w_line type i.
describe table i_tab1 lines w_line.
do w_line time.
read i_tab1 into w_tab1 index count.
loop at tab2 into w_tab2 where A = itab1-A.
w_tab3-A = itab1-A.
w_tab3-B = itab1-B.
w_tab3-C = itab1-C.
w_tab3-D = itab2-D.
APPEND w_tab3 TO i_tab3
endloop.
count = count + 1.
enddo.
With luck,
Pritam.
08-02-2008 2:18 PM
Hi Pritam,
Thanks a lot.
U gave a very-very precise logic.
It's running.
Again thanks.
08-02-2008 2:23 PM
Modified version of your code..
LOOP AT i_tab1 INTO w_tab1.
CLEAR w_tab3.
w_tab3-A = itab1-A.
w_tab3-B = itab1-B.
w_tab3-C = itab1-C.
loop at i_tab2 INTO w_tab2 where A = w_tab1-A.
w_tab3-D = w_tab2-D.
append w_tab3 to i_tab3.
clear w_tab2.
endloop.
if sy-subrc ne 0.
APPEND w_tab3 TO i_tab3.
ENDIF.
clear w_tab1.
ENDLOOP.
No need to use SY-TABIX here...