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: 

ABAP SQL join syntax

Former Member
0 Kudos

Hi,

I am wondering if anyone can provide me with examples on correct syntax for different join types such as inner join, left outer join, right outer join, outer full join, and cross join.

Thank you in advance,

Sunny

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

In ABAP, there are only INNER JOINs and LEFT OUTER JOINs.




report zrich_0004.


data: begin of itab occurs 0,
      matnr type mara-matnr,
      maktx type makt-maktx,
      end of itab.



      select * into corresponding fields of table itab
              from mara
                   inner join makt
                      on mara~matnr = makt~matnr
                            where mara~mtart = 'HALB'
                              and makt~spras = sy-langu.



       select * into corresponding fields of table itab
              from mara
                   left outer join makt
                      on mara~matnr = makt~matnr
                            where mara~mtart = 'HALB'.

Regards,

Rich HEilman

3 REPLIES 3

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

In ABAP, there are only INNER JOINs and LEFT OUTER JOINs.




report zrich_0004.


data: begin of itab occurs 0,
      matnr type mara-matnr,
      maktx type makt-maktx,
      end of itab.



      select * into corresponding fields of table itab
              from mara
                   inner join makt
                      on mara~matnr = makt~matnr
                            where mara~mtart = 'HALB'
                              and makt~spras = sy-langu.



       select * into corresponding fields of table itab
              from mara
                   left outer join makt
                      on mara~matnr = makt~matnr
                            where mara~mtart = 'HALB'.

Regards,

Rich HEilman

Former Member
0 Kudos

Note this sample code for inner join using 4 tables.

This can be done by using Inner join in select query u can do a f1 check in select query,

eg.

* SELECT c~ekgrp
* a~matnr
* b~maktx
* c~werks
* c~minbe
* INTO CORRESPONDING FIELDS OF TABLE i_output
* FROM mara AS a INNER JOIN makt AS b
* ON a~matnr = b~matnr
* INNER JOIN marc AS c
* ON a~matnr = c~matnr
* inner join MSKU as d* on a~matnr = d~matnr* WHERE a~matnr IN s_matnr
* AND a~mtart IN s_mtart
* AND c~werks IN s_werks
* AND c~ekgrp IN s_ekgrp
* AND c~lgfsb IN s_lgfsb
* and d~KUNNR in s_kunnr
* and d~sobkz = c_w
* and d~kulab > 0.

Similarly u can check the sample code in the documentation.

Thanks & Regards,

Judith.

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Check this for left outer join.

SELECT KNA1KUNNR KNA1ADRNR ADR6~SMTP_ADDR

INTO (A, B, C)

FROM KNA1 LEFT OUTER JOIN ADR6

ON KNA1ADRNR = ADR6ADDRNUMBER

WHERE KUNNR BETWEEN '0000000000' AND '0000500000'.

Check this for inner join.

select db1field1 db2field2 from db1 inner join db2 into table itab on db1field = db2field.