‎2009 Sep 08 6:16 AM
Dear All,
I have two Internal tables with the same structure.
Now i want to compare their contents line by line.
eg.
Loop at IT1.
Read Table IT2 with key MBLNR = IT1-MBLNR.
----
----
EndLoop.
Please help.
Regards
Ankur
‎2009 Sep 09 10:37 AM
Hi Ankur,
first sort both the internal tables.
loop at the first internal table (which has more entries) and read the content of the second internal table(which has less entries) for every occurence of the first internal table and have a count if count increses the tables are different.
*for checking the no of entries in the internal table and looping based on the no of entries
DESCRIBE TABLE itab1 LINES COUNT_1.
DESCRIBE TABLE itab2 LINES COUNT_2.
DATA : count type i default 0, *variable for checking the same content
count_1 type i default 0,
count_2 type i default 0.
SORT ITAB1 field1 field2.
SORT ITAB2 field1 field2.
IF count1 >count2.
LOOP AT itab1 INTO watab1.
READ TABLE itab2 INTO watab2 WITH KEY field1 = 'VALUE'.
IF SY-SUBRC NE 0.
count = count + 1.
ENDIF.
ENDLOOP.
ELSE.
LOOP AT itab2 INTO watab2.
READ TABLE itab1INTO watab1 WITH KEY field1 = 'VALUE'.
IF SY-SUBRC NE 0.
count = count + 1.
ENDIF.
ENDLOOP.
ENDIF.
IF count >0.
write ' both the contents are same'.
ELSE.
write 'Different'.
ENDIF.
Hope it helps u.
regards,
Gopalakrishnan Ulagajothi
‎2009 Sep 08 6:20 AM
‎2009 Sep 08 6:20 AM
Hello
sort: IT1, IT2.
if IT1[] = IT2[].
write: 'Same'.
else.
write: 'With difference'.
endif.
‎2009 Sep 08 6:22 AM
I want to compare it line by line.
So i have to perform it in a loop.
I cant use IT1[] = IT2[].
‎2009 Sep 08 6:26 AM
Get Number of lines of table1 and table2. if different, tables are different.
The do a DO loop DO lines times.
Read from table 1 with index into workarea1, read from table2 by index into workarea 2. Compare both workareas.
‎2009 Sep 08 6:24 AM
Hi Ankur,
Your problem is not very much clear.
Use loop instead of Read, because any of two same records, Read statement takes only first record.
Loop at IT1.
loop at IT2 where MBLNR = IT1-MBLNR.
-
-
EndLoop.
Endloop.
Regards,
Vijay
‎2009 Sep 08 6:24 AM
‎2009 Sep 08 6:26 AM
Hi,
Before comparing sort bothinternal tables on all the fields & compare line to line.
‎2009 Sep 08 6:36 AM
Dear All,
I think the problem is not clear to you all. Check the below detail description.
I have 2 Internal table of same structure. Both Internal tables contain 70 fields
Both have a primary key DOCNO.
I have sorted both Internal tables.
Now i want to check if their is any change in contents in IT2 with respect to the contents of IT1-DOCNO.
I have to check the IT2 field by field & Line by line.
Eg.:
IT1 ->
DOCNO EBELN MATNR LIFNR DMBTR
50001 25001 110-001 10021 100
50002 25002 110-001 10021 200
50003 25003 110-001 10021 500
IT2 ->
DOCNO EBELN MATNR LIFNR DMBTR
50001 25001 110-001 10021 300
50002 25002 110-001 10021 200
50003 25003 110-001 10021 600
Now as shown above, I want to compare both the internal tables field by field.
Like: In row 1 & 3 only DMBTR is different. Rest is same.
So, i want to copy such rows in separate IT3.
Please guide me how to code the Loop.
Regards
Ankur
Edited by: Ankur Gupta on Sep 8, 2009 7:39 AM
‎2009 Sep 08 6:42 AM
Unclear problems will result in unclear solutions.
Line by line is completly different to field by field.
Just go through the tables and compare the fields. The needed statement is IF. This is just a laborious task.
Loop, read from both tables into different work areas, compare field by field with if. Thats it.
‎2009 Sep 08 6:39 AM
hi ,
there is two way to do this
1.
loop tab1 .
read table tab2 with key fld1 = itab1-fld1 fld2 = itab1-fld2 fld3 = itab1-fld3 . (compare all fields)
if sy-subrc eq 0.
match .
else .
not match .
endif .
endloop.
2
try to use FM.
CATSXT_COMPARE_STRUCTURES
CTVB_COMPARE_TABLES
Jitendra
‎2009 Sep 08 6:46 AM
I know this is a laborious task so i cant use if Condition with in a loop.
For that only i am asking if their is any dynamic solution for handling such requirement or if there is any standard function to handle the same.
‎2009 Sep 08 8:01 AM
Hello Ankur,
By whichever way you go finally you need to compare using IF statement only. it may be custom code or standard code.
other option may be you can try using SEARCH <itab> FOR <data>.
Thanks,
Augustin.
‎2009 Sep 09 10:37 AM
Hi Ankur,
first sort both the internal tables.
loop at the first internal table (which has more entries) and read the content of the second internal table(which has less entries) for every occurence of the first internal table and have a count if count increses the tables are different.
*for checking the no of entries in the internal table and looping based on the no of entries
DESCRIBE TABLE itab1 LINES COUNT_1.
DESCRIBE TABLE itab2 LINES COUNT_2.
DATA : count type i default 0, *variable for checking the same content
count_1 type i default 0,
count_2 type i default 0.
SORT ITAB1 field1 field2.
SORT ITAB2 field1 field2.
IF count1 >count2.
LOOP AT itab1 INTO watab1.
READ TABLE itab2 INTO watab2 WITH KEY field1 = 'VALUE'.
IF SY-SUBRC NE 0.
count = count + 1.
ENDIF.
ENDLOOP.
ELSE.
LOOP AT itab2 INTO watab2.
READ TABLE itab1INTO watab1 WITH KEY field1 = 'VALUE'.
IF SY-SUBRC NE 0.
count = count + 1.
ENDIF.
ENDLOOP.
ENDIF.
IF count >0.
write ' both the contents are same'.
ELSE.
write 'Different'.
ENDIF.
Hope it helps u.
regards,
Gopalakrishnan Ulagajothi
‎2009 Nov 30 10:26 AM
Hey,
Please check withthe following ideas.
1.describe structureof two internal tables.
den create dynamic subroutine and apply loop in one table.
it will take one by one all he fields and compare it with another fields.
3. u are having fundamentals od how to compare.
please
try dis it will work and with optimized code also.