04-04-2007 1:40 PM
Hi Group,
I have two files,in which one file contains all the records(let us say 10) and second file contains some part of the First file(let us say 5) I need to compare both and needs to remove the common records and the remaining records I need to write in to third file.
First I took the two files in to two separate Itabs ,now how to compare these Internal table for Common records?
Can any body suggest
04-04-2007 1:47 PM
Hi..,
If the two tables are of the same type , i mean the structures should be same...
then go for this..
<b>loop at itab2 into wa_itab2.
delete table itab1 from wa_itab2.
endloop. (** at the end of this loop itab1 contains non common records )
copying the remaining records in itab1 to third table itab3..
itab3[] = itab1[].</b>
regards,
sai ramesh
04-04-2007 1:44 PM
Hi.
Three internal Tables.
itab,itab1,itab2.
Try this code.
In both itab and itab1 the field matnr is common.
and in itab2 the result will store(which not common).
Loop at itab into wa_itab.
Read table itab1 into wa_itab1 with key matnr = itab-matnr.
if sy-subrc NE 0.
append itab1 to itab2.
endif.
Endloop.
Reard all helpful answers.
Regards
Bala.
null
04-04-2007 1:46 PM
Hi,
Here is the sampl eprogram to compare the 2 internal tables
<b>REPORT demo_int_tables_compare.</b>
DATA: BEGIN OF line,
col1 TYPE i,
col2 TYPE i,
END OF line.
DATA: itab LIKE TABLE OF line,
jtab LIKE TABLE OF line.
DO 3 TIMES.
line-col1 = sy-index.
line-col2 = sy-index ** 2.
APPEND line TO itab.
ENDDO.
MOVE itab TO jtab.
line-col1 = 10. line-col2 = 20.
APPEND line TO itab.
IF itab GT jtab.
WRITE / 'ITAB GT JTAB'.
ENDIF.
APPEND line TO jtab.
IF itab EQ jtab.
WRITE / 'ITAB EQ JTAB'.
ENDIF.
line-col1 = 30. line-col2 = 80.
APPEND line TO itab.
IF jtab LE itab.
WRITE / 'JTAB LE ITAB'.
ENDIF.
line-col1 = 50. line-col2 = 60.
APPEND line TO jtab.
IF itab NE jtab.
WRITE / 'ITAB NE JTAB'.
ENDIF.
IF itab LT jtab.
WRITE / 'ITAB LT JTAB'.
ENDIF.
<b>The list output is:
ITAB GT JTAB
ITAB EQ JTAB
JTAB LE ITAB
ITAB NE JTAB
ITAB LT JTAB</b>
Two tables itab and jtabare created. itab is then filled with 3 lines and assigned to jtab. Another line is added to itaband the first logical expression returns the result that itab is bigger than jtab. After appending the same line to jtab, the second logical expression tests whether both tables are equal. Then another line is appended to itab and the third logical expressions tests whether jtab is less than or equal to itab. Next, another line is appended to jtab. Its contents are different to the contents of the last line of itab. The next logical expressions test whether itab is not equal to jtab. The first table field whose contents are different in itab and jtabis col1 in the last line of the table: 30 in itab and 50 in jtab. Therefore, in the last logical expression, itab is less than jtab.
Regards
Sudheer
04-04-2007 1:47 PM
Hi..,
If the two tables are of the same type , i mean the structures should be same...
then go for this..
<b>loop at itab2 into wa_itab2.
delete table itab1 from wa_itab2.
endloop. (** at the end of this loop itab1 contains non common records )
copying the remaining records in itab1 to third table itab3..
itab3[] = itab1[].</b>
regards,
sai ramesh
04-04-2007 1:48 PM
Sort the smaller itab using the comparison key.
Loop at the larger itab.
read smaller itab using the camparison key and using binary search.
subrc = 0?
delete the record from the larger itab.
endloop.
Write the contents of the larger itab to the third file.
04-04-2007 1:48 PM
Hi,
try this
CHECK ITAB1[] NE ITAB2[].
LOOP AT ITAB1.
LOOP AT ITAB2.
LV_TABIX = SY-TABIX.
IF ITAB1 = ITAB2.
DELETE ITAB2 INDEX LV_TABIX.
CONTINUE.
ENDIF.
ENDLOOP.
ENDLOOP.
this way you wont need a third table since itab2 will only contain the differences. But if you should pass the data into a third table you can add: itab3[] = itab[]2.
04-04-2007 1:49 PM
hi,
fill the two file into an internal table and the sort the internal table with some field....
then use DELETE ADJACENT DUPLICATES FROM itab comparing all fields
04-04-2007 1:49 PM
Hi..
loop at itab2.
read table itab1 with key f1 = itab2-f1.
if sy-subrc = 0.
delete itab1 index sy-tabix.
endif.
endloop.
now...itab1 is ur final result..
04-04-2007 1:51 PM
Hi,
itab1(10).
itab2(50).
itab3> we need to fill.
<b>loop at itab1.
read table itab2 with key = itab1-key.
if sy-subrc ne 0.
append itab1 to itab3.
endif.
endloop.</b>
Regards,
ananth