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: 
Read only

Compare two Hash Table

Former Member
1,112

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
Read only

marcin_cholewczuk
Active Contributor
0 Likes
936

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
Read only

ravi_lanjewar
Contributor
0 Likes
936

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]

Read only

marcin_cholewczuk
Active Contributor
0 Likes
937

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

Read only

0 Likes
759

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