Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Compare two Hash Table

Former Member
462

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.

1 ACCEPTED SOLUTION

marcin_cholewczuk
Active Contributor
0 Kudos
286

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

3 REPLIES 3

ravi_lanjewar
Contributor
0 Kudos
286

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]

marcin_cholewczuk
Active Contributor
0 Kudos
287

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

0 Kudos
109

I think this gives wrong answer since there is no indexing in hashed tables