2011 Mar 29 11:26 AM
Hi experts,
I want to compare two hash table. here is the sample code.
TYPES: BEGIN OF company,
"name(20) TYPE c,
uom TYPE char4,
qty TYPE i,
END OF company.
DATA: comp TYPE company,
comptab TYPE HASHED TABLE OF company
WITH UNIQUE KEY uom,
comptab1 TYPE HASHED TABLE OF company
WITH UNIQUE KEY uom.
comp-uom = 'KG'.comp-qty = 10. COLLECT comp INTO comptab.
comp-uom = 'CT'.comp-qty = 20. COLLECT comp INTO comptab.
comp-uom = 'KG'.comp-qty = 30. COLLECT comp INTO comptab.
comp-uom = 'CT'.comp-qty = 10. COLLECT comp INTO comptab1.
comp-uom = 'KG'.comp-qty = 20. COLLECT comp INTO comptab1.
comp-uom = 'CT'.comp-qty = 10. COLLECT comp INTO comptab1.
comp-uom = 'KG'.comp-qty = 20. COLLECT comp INTO comptab1.
LOOP AT comptab INTO comp.
WRITE : comp-uom, comp-qty .
NEW-LINE.
ENDLOOP.
NEW-LINE.
WRITE : 'Second Table'.
NEW-LINE.
LOOP AT comptab1 INTO comp.
WRITE : comp-uom, comp-qty .
NEW-LINE.
ENDLOOP.
Here I have two table comptab and comptab1. I want to compare these two table.
Regards,
Kapil.
2011 Mar 29 10:07 PM
Hi,
Do it like this. However this is not a normal use of hashed tables and I think it will have impact on performance.
SORT: comptab, comptab1.
IF comptab1[] = comptab[].
WRITE 'equal'.
ELSE.
WRITE 'not equal'.
ENDIF.
BR
Marcin Cholewczuk
2011 Mar 29 12:40 PM
Hello,
You may want to have a look at the Wiki posting:
[Comparing Two Internal Tables - A Generic Approach|http://wiki.sdn.sap.com/wiki/display/Snippets/ComparingTwoInternalTables-AGeneric+Approach]
2011 Mar 29 10:07 PM
Hi,
Do it like this. However this is not a normal use of hashed tables and I think it will have impact on performance.
SORT: comptab, comptab1.
IF comptab1[] = comptab[].
WRITE 'equal'.
ELSE.
WRITE 'not equal'.
ENDIF.
BR
Marcin Cholewczuk
2025 Apr 18 8:24 AM
I think this gives wrong answer since there is no indexing in hashed tables