Skip to Content
avatar image
Former Member

Compare two internal tables and list / show the differences

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Jun 24, 2010 at 03:16 PM

    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!

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 24, 2010 at 02:54 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      >

      > 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