Skip to Content
avatar image
Former Member

Comparing 2 columns with abap

Hi experts,

Is there any statement in abap which allows to compare 2 columns of an internal table?

If i take the follwing example:

Column A

Column B

A

A

A

A

A

A

B

A

At the end, I want to see that record B is present in Column A but not in B.

Thanks.

Amine

PS : To moderators, no need to lock my thread, i am junior consultant on BW side and i want to improve my knowledge in Abap and learn form experienced Abap consultans.

Thanks for your understanding.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    Jan 30, 2013 at 11:29 AM

    Amine:

    Either you are looking for a solution with maximum elegance - or I don't understand your problem.

    Here would be my solution. Not elegant. But straightforward.

    field-symbols: <ls_line> type (line structure of itab)

    loop at itab assigning <ls_line>.

    if <ls_line>-column_a ne <ls_line>-column_b.

    write: / sy-tabix, <ls_line>-column_a, <ls_line>-column_b.

    endif.

    endloop.

    Regards,
    Rüdiger

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Rüdiger,

      Thanks for your answer. I want really to improve my abap skills, it's very usefull on BW side 😉

      Ok, I heard about an Abap option Comparing fields...

      What do you think about it in my case?

      Amine

      PS : I like elegance too 😊

  • Jan 30, 2013 at 02:57 PM

    You can also reduce record read executing your check in the LOOP statement,

    LOOP AT itab ASSIGNING <ls_line> WHERE column_a NE column_b.  WRITE: / sy-tabix, <ls_line>-column_a, <ls_line>-column_b.ENDLOOP.

    Regards,

    Raymond

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 30, 2013 at 01:16 PM

    Hi Amine,

    Consider your internal table as ITAB_COLUMN and work area as WA_COLUMN.

    Suppose your internal table contains two fields namely column1 and column2.

    loop at itab_columns into wa_columns.

    if wa_column-column1 NE wa_column-column2

    write:/ wa_column-coumn1,

    wa_column-column2,

    sy-tabix.

    endif.

    Here sy-tabix indicates in which record the contents are mismatching.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Amine,

      Thats why we are mentioning the record contents after write statment.

      Using write statement we can display the contents of the record as per the requirement.

  • avatar image
    Former Member
    Jan 30, 2013 at 03:24 PM

    Thanks to all for your contributions.

    Amine

    Add comment
    10|10000 characters needed characters exceeded