Skip to Content
author's profile photo Former Member
Former Member

multiple left outer join in single select query

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 07, 2008 at 12:03 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 07, 2008 at 12:13 PM

    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^

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 07, 2008 at 12:32 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.