2007 Jun 14 6:10 PM
Hi,
I have to compare records within an ITAB.
eg
ITAB
Field1 Field2 Field3 Field4
Abc 06 Xyz 100
Def 05 Xyz 25
I have to compare the records withing this ITAB
If field1 & 3 are same in two records and field2 is different in the same two records, then I have to subract the fourth fields ..
Please let me know how can I code this? I'm confused..
Thanks..
Uma.
Message was edited by:
Uma
2007 Jun 14 6:39 PM
hi try this out:
1. Declare one more internal table itab2 and populate it with all the records that r present in itab1.
2. LOOP AT itab1 INTO wa1.
LOOP AT itab2 INTO wa2.
if wa1-field1 = wa2-field1 and
wa1-field3 = wa2-field3 and
wa1-field2 ne wa2-field2.
-
then do ur calculation here----
ENDLOOP.
ENDLOOP.
Please reward pts if useful!!
Hi,
I have to compare records within an ITAB.
eg
ITAB
Field1 Field2 Field3 Field4
Abc 06 Xyz 100
Def 05 Xyz 25
I have to compare the records withing this ITAB
If field1 & 3 are same in two records and field2 is different in the same two records, then I have to subract the fourth fields ..
Please let me know how can I code this? I'm confused..
Thanks..
Uma.
Message was edited by:
Uma
2007 Jun 14 6:22 PM
loop at itab.
if itab-field1 = itab-field3.
if itab-fld1 ne itab-fld2 and itab-fld3 ne itab-fld2.
use your subtract condition.
endif.
endif.
endloop.
2007 Jun 14 6:28 PM
I think you have to make a copy of ITAB then loop through itab and read itab1 where itab1-field3 = itab-field1.
Rob
2007 Jun 14 6:39 PM
hi try this out:
1. Declare one more internal table itab2 and populate it with all the records that r present in itab1.
2. LOOP AT itab1 INTO wa1.
LOOP AT itab2 INTO wa2.
if wa1-field1 = wa2-field1 and
wa1-field3 = wa2-field3 and
wa1-field2 ne wa2-field2.
-
then do ur calculation here----
ENDLOOP.
ENDLOOP.
Please reward pts if useful!!
2007 Jul 23 10:14 AM
hi
try following code !!!
data : begin of sample occurs 0,
f1(2),
f2(2),
f3(2),
f4(2),
end of sample,
wa_sample like sample,
final_sample like sample occurs 0.
sample-f1 = 'a'.
sample-f2 = 'b'.
sample-f3 = '1'.
sample-f4 = '12'.
append sample.
sample-f1 = 'a'.
sample-f2 = 'b'.
sample-f3 = '1'.
sample-f4 = '13'.
append sample.
sample-f1 = 'a'.
sample-f2 = 'c'.
sample-f3 = '1'.
sample-f4 = '14'.
append sample.
read table sample index 1 into wa_sample.
loop at sample.
read table sample comparing f1 f3.
if sy-subrc EQ 0.
if sample-f2 NE wa_sample-f2.
<<< subtraction coding>>>
append sample to final_sample.
endif.
endif.
endloop.
rewars points if u find it correct as per ur requirements
Nilesh