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

UNION statement in ABAP SQL

Hi,

How to achieve the UNION SQL operation results in ABAP? To be specific, I want to retrieve STCD1 field value from vendor master table (LFA1) for all vendors (LIFNR) that exist in table BSIK or BSAK.

And I want to achieve the results in single SQL statement. So in essence, the resultant SQL would be something like:

SELECT STCD1

INTO TABLE my_internal_table

FROM LFA1

WHERE LIFNR IN (SELECT DISTINCT LIFNR

FROM BSIK

UNION

SELECT DISTINCT LIFNR

FROM BSAK)

But the UNION is not a valid keyword in ABAP. Any idea how to achieve this?

Regards,

Chetan

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Apr 25, 2007 at 03:03 PM

    Then try this.

    First get all the vendors from the BSIK into internal table gt_vendor and then get all the vendors from the BSAK table by appending gt_vendor.

    Fetch STCD1 from table LFA1

    for all entries in gt_vendor.

    Add a comment
    10|10000 characters needed characters exceeded

    • hi chetan,

      do you have any where condition to filter the records from bsak and bsik?

      your requirement cannot be realized in a single statement.

      you have to use two separate selects from bsak and bsik, then, collect all the vendors in one internal table and at last you have to use this table to get the vendor info from lfa1.

      regards,

      ravi

  • author's profile photo Former Member
    Former Member
    Posted on Apr 25, 2007 at 02:56 PM

    use inner join

    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.