‎2008 Aug 18 2:27 PM
Hi Guys,
I have one internal table, I need to loop the table and READ the same table with in the loop.
My requirement is like this:
In the internal table KUNNR VKORG and VTWEG, if three fields values are same for more then one record, i need to append those records into another internal table.
Could any one help me.
Thanks,
Gourisankar
‎2008 Aug 18 2:32 PM
Hi Sankar,
1) Sort the Internal table by KUNNR,VKORG and VTWEG
2) Loop the table and comparing the current value with previous value, If the values matches then move the record into another internal table.
‎2008 Aug 18 2:35 PM
hi try this.
itab1 = itab2.
Loop at itab1 into ls_itab1.
lv_tabix = sy-tabix.
loop at itab2 into ls_itab2.
if sy-tabix > lv_tabix.
if ls_itab1 eq ls_itab2.
Append ls_itab1 into itab3.
endif.
endif.
endloop.
endloop.
Regards,
Bhupal
‎2008 Aug 18 2:37 PM
Hi,
try this way-
Sort itab1 by kunnr vkorg vtweg.
Loop at itab1 into wa1.
Read table itab1 into wa2 with keys kunnr = wa1-kunnr
vkorg = wa1-vkorg
vtweg = wa1-vtweg.
If sy-subrc = 0.
Append wa2 to itab2.
endif.
Endloop.Regards,
Sujit
‎2008 Aug 18 2:38 PM
Hi Gourisankar,
try to use an additional structure.
tab1 (KUNNR VKORG and VTWEG)
data:
tab2 like standard table tab2,
struc1 like line of tab1,
struc2 like line of tab1.
sort table tab1 ascending by KUNNR VKORG VTWEG.
loop at tab1 into struc1.
at first.
move struc1 to struc2.
continue. "Next data
endat.
if struc1 = struc2.
insert struc2 into table tab2.
else.
move struc1 to struc2.
endif.
endloop.
Something like that.
kind regards Philip
‎2008 Aug 18 2:42 PM
data: l_index1 type sy-tabix,
l_index2 type sy-tabix,
l_wa_kna1 type wa_kan1.
*sort ikna1.*_
clear wa_kna1.
loop at i_kna1 into wa_kna1.
move sy-tabix to l_index1.
if l_index eq 1.
move wa_kna1 to l_wa_kna1.
else.
compare your 3 key fields which should be equal with the current work area with l_wa_kna1.
if satisfied.
move ur rec to new itab.
else.
clear l_wa_kan1.
move wa_kna1 to l_wa_kna1.
endif.
endif.
endloop.
hope this helps.
thanks
kiran
‎2008 Aug 18 2:54 PM
Hi,
Loop at itab1 into wa_tab1.
Read table itab1 into wa_tab2 with key kunnr = wa_tab1-kunnr
vkorg = wa_tab1-vkorg
vtweg = wa_tab1-vtweg
field4 NE wa_tab1-field4 .
If sy-subrc = 0.
Append wa_tab2 to itab2.
endif.
Endloop.Important: Here field4 should be a unique key in ur internal table.
Regards,
Prem