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

Comparing 2 internal tables in UNICODE

Former Member
0 Likes
696

HI guys,

I have to compare 2 internal tables with same structure. Every field excepting first field should be compared.

Old, non unicode code is below.


DATA: a  TYPE TABLE OF pc20e WITH HEADER LINE,
           b  TYPE TABLE OF pc20e WITH HEADER LINE.

IF a+1 = b+1.
  WRITE: / 'Hello World'.
ENDIF.

That´s just an example of course. The real code is in a HR user exit, so i can´t deactivate UNICODE Check.

Thanks a lot.

HI guys,

I have to compare 2 internal tables with same structure. Every field excepting first field should be compared.

Old, non unicode code is below.


DATA: a  TYPE TABLE OF pc20e WITH HEADER LINE,
           b  TYPE TABLE OF pc20e WITH HEADER LINE.

IF a+1 = b+1.
  WRITE: / 'Hello World'.
ENDIF.

That´s just an example of course. The real code is in a HR user exit, so i can´t deactivate UNICODE Check.

Thanks a lot.

3 REPLIES 3
Read only

Former Member
0 Likes
657

data: flag(1) type c,

l_index type sy-index.

sort: a,b.

l_index =1.

loop at a from index l_index.

read table b index l_index.

if sy-subrc eq 0.

compare the common fields.

if mismatch.

flag =1.

exit.

endif.

else.

flag =1.

exit.

endif,

l_index =l_index+1.

endloop.

if flag eq 1.

write:............

endif.

Read only

0 Likes
657

Guess, that code doesn't´t resolve the problem.

I want to compare every row, so sy-index isn´t very helpful.

I want to ignore the first column !!

The problem is, that the first field of table is not character like.

Read only

uwe_schieferstein
Active Contributor
0 Likes
657

Hello Alexander

I would copy the two internal tables into two temporay itabs of the same structure and initialize the values in the first itab field:

DATA:
  lt_itab_pbo   TYPE ...,
  lt_itab_pai    TYPE ...,
  ls_entry        LIKE LINE OF lt_itab_pbo.

  lt_Itab_pbo = itab1.
  lt_Itab_pai = itab2.

  CLEAR: ls_entry-field1.
  MODIFY lt_Itab_pbo FROM ls_entry
    TRANSPORTING field1
    WHERE ( field1 IS NOT INITIAL ).
  MODIFY lt_Itab_pai FROM ls_entry
    TRANSPORTING field1
    WHERE ( field1 IS NOT INITIAL ).

Next I would use the approach that I have published in:

<a href="https://wiki.sdn.sap.com/wiki/display/Snippets/ComparingTwoInternalTables-AGeneric+Approach">Comparing Two Internal Tables - A Generic Approach</a>

Regards

Uwe