Skip to Content
2
Former Member
Feb 13, 2019 at 12:57 PM

Table comprehension, Left outer join

122 Views Last edit Feb 13, 2019 at 01:01 PM 3 rev

Hello,

I want to merge two internal tables as described on the following SAP help page with one difference: the rows of the first table should be considered in the result table even if the second table doesn't contain corresponding entries.

Table Comprehensions, Join

In my example the result table itab3 only contains key "a", but it should also contain "b", even if it is not in itab2. What is the best approach to resolve this issue with new ABAP statements.

Thanks & regards

P.S. (Off-Topic): Is it possible to add text in a post below inserted code, because I don't know how to do it?

Here the example code:

TYPES:
      BEGIN OF line1,
        key TYPE c LENGTH 1,
        col1 TYPE i,
      END OF line1,
      itab1 TYPE TABLE OF line1 WITH EMPTY KEY,
<br>      BEGIN OF line2,
        key TYPE c LENGTH 1,
        col2 TYPE i,
      END OF line2,
      itab2 TYPE TABLE OF line2 WITH EMPTY KEY,

      BEGIN OF line3,
        key TYPE c LENGTH 1,
        col1 TYPE i,
        col2 TYPE i,
      END OF line3,
      itab3 TYPE TABLE OF line3 WITH EMPTY KEY.

DATA(itab1) = VALUE itab1(
      ( key = 'a' col1 = 1 )
      ( key = 'b' col1 = 2 ) ).

DATA(itab2) = VALUE itab2(
      ( key = 'a' col2 = 3 ) ).

DATA(itab3) = VALUE itab3(
      FOR wa1 IN itab1 INDEX INTO idx
      FOR wa2 IN itab2 WHERE ( key = wa1-key )
        ( key   = wa1-key
          col1 = wa1-col1
          col2 = wa2-col2 ) ).