‎2009 Mar 23 6:09 AM
i have 2 internal table. itab and itab1
itab1
material1 material2 qty
aaa 123 1
aaa 456 3
itab2
material1 material2 material3 values
aaa 123 xyz 1a
aaa 123 x1y1 2b
aaa 123 x2z2 1a
bbb 456 abc 4g
ddd 789 pqr 2g
ddd 789 lmn 5g
ddd 789 1bc 7h
i need to compare both the internal tables with material1 and material2, In the 2nd internal table the field material2's records comes three or more times i need to remove those records from the internal tabel and append the correct records into another table.
How to add with out this values into another internal table.
From the above example i need to remove aaa and ddd from the internal and append only bbb from here to itab3.
any one help this?
Mohana
‎2009 Mar 23 7:52 AM
Hi Mohana,
do sumthing like this:
Sort itab_1 with by field1, field2.
Loop at itab_1 into wa_1.
count = count + 1.
" if you want to check some condition with itab_2 use a READ statement & check the same
At end of field1.
" if you want combination of field1 & field2 than use 'AT END OF FIELD2'
If count lt 3.
Append wa1 to itab3.
Clear count.
Endif.
Endat.
Endloop.With luck,
Pritam.
Edited by: Pritam Ghosh on Mar 23, 2009 8:57 AM
‎2009 Mar 23 6:16 AM
hi,
use
DELETE ADJACENT DUPLICATE
on both the internal table..
this remove al the duplicate records from both the internal table after that you append left value
in the third internal table...
hope this help you
Regards
Ritesh J
‎2009 Mar 23 6:18 AM
Hi Mohana,
Loop through ITAB2 with WHERE Condition and move the value to other internal table.. or
u can check and delete from ITAB2 without deleting.
to move to other.
loop at itab2 where fld1 = 'value ' and fld2 = 'value '.
itab3 = itab2.
append itab3.
clear itab3.
endloop.
to delete it from itab2.
loop at itab2.
if fld1 ne 'value' and fld2 ne 'value'.
delete itabe2.
endif.
endloop.
Hope this helps u.
Guru
‎2009 Mar 23 6:20 AM
Hi friend,
Use like below in itab2.
DELETE ADJACENT DUPLICATES FROM itab2 comparing material1 material2.
Thanks..
‎2009 Mar 23 6:25 AM
loop at itab1 into wa_itab1.
read table itab2 into wa_itab2
where wa_itab2-mat1 = wa_itab1-mat1 and wa_itab2-mat2 = wa_itab1-mat2.
IF SY-SUBRC NE 0.
MOVE-CORRESPONDING wa_itab2 to wa_itab3.
APPEND WA_ITAB3 TO ITAB3.
ENDIF.
endloop .
HOPETHIS WILL HELP U.
‎2009 Mar 23 7:12 AM
i have one internal table itab with below records.
fld1 fld2 fld3
zzz 784 231
zzz 784 597
AAA 111 BBB
AAA 111 CCC
AAA 111 DDD
BBB 222 xyz
BBB 222 pqr
BBB 222 123
BBB 222 478
BBB 222 zqr
ggg 123 879
CCC 777 kkk
CCC 777 qwi
CCC 777 dsf
CCC 777 qwe
my requirement is i need to check the field fld1 and fld2, if the values comes more than 3times i need to remove the records, i want to append the correct records into another internal table.
the above case i need to append 'ggg' and 'zzz' rows only.
Anyone pls suggest the logic.
‎2009 Mar 23 7:22 AM
Just in your words tell what is the final o/p you are expecting from your internal table ..
give the output for the below..
fld1 fld2 fld3
zzz 784 231
zzz 784 597
AAA 111 BBB
AAA 111 CCC
AAA 111 DDD
BBB 222 xyz
BBB 222 pqr
BBB 222 123
BBB 222 478
BBB 222 zqr
ggg 123 879
CCC 777 kkk
CCC 777 qwi
CCC 777 dsf
CCC 777 qwe
is it the occurance of fld1 & fld2 thrice or fld1 3 times sinlge is enough to discard the entry ?
AAA 111 BBB
AAA 121 CCC " check hte change
AAA 111 DDD
AAA 111 BBB
ABA 111 CCC
AAA 111 DDD
in both the cases can we discard the entry ..
Br,
Vijay..
‎2009 Mar 23 7:27 AM
Hi,
My final output table will be like below
zzz 784 231
zzz 784 597
ggg 123 879
pls help this out.
Mohana
‎2009 Mar 23 7:27 AM
Apply this logic.
sort itab by 3 fields.
Loop at internal table.
var1 = field1.
count = count +1.
At new field 1
if count >3.
clear var1.
else.
move var1 to second internal table.
endif.
endloop.
Thanks & Regards.
Ruchi Tiwari
‎2009 Mar 23 7:39 AM
execute the code ..
REPORT ZEX14.
data : begin of itab occurs 0 ,
f1(4) type c,
f2(4) type c,
f3(4) type c,
end of itab.
DATA : GV_FLAG, GV_CNT TYPE I, GV_VAL(4) TYPE C.
ITAB-F1 = 'ZZZ'. ITAB-F2 = '784'. ITAB-F3 = '231'. APPEND ITAB.CLEAR ITAB.
ITAB-F1 = 'ZZZ'. ITAB-F2 = '784'. ITAB-F3 = '597'. APPEND ITAB.CLEAR ITAB.
ITAB-F1 = 'AAA'. ITAB-F2 = '111'. ITAB-F3 = 'BBB'. APPEND ITAB.CLEAR ITAB.
ITAB-F1 = 'AAA'. ITAB-F2 = '111'. ITAB-F3 = 'BBB'. APPEND ITAB.CLEAR ITAB.
ITAB-F1 = 'AAA'. ITAB-F2 = '111'. ITAB-F3 = 'BBB'. APPEND ITAB.CLEAR ITAB.
SORT ITAB BY F1 F2.
LOOP AT ITAB.
AT NEW F1.
GV_FLAG = 'X'.
ENDAT.
IF GV_FLAG = 'X'.
GV_CNT = GV_CNT + 1.
ENDIF.
AT END OF F1.
IF GV_CNT GE 3.
DELETE ITAB WHERE F1 = ITAB-F1.
ENDIF.
CLEAR : GV_FLAG, GV_CNT.
ENDAT.
ENDLOOP.
LOOP AT ITAB.
WRITE:/ ITAB-F1, ITAB-F2, ITAB-F3.
ENDLOOP.
you can enhace the logic on fld2 just like f1 in the above.
br,
vijay.
‎2009 Mar 23 7:41 AM
Hi,
Use like this.
loop at it.
if prev_fld1 = it-fld1 and prev_fld2 = it-fld2.
count = count + 1.
if count GE 3.
delete it where fld1 = prev_fld1 and fld2 = prev_fld2 .
endif.
endif.
prev_fld1 = it-fld1.
prev_fld2 = it-fld2.
endloop.
‎2009 Mar 23 7:52 AM
Hi Mohana,
do sumthing like this:
Sort itab_1 with by field1, field2.
Loop at itab_1 into wa_1.
count = count + 1.
" if you want to check some condition with itab_2 use a READ statement & check the same
At end of field1.
" if you want combination of field1 & field2 than use 'AT END OF FIELD2'
If count lt 3.
Append wa1 to itab3.
Clear count.
Endif.
Endat.
Endloop.With luck,
Pritam.
Edited by: Pritam Ghosh on Mar 23, 2009 8:57 AM