04-25-2007 3:48 PM
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
04-25-2007 4: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.
04-25-2007 3:56 PM
04-25-2007 3:59 PM
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.
04-25-2007 4: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.
04-25-2007 4:07 PM
That doesn't meet my requirement (my original text states "I want to achieve the results in single SQL statement")
04-25-2007 4:29 PM
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