Application Development and Automation 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: 
Read only

multiple left outer join in single select query

Former Member
0 Likes
2,365

My client requires to apply multiple left outer join in single select query.

Tell me how it is possible . tell me if we can use native sql query.

3 REPLIES 3
Read only

Former Member
0 Likes
948

Hi Vineet Kumar,

My suggestion would be better go for a VIEW. If u can't go for View's Use LDB this might solve ur issue.

Regards,

Dheepak

Read only

Former Member
0 Likes
948

hi

good

check this code and try accordingly.

SELECT *

FROM table1 AS t1

LEFT OUTER JOIN table2 AS t2

ON t2col2 = t1col2

INTO CORRESPONDING FIELDS OF TABLE result

WHERE t1~col1 IN so_col1.

hope this will help you to solve your problem.

Thanks

mrutyun^

Read only

Former Member
0 Likes
948

HI vineet,

Using multile left join is possible but it reduce performance as it takes a long time to retrieve data.

The following code would help you in knowing how to use multiple left join

REPORT  test.

PARAMETERS:
  p_auart LIKE vbak-auart.

DATA:
  BEGIN OF fs_sales,
    auart LIKE vbak-auart,
    vbeln LIKE vbak-vbeln,
    posnr LIKE vbap-posnr,
    matnr LIKE vbap-matnr,
    netwr LIKE vbap-netwr,
  END OF fs_sales,
  fs_temp LIKE fs_sales.

DATA:
  t_sales LIKE STANDARD TABLE OF fs_sales.

SELECT k~auart
       k~vbeln
       p~posnr
       p~matnr
       p~netwr
  INTO TABLE t_sales
  FROM vbak AS k
  OUTER JOIN vbap AS p
  ON k~vbeln = p~vbeln
 WHERE auart = p_auart
   AND p~netwr LT 1000.


IF sy-subrc EQ 0.
  WRITE:/5 'Sales Document'(001),/,
        15 'Sales Document Item'(002),
        40 'Material Number'(003).

  sort t_sales by netwr ascending.
  LOOP AT t_sales INTO fs_sales.
    WRITE:/ fs_sales-vbeln under text-001.
    LOOP AT t_sales INTO fs_temp WHERE vbeln = fs_sales-vbeln.
      WRITE:/ fs_temp-posnr under text-002,
              fs_temp-matnr under text-003.
    ENDLOOP.
  ENDLOOP.
ELSE.
  MESSAGE 'No Record Found' TYPE 'I'.

ENDIF.

But i would suggest you to go with views instead of using multiple joins..

Best of luck,

Bhumika