‎2006 Dec 21 1:20 AM
Hi
Iam having two internal tables
data: begin of itab,
matnr like mara-matnr,
maktx like makt-maktx,
charg like mch1-charg,
end of itab.
data: itab1 like itab occurs 0 with header line,
itab2 like itab occurs 0 with header line,
data:begin of jtab,
matnr like mara-matnr,
charg like makt-charg,
end of jtab.
data: itab3 like jtab occurs 0 with header line,
itab4 like jtab occurs 0 with header line.
<b>[ both itab1 and itab3 contains records.they can be different or same records. now i have compare both the tables with matnr and charg.For one matnr number we can have multiple charg numbers.
1.when compared if the record is found in itab1 and not in itab3 then we have to pull out that record into itab2.
2.if the record is not found in itab1 and found in itab3 then we have to pull that record into itab4
3. if they are same nothing to be done.]</b>
CAN ANY ONE POST WITH EXAMPLE.
‎2006 Dec 21 1:30 AM
First loop at itab1 and read against itab3. Then reverse it.
Loop at itab1.
read table itab3 with key matnr = itab1-matnr
charg = itab1-charg.
if sy-subrc <> 0.
append itab1 to itab2.
endif.
endloop.
Loop at itab3.
read table itab1 with key matnr = itab3-matnr
charg = itab3-charg.
if sy-subrc <> 0.
append itab3 to itab4.
endif.
endloop.Regards,
RIch Heilman
‎2006 Dec 21 2:36 AM
Is there any function module which can compare two internal tables
‎2006 Dec 21 3:00 AM
I don't think there are any function modules that can compare two tables.
Regards,
Ravi
Note - Please mark all the helpful answers
‎2011 Jan 18 10:49 AM
Hello
CTVB_COMPARE_TABLES --- function module to compare tables
Here u should give 2 internal tables as input and 3 as output
Inputs: comparing tables
Output: modifications/changes, Additions and error tables
‎2006 Dec 21 3:44 AM
Hi satya,
sort : itab1 by matnr charg,
itab3 by matnr charg.
Loop at itab1.
read table itab3 with key matnr = itab1-matnr
charg = itab1-charg bynary search.
if sy-subrc <> 0.
append itab1 to itab2.
clear itab2.
endif.
endloop.
Loop at itab3.
read table itab1 with key matnr = itab3-matnr
charg = itab3-charg bynary search.
if sy-subrc <> 0.
append itab3 to itab4.
clear itab4.
endif.
endloop.
Pls. reward points for useful answers.
‎2006 Dec 21 4:02 AM
you can try like this.
loop at itab1.
read table itab3 with key matnr = itab1-matnr charg = itab1-charg.
if sy-subrc ne 0.
move-corresponding itab1 to itab2.
append itab2.
else.
delete itab3 index sy-tabix.
endif.
endloop.
<now your itab3 contains which are not common in itab1>
append lines of itab3 to itab4.
regards
shiba dutta
‎2006 Dec 21 6:14 PM