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: 

left ouer join with internal table

Former Member
0 Kudos

Good morning to everybody

I need created a internal table with 2 internal table but 1 is primary.

I tried use "left outer join" but it allows only with table and not with internal tabel

I would to be this result

a a xxx

b

c c zzz

d d sss

e

f f ttt

How can i do it?

Thanks a lot for your support

Beste regatrds

6 REPLIES 6

Sandra_Rossi
Active Contributor
0 Kudos

You may use abap statements [LOOP AT|http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb381a358411d1829f0000e829fbfe/frameset.htm] and [READ TABLE|http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/frameset.htm], and [APPEND|http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb36c8358411d1829f0000e829fbfe/frameset.htm]

For doing something like "itab1 left outer join itab2" to be stored in itab3, do:

LOOP AT itab1...
  CLEAR ls_itab3.
  ls_itab3-... = ls_itab1-...
  READ TABLE itab2... WITH KEY ...
  IF sy-subrc = 0.
    ls_itab3-... = ls_itab2-...
  ENDIF.
  APPEND ls_itab3 TO itab3.
ENDLOOP.

Ask developer for performance issues, or look at forum (lots of threads).

Former Member
0 Kudos

Hi,

Can you tell me which records are in these two internal tables so as to make your problem more clear?

Thanks and regards,

Chris Gu

Former Member
0 Kudos

thanks guys for your replay

in itab1 I have (example)

key:

a

b

c

e

f

in itab 2 I have

key filed1

a zzz

c yyy

d ttt

f sss

result into itab3:

a a zzz

b

c c yyy

d c ttt

e

f f sss

Again thanks for your support

Former Member
0 Kudos

Hi,

The following code is for your reference:

data: begin of wa1,
      key type c,
      end of wa1.

data: begin of wa2,
      key type c,
      var(3) type c,
      end of wa2.

data: begin of wa3,
      key1 type c,
      key2 type c,
      var(3) type c,
      end of wa3.

data: itab1 like standard table of wa1,
      itab2 like standard table of wa2,
      itab3 like standard table of wa3.

wa1-key = 'a'.
append wa1 to itab1.
wa1-key = 'b'.
append wa1 to itab1.
wa1-key = 'c'.
append wa1 to itab1.
wa1-key = 'd'.
append wa1 to itab1.
wa1-key = 'e'.
append wa1 to itab1.
wa1-key = 'f'.
append wa1 to itab1.
clear wa1.

wa2-key = 'a'.
wa2-var = 'zzz'.
append wa2 to itab2.
wa2-key = 'c'.
wa2-var = 'yyy'.
append wa2 to itab2.
wa2-key = 'd'.
wa2-var = 'ttt'.
append wa2 to itab2.
wa2-key = 'f'.
wa2-var = 'sss'.
append wa2 to itab2.
clear wa2.

loop at itab1 into wa1.
  read table itab2 into wa2
  with key key = wa1-key
  binary search.
  if sy-subrc = 0.
    wa3-key1 = wa1-key.
    wa3-key2 = wa2-key.
    wa3-var = wa2-var.
    append wa3 to itab3.
    clear wa3.
  else.
    append wa1 to itab3.
  endif.
endloop.

loop at itab3 into wa3.
  write:/ wa3-key1, wa3-key2,wa3-var.
endloop.

Hope it helps.

Regards,

Chris Gu

Former Member
0 Kudos

perfect Chris Gu

thanks a lot

post close

0 Kudos

Hi,

But you don't give any point.............

Chris