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: 

UNION statement in ABAP SQL

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

5 REPLIES 5

Former Member
0 Kudos

use inner join

0 Kudos

I don't think using JOIN solves the problem. As I stated earlier, I want to get STCD1 for vendors that are in BSIK "or" BSAK (not BSIK "AND" BSAK) so JOIN cannot be used.

Former Member
0 Kudos

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.

0 Kudos

That doesn't meet my requirement (my original text states "I want to achieve the results in single SQL statement")

0 Kudos

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