Application Development 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 internal tables and list / show the differences

Former Member
0 Kudos

Dear forum members,

I might need some help: I`m filling two internal tables from database tables. I have to see whether there are differences in the two tables or not. To make it clear: I need to know if the entries for the field VKONT of the table DFKKOP are also existing in the table FKKVKP.

Now it`s not a problem to bring the entries into a internal table, but I don`t know how to compare my two tables and list the differences. Here`s the code:

DATA: wa_vkont TYPE dfkkop-VKONT,

wa_vkfkkvkp TYPE fkkvkp-vkont,

n_vorhfkkvkp TYPE string.

TYPES: wa_vkont2 TYPE dfkkop-VKONT.

DATA: lt_dfkkop TYPE TABLE OF wa_vkont2,

  • lt_dfkkop TYPE TABLE OF dfkkop,

lt_fkkvkp TYPE TABLE OF wa_vkont2,

  • lt_fkkvkp TYPE TABLE OF fkkvkp,

wa_dfkkop like LINE OF lt_dfkkop,

wa_fkkckp LIKE LINE OF lt_fkkvkp.

SELECT-OPTIONS: s_vkont FOR wa_vkont,

f_vkont FOR wa_vkfkkvkp.

select vkont from dfkkop INTO TABLE lt_dfkkop

WHERE vkont IN s_vkont.

SORT lt_dfkkop ASCENDING.

Delete ADJACENT DUPLICATES FROM lt_dfkkop.

select vkont from fkkvkp INTO TABLE lt_fkkvkp

WHERE vkont IN f_vkont.

SORT lt_fkkvkp ASCENDING.

Delete ADJACENT DUPLICATES FROM lt_fkkvkp.

8 REPLIES 8

kesavadas_thekkillath
Active Contributor
0 Kudos

The logic is to loop first itab and read second itab.

With the subrc value you can identify the existence of records in the second itab.

if it1[] ne it2[].

"Then there is a difference

endif.

0 Kudos

How do I do so??? Sorry, but I`m very new in ABAP!?

Ok, I know that command. But I don`t know how to list the differences!!! Do you understand that!?

Thank`s in advance.

Edited by: Imer Sabani on Jun 24, 2010 4:58 PM

0 Kudos

The logic is to loop first itab and read second itab.

With the subrc value you can identify the existence of records in the second itab.

If you're trying to list all differences, then also loop at 2nd tab and read the first...could have something in 2nd that doesn't exist in 1st and something in 1st that doesn't exist in 2nd.

if it1] ne it2[]. "sometimes does not work....large tables will (in some versions of WebAS or NetWeaver, at least) give false results

"Then there is a difference

endif.

0 Kudos

Do you understand that!?

Hi,

Eventhough you are new to ABAP. the logic is same in all languages if you know the commands.

0 Kudos

That`s the point. I don`t know the command nor the logic!!!

Is it Like this:

LOOP at lt_dfkkop INTO wa_dfkkop.

LOOP AT lt_fkkvkp INTO wa_fkkckp.

IF lt_dfkkop <> lt_fkkvkp.

WRITE wa_fkkckp.

ENDIF.

ENDLOOP.

ENDLOOP.

???

0 Kudos

>

> That`s the point. I don`t know the command nor the logic!!!

Moderator message - Unfortunately, this forum is not a place to learn ABAP. I suggest that you get one of the good ABAP books that are out there and maybe join an internet forum that caters to beginners - post locked Rob

Former Member
0 Kudos

Use in such way ...

LOOP at lt_dfkkop.

rEAD TABLE lt_fkkvkp WITH KEY VKONT = lt_dfkkop-VKONT. "mAKE USE OF BINARY SEARCH

if SY-SUBRC NE 0.

**you got the record **

ENDIF.

ENDLOOP.

Thanks!

0 Kudos

Make use of workareas..I have not used it..