Skip to Content
avatar image
Former Member

how to compare the two same fields of different tables

Hi can any one let me know the logic for compare the two fields of different tables.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 21, 2007 at 03:00 PM

    hi

    good

    IF it_1[] = it_2[].

    " Tables contents are the same

    ELSE.

    " Tables contents are different

    ENDIF.

    If they have different structure, you probably must loop one of the tables, and inside read the other, then compare field by field.

    Or if you don't need the contents (just comparing) you can do this, for example:

    LOOP AT it_1 INTO wa_1.

    READ TABLE it_2 WITH KEY field2 = wa_1-field2

    field5 = wa_1-field5

    TRANSPORTING NO FIELDS.

    IF sy-subrc = 0.

    " Record is on both tables (field2 and field5 are the fields in common for both tables).

    ENDIF.

    ENDLOOP.

    thanks

    mrutyun^

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 21, 2007 at 02:25 PM

    Hi Sudhir,

    If you are talking about comparing two fields of different internal tables, then

    LOOP ITAB1 into LS_ITAB1.

    READ ITAB2 into LS_ITAB2 with key keyfield = LS_ITAB1-keyfield

    BINARY SEARCH.

    IF LS_ITAB1-field EQ LS_ITAB2-field.

    " Enter your logic here

    ENDIF.

    ENDLOOP.

    <b>Reward points for helpful answers.</b>

    Best Regards,

    Ram.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      hi

      if u r validating the field of itab with db table then

      select field

      from itab into

      <some variable of same type as field>

      for all entries in <dbtable>

      where field = dbtable-field

  • avatar image
    Former Member
    Aug 21, 2007 at 02:59 PM

    You can use Inner Join or For all entries option for your comparision.

    Reward points if usefull.

    Thanks,

    Veeru.

    Add comment
    10|10000 characters needed characters exceeded